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.
| Function | When it runs |
|---|---|
| onInit | When the instance starts. Read parameters or saved state once |
| onTick | A new last price arrived |
| onBar | A candle closed. The argument is that candle |
| onTimer | On a timer, with no market argument |
| onFill | A fill. Includes clientOrderId, price, amount, fee, and timestamp |
| onStop | When 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);
}