Skip to content

Hooks ​

Subclass Strategy, override the hooks you care about. Universal tickers are Venue_Category_SYMBOL — see Write & publish. Which venues exist, and which feeds they serve: Exchanges.

Lifecycle ​

Process and session state. Called in order around a run.

Hook / methodWhat it is
on_initialized(cls, params)Classmethod. Deserialize strategy.yml sts.config into runtime paras. Called once before the session starts.
on_rebuild(remembered)Prior run restored. Before on_start / on_ready. Restore from recon + remembered, not a saved copy of your attributes.
on_startSession starts strategy infrastructure
on_readyAfter start, session is ready to run
on_stopSession shutting down
exit(reason=...)Natural end → on_stop → status done
fail(reason)Same teardown, status failed, reason persisted for the UI
remember(key, value)Persist one fact a rebuild could not re-derive (config is in st_paras; venue state returns via recon). Write when it becomes true — a kill runs no shutdown.

fail does not unwind orders — cancel what must not outlive the session first.

Set rebuildable = True on the class, or STS leaves the row interrupted. Operator side: Rebuild on boot. cid_slot is kept so owns() still recognises the session's orders. Facts are established once; re-remembering a moving value stores something wrong when read.

Market data ​

Public feeds and one-shot queries.

Live feeds ​

Subscribe in the deploy document (md:), one topic per instrument.

HookTopicWhat it is
on_best_quotebestquoteTouch with sizes, at book speed
on_order_bookorderbookFull snapshot each time (no depth-diff sequencing)
on_tradetradeOne match, taker side
on_agg_tradeaggtradeVenue-aggregated; match_count in the print
on_klinekline_{interval}In-progress candle re-pushed; only closed is final
on_tickerticker24h stats + top of book
on_liquidationliquidationOther accounts closed out — not your fill
on_funding_ratefunding_rateStill-moving prediction for the next settlement; positive = longs pay shorts
on_open_interestopen_interestOne side's size. Linear books in base; BinanceCM in contracts

A subscribe the venue does not serve is refused at attach (no stream_*, or the method refuses that category). Gate has no aggtrade; paper has no candles; Bybit liquidations are perp. funding_rate and open_interest are contract books — spot and paper refuse. Binance futures have no OI stream (use mds.fetch_open_interest). Per-venue list: Exchanges.

Queries ​

self.mds.fetch_klines / fetch_order_book / fetch_best_quote / fetch_funding_history / fetch_open_interest return a query_id (or None if it never left). Answers arrive later:

HookNotes
on_fetch_klinesNot the same as on_kline
on_fetch_orderbookNot the same as on_order_book
on_fetch_bestquoteNot the same as on_best_quote
on_fetch_funding_historyNot the same as on_funding_rate. Settled rows, oldest first
on_fetch_open_interestNot the same as on_open_interest. Snapshot of now, not a series

They also fire on failure (ok False). Independent of md_ids. Interval is canonical (1m, 4h, 1mo — month is 1mo, never 1M).

A venue that has no history or snapshot for that instrument (spot, paper, dated Future for funding) answers MD_VENUE_UNSUPPORTED_READ. Paper has no fetch reader at all — the query never leaves.

Private ​

From td.{api_id}.global, account-wide. Filter with self.owns(cid) before treating an event as yours.

HookWhat it is
on_order_updateOrder status from TD
on_fillFill / execution report
on_order_rejectSubmit fail
on_cancel_rejectCancel fail
on_balance_updateBalance change
on_position_updateContract venues only; qty signed; close arrives as zero; spot never calls this
on_recon_doneOMS snapshot in self.oms after recon

submit → on_order_update | on_order_reject; cancel → on_order_update | on_cancel_reject.

Next ​

Which venues exist and which feeds they serve: Exchanges. Tape warm-up and accessors (oms, ledger, tape, mds, symbols, timer, log): Architecture, Write & publish.