DoQuant
English
Back to handbook

Harbor SDK

Example: AltRank basket

This example is a spot basket. symbolMode is basket, and symbols lists the names to compare. Each bar reads one social point per symbol. A smaller AltRank ranks higher.

  • getSocial sees only stored points. A symbol with no points is treated as ranked far behind.
  • kv key held stores the chosen symbol. If the leader did not change, it does not order again.
  • On a switch it buys the new leader at market. The sample does not sell the previous symbol. Add that sell before live.

Full example:

const manifest = {
  name: "AltRank 篮子",
  version: "1.0.0",
  ccxtIds: ["binance"],
  markets: ["spot"],
  symbolMode: "basket",
  symbols: ["BINANCE:BTC/USDT", "BINANCE:ETH/USDT"],
  params: {},
  permissions: ["market", "order", "account"],
};
async function onBar(rt, bar) {
  const symbols = await rt.market.getSymbols();
  let best = symbols[0] || bar.symbol;
  let bestRank = 999999;
  for (const symbol of symbols) {
    const points = await rt.market.getSocial(symbol, 1);
    const rank = points.length ? Number(points[points.length - 1].altRank) : 999999;
    if (rank < bestRank) {
      bestRank = rank;
      best = symbol;
    }
  }
  const held = await rt.kvGet("held");
  if (held !== best) {
    await rt.order.create({
      clientOrderId: "alt-" + bar.time,
      symbol: best,
      side: "buy",
      type: "market",
      amount: "0.01",
    });
    await rt.kvSet("held", best);
  }
}
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