DoQuant
English
Back to handbook

Harbor SDK

Lifecycle and state

The platform calls a strategy function when the matching event happens. Implement at least one of onBar, onTick, or onTimer. Otherwise the strategy never gets a turn.

FunctionWhen it runs
onInitWhen the instance starts. Read parameters or saved state once
onTickA new last price arrived
onBarA candle closed. The argument is that candle
onTimerOn a timer, with no market argument
onFillA fill. Includes clientOrderId, price, amount, fee, and timestamp
onStopWhen the instance stops. Finish logs or UI

01Logs and a little state

  • rt.log(level, message) uses info, warn, or error. The line shows in the instance log.
  • rt.kvGet(key) reads a string saved earlier, or null.
  • rt.kvSet(key, value) stores a string. Use it for flags such as already bought or the symbol currently held. Do not store long candle history.
async function onBar(rt, bar) {
  rt.log("info", bar.close);
}