Session
class backtide.live.Session(config=None, strategy=None, indicators=None)
A stateful simulated account with optional strategy evaluation.
| Parameters |
config : SessionConfig | None, default=None
Execution, fee, and risk settings. Uses defaults when omitted.
strategy : BaseStrategy | None, default=None
Existing built-in or custom strategy. Its
indicators : list[BaseIndicator] | None, default=Noneevaluate method runs after
resting orders are matched on each processable candle. Explicit orders
can also be passed to on_bar.
Additional indicators to compute for live monitoring. Indicators
required by
strategy are included automatically.
|
See Also
A candle received from a live market-data connection.
Configuration for a live simulated session.
Example
>>> from backtide.live import MarketUpdate, Session
>>> session = Session()
>>> update = session.on_bar(
... MarketUpdate(
... "BTC-USD", "1m", 1_700_000_000, 1_700_000_060,
... 100.0, 102.0, 99.0, 101.0, volume=5.0,
... )
... )
>>> print(update.snapshot.equity)
100000.0
Methods
| on_bar | Process a live or replayed candle. |
| snapshot | Return the current account state without processing a candle. |
method on_bar(market, orders=None)
Process a live or replayed candle.
Example
>>> from backtide.backtest import Order
>>> from backtide.live import MarketUpdate, Session
>>> session = Session()
>>> market = MarketUpdate(
... "BTC-USD", "1m", 1_700_000_000, 1_700_000_060,
... 100.0, 102.0, 99.0, 101.0,
... )
>>> update = session.on_bar(market, [Order("BTC-USD", 1.0)])
>>> print(update.processed)
True
| Parameters |
market : MarketUpdate
Provider-normalized candle update.
orders : list[Order] | None, default=None
Explicit orders to submit after resting orders are matched. Orders
returned by the configured strategy are appended automatically.
|
| Returns |
Fills plus a complete mark-to-market account snapshot.
|
method snapshot()
Return the current account state without processing a candle.
Example
>>> from backtide.live import Session
>>> snapshot = Session().snapshot()
>>> print(snapshot.equity)
100000.0
| Returns |
Current cash, positions, prices, and profit-and-loss values.
|