Skip to content
SPECTRE
Xcoming soon

API reference

Everything your code can see and return. There is nothing else: no network, no keys, no clock beyond ctx.now.

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. Return None to change nothing.

Context

  • ctx.now: bar close time, UTC datetime.
  • ctx.markets: the manifest's markets.
  • ctx.candles(coin, n): last n closed candles, each with t, o, h, l, c, v. At most 1,000.
  • ctx.closes(coin, n): last n closes as floats.
  • ctx.mid(coin): current mid price.
  • ctx.funding(coin): current hourly funding rate, or None.
  • 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 worth weight × 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 numpy and pandas.
  • 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.