pub trait StrategyContext {
Show 20 methods
// Required methods
fn place_order(&mut self, cmd: PlaceOrder);
fn place_orders(&mut self, cmds: Vec<PlaceOrder>);
fn cancel_order(&mut self, cmd: CancelOrder);
fn cancel_all(&mut self, cmd: CancelAll);
fn stop_strategy(&mut self, strategy_id: StrategyId, reason: &str);
fn set_timer(&mut self, delay: Duration) -> TimerId;
fn set_interval(&mut self, interval: Duration) -> TimerId;
fn cancel_timer(&mut self, timer_id: TimerId);
fn mid_price(&self, instrument: &InstrumentId) -> Option<Price>;
fn quote(&self, instrument: &InstrumentId) -> Option<Quote>;
fn instrument_meta(
&self,
instrument: &InstrumentId,
) -> Option<&InstrumentMeta>;
fn balance(&self, asset: &AssetId) -> Balance;
fn position(&self, instrument: &InstrumentId) -> Position;
fn exchange_health(&self, exchange: &ExchangeInstance) -> ExchangeHealth;
fn order(&self, client_id: &ClientOrderId) -> Option<&LiveOrder>;
fn now_ms(&self) -> i64;
fn log_info(&self, msg: &str);
fn log_warn(&self, msg: &str);
fn log_error(&self, msg: &str);
fn log_debug(&self, msg: &str);
}Expand description
Strategy context - what strategies use to interact with the engine.
This is passed to strategy methods and provides:
- Command emission (place/cancel orders)
- Timer management
- Read-only access to market data and state
- Logging
Required Methods§
Sourcefn place_order(&mut self, cmd: PlaceOrder)
fn place_order(&mut self, cmd: PlaceOrder)
Place a new order. Returns immediately; acceptance/rejection comes via events.
Sourcefn place_orders(&mut self, cmds: Vec<PlaceOrder>)
fn place_orders(&mut self, cmds: Vec<PlaceOrder>)
Place multiple orders in a single batch. Returns immediately; acceptance/rejection comes via events.
Sourcefn cancel_order(&mut self, cmd: CancelOrder)
fn cancel_order(&mut self, cmd: CancelOrder)
Cancel an existing order by client_id.
Sourcefn cancel_all(&mut self, cmd: CancelAll)
fn cancel_all(&mut self, cmd: CancelAll)
Cancel all open orders (optionally for an instrument).
Sourcefn stop_strategy(&mut self, strategy_id: StrategyId, reason: &str)
fn stop_strategy(&mut self, strategy_id: StrategyId, reason: &str)
Request strategy stop. This will trigger on_stop callback after current event processing.
Sourcefn set_timer(&mut self, delay: Duration) -> TimerId
fn set_timer(&mut self, delay: Duration) -> TimerId
Register a one-shot timer that fires after delay.
Sourcefn set_interval(&mut self, interval: Duration) -> TimerId
fn set_interval(&mut self, interval: Duration) -> TimerId
Register a repeating timer that fires every interval.
Sourcefn cancel_timer(&mut self, timer_id: TimerId)
fn cancel_timer(&mut self, timer_id: TimerId)
Cancel a previously set timer.
Sourcefn mid_price(&self, instrument: &InstrumentId) -> Option<Price>
fn mid_price(&self, instrument: &InstrumentId) -> Option<Price>
Get the current mid price for an instrument (if available from quote poller)
Sourcefn quote(&self, instrument: &InstrumentId) -> Option<Quote>
fn quote(&self, instrument: &InstrumentId) -> Option<Quote>
Get the current best bid/ask quote for an instrument
Sourcefn instrument_meta(&self, instrument: &InstrumentId) -> Option<&InstrumentMeta>
fn instrument_meta(&self, instrument: &InstrumentId) -> Option<&InstrumentMeta>
Get instrument metadata
Sourcefn position(&self, instrument: &InstrumentId) -> Position
fn position(&self, instrument: &InstrumentId) -> Position
Get the current position for an instrument
Sourcefn exchange_health(&self, exchange: &ExchangeInstance) -> ExchangeHealth
fn exchange_health(&self, exchange: &ExchangeInstance) -> ExchangeHealth
Check if exchange is Active or Halted
Sourcefn order(&self, client_id: &ClientOrderId) -> Option<&LiveOrder>
fn order(&self, client_id: &ClientOrderId) -> Option<&LiveOrder>
Get an order by client_id (if tracked)
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".