live module provides functionality for deploying trading strategies in live markets using the same code and interface as backtesting.
Core Types
LiveBot
A live trading bot that implements the sameBot trait as the backtester.
LiveBot receives market data and order updates from connectors via an IPC channel and processes them in real-time.
Example:
LiveBotBuilder
Builder for constructingLiveBot instances.
new()- Creates a new builder with a random bot IDregister(instrument)- Adds an instrument for tradingerror_handler(handler)- Sets callback for handling connector errorsorder_recv_hook(hook)- Sets callback invoked when order updates are receivedid(id)- Sets a custom bot ID (must be unique per connector)build()- Constructs theLiveBotinstance
Instrument
Represents a trading instrument (asset) in the live bot.connector_name- Name of the connector to use for this instrumentsymbol- Trading symbol (symbology depends on the connector)tick_size- Minimum price incrementlot_size- Minimum quantity incrementdepth- Market depth implementationlast_trades_capacity- Number of recent trades to store (0 to disable)
Errors and Events
BotError
Errors that can occur during live trading.LiveError
Error information received from connectors.ErrorKind
Type of error from the connector.LiveEvent
Events sent by connectors to the bot.BatchStart/BatchEnd- Marks the beginning and end of a batch of eventsFeed- Market data feed event (depth, trades, etc.)Order- Order update (new, filled, canceled, etc.)Position- Position update from the exchangeError- Error notification from the connector
LiveRequest
Requests sent from the bot to connectors.Value Type
A variant type for passing data between bot and connector.IPC Communication
The live bot communicates with connectors through an IPC channel.Channel Trait
Usage Examples
Basic Live Bot Setup
Multi-Instrument Bot
Trading in Live Mode
Error Handling
Order Response Hook
Unified Interface
The key advantage of the live module is that it implements the sameBot trait as the backtester, allowing you to run the same strategy code in both backtesting and live trading:
Recorder
The live module also provides aLoggingRecorder for logging trading statistics.