Strategy
interval: bar size, one of"1m", "5m", "15m", "1h", "4h", "1d". Must be at least the manifest's rebalance interval.on_start(self, ctx): optional, called once.on_bar(self, ctx) -> list[Target | Order] | None: called at each bar close. ReturnNoneto change nothing.
Context
ctx.now: bar close time, UTCdatetime.ctx.markets: the manifest's markets.ctx.candles(coin, n): lastnclosed candles, each witht, o, h, l, c, v. At most 1,000.ctx.closes(coin, n): lastncloses as floats.ctx.mid(coin): current mid price.ctx.funding(coin): current hourly funding rate, orNone.ctx.position(coin): reference portfolio position as a signed fraction of equity.ctx.equity: reference portfolio equity in USDC.ctx.state: a dict that persists between bars, up to 64 KB of JSON.ctx.log(msg): write to your private run log, visible only in your studio.
Outputs
Target(coin, weight): hold a position worthweight × equity; negative is short. The sum of absolute weights cannot exceed the manifest's max leverage; one market cannot exceed max position.Order(coin, side, size_usd, reduce_only=False): a one-off intent, for strategies that think in trades rather than targets.
The risk guard clips or rejects outputs that break the manifest and logs why. Your run log shows each rejection.
Limits
- 500 ms CPU per bar, 256 MB memory, standard library plus
numpyandpandas. - No network, no subprocesses, no filesystem writes outside
ctx.state. - An exception or timeout skips the bar and holds positions; three in a row pause the strategy.