Harbor SDK
Example: spot grid
This example is one spot symbol. The first bar buys once at market and stores that fact in kv so later bars do not buy again. The UI shows the close on a metric card and a one-point line.
- markets is only spot. symbolMode is single.
- params.amount is the size field on the create page. The sample order still uses 0.01. When you wire the form, use the value the user entered.
- clientOrderId includes the bar time, so a repeated trigger on the same bar does not become two orders.
- permissions includes market, order, and account.
Full example:
const manifest = {
name: "现货网格",
version: "1.0.0",
ccxtIds: ["binance"],
markets: ["spot"],
symbolMode: "single",
params: { amount: { type: "number", label: "数量" } },
permissions: ["market", "order", "account"],
};
async function onBar(rt, bar) {
const bought = await rt.kvGet("bought");
if (!bought) {
await rt.order.create({
clientOrderId: "grid-" + bar.time,
symbol: bar.symbol,
side: "buy",
type: "market",
amount: "0.01",
});
await rt.kvSet("bought", "1");
}
rt.setUi({
cards: [{ kind: "metric", id: "px", label: "close", value: bar.close }],
buttons: [],
charts: [{ kind: "chart", id: "c", label: "close", points: [{ time: bar.time, value: bar.close }] }],
fields: [],
});
}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