Harbor SDK
Example: funding dual leg
This example declares spot and perpetual together. symbolMode must be dual, and symbols must name both legs. At runtime, getSymbols returns the allowed list, then the strategy reads the perpetual's current funding rate and recent history.
- The spot symbol is BINANCE:BTC/USDT. The perpetual is BINANCE:BTC/USDT:USDT.
- When the rate is positive and history is not empty, the sample buys the current bar's symbol at market. A real dual-leg strategy must use both declared symbols.
- The UI shows the rate on a metric card.
getFundingRate returns null when there is no data. The sample treats that as 0 and does not order. Full example:
const manifest = {
name: "资金费双腿",
version: "1.0.0",
ccxtIds: ["binance"],
markets: ["spot", "swap"],
symbolMode: "dual",
symbols: ["BINANCE:BTC/USDT", "BINANCE:BTC/USDT:USDT"],
params: {},
permissions: ["market", "order", "account"],
};
async function onBar(rt, bar) {
const symbols = await rt.market.getSymbols();
const perp = symbols[1] || bar.symbol;
const funding = await rt.market.getFundingRate(perp);
const history = await rt.market.getFundingHistory(perp, 4);
const rate = funding ? Number(funding.rate) : 0;
if (rate > 0.0001 && history.length > 0) {
await rt.order.create({
clientOrderId: "fund-" + bar.time,
symbol: bar.symbol,
side: "buy",
type: "market",
amount: "0.01",
});
}
rt.setUi({
cards: [{ kind: "metric", id: "f", label: "funding", value: String(rate) }],
buttons: [],
});
}This chapter is for signed-in readers
Create a free account to read the full chapter, including sample code and step-by-step instructions.
Sign in to continue