Strategy
Subclass Strategy, wire up handlers in init(), and place orders. You never import an engine — the runtime wires one behind the SDK.
from signalai_quant import Strategy, Bar, Side, OrderType
class MyStrategy(Strategy):
def init(self):
self.subscribe(Bar, self.on_bar)
def on_bar(self, bar):
if self.portfolio[bar.symbol].qty == 0:
self.order(bar.symbol, Side.BUY, 10, OrderType.MARKET)
Methods
init(self)
Called once before replay (and once per day in intraday mode). Register handlers and timers here.
subscribe(event_type, handler)
Call handler(event) for each event of event_type. The common case is self.subscribe(Bar, self.on_bar).
every(interval, callback)
Fire callback(Timer) on a fixed interval. interval is a string like "7d", "1h", or "30m".
order(symbol, side, qty, type=OrderType.MARKET, price=None)
Place an order. side is Side.BUY / Side.SELL; type is OrderType.MARKET / OrderType.LIMIT (price required for limit). Returns an order id. See Fills for when it executes.
set_holdings(symbol, target_pct)
Convenience: order toward a target fraction of equity (e.g. 0.5 = 50% of account value in symbol). Computes the share delta and places a market order.
Properties
self.portfolio
The live Portfolio. Read positions with self.portfolio[symbol].qty.
self.universe
The list of symbols this backtest runs over.