Skip to main content

EngineContext

Struct EngineContext 

Source
pub struct EngineContext<'a> {
Show 14 fields pub place_orders: Vec<PlaceOrder>, pub batch_orders: Vec<Vec<PlaceOrder>>, pub cancel_orders: Vec<CancelOrder>, pub cancel_alls: Vec<CancelAll>, pub stop_requests: Vec<StopStrategy>, pub timers: Vec<PendingTimer>, pub canceled_timers: Vec<TimerId>, pub quotes: &'a HashMap<InstrumentId, Quote>, pub instruments: &'a HashMap<InstrumentId, InstrumentMeta>, pub orders: &'a OrderManager, pub inventory: &'a InventoryLedger, pub positions: &'a HashMap<InstrumentId, Position>, pub exchange_health: &'a HashMap<ExchangeInstance, ExchangeHealth>, pub now_ms: i64,
}
Expand description

Concrete implementation of StrategyContext

Fields§

§place_orders: Vec<PlaceOrder>

Single-order commands emitted during the current callback.

§batch_orders: Vec<Vec<PlaceOrder>>

Batch order commands emitted during the current callback.

§cancel_orders: Vec<CancelOrder>

Cancel-one commands emitted during the current callback.

§cancel_alls: Vec<CancelAll>

Cancel-all commands emitted during the current callback.

§stop_requests: Vec<StopStrategy>

Strategy stop requests emitted during the current callback.

§timers: Vec<PendingTimer>

Timer registrations emitted during the current callback.

§canceled_timers: Vec<TimerId>

Timer cancellations emitted during the current callback.

§quotes: &'a HashMap<InstrumentId, Quote>

Latest quotes by instrument.

§instruments: &'a HashMap<InstrumentId, InstrumentMeta>

Instrument metadata by instrument.

§orders: &'a OrderManager

Order manager snapshot.

§inventory: &'a InventoryLedger

Inventory ledger snapshot.

§positions: &'a HashMap<InstrumentId, Position>

Current positions by instrument.

§exchange_health: &'a HashMap<ExchangeInstance, ExchangeHealth>

Exchange health by exchange instance.

§now_ms: i64

Engine clock in milliseconds since the Unix epoch.

Implementations§

Source§

impl<'a> EngineContext<'a>

Source

pub fn new( quotes: &'a HashMap<InstrumentId, Quote>, instruments: &'a HashMap<InstrumentId, InstrumentMeta>, orders: &'a OrderManager, inventory: &'a InventoryLedger, positions: &'a HashMap<InstrumentId, Position>, exchange_health: &'a HashMap<ExchangeInstance, ExchangeHealth>, now_ms: i64, ) -> Self

Create an engine context for one strategy callback.

Source

pub fn take_commands( &mut self, ) -> (Vec<PlaceOrder>, Vec<Vec<PlaceOrder>>, Vec<CancelOrder>, Vec<CancelAll>, Vec<StopStrategy>)

Drain all collected commands

Source

pub fn take_timers(&mut self) -> (Vec<PendingTimer>, Vec<TimerId>)

Drain all timer registrations

Trait Implementations§

Source§

impl<'a> StrategyContext for EngineContext<'a>

Source§

fn place_order(&mut self, cmd: PlaceOrder)

Place a new order. Returns immediately; acceptance/rejection comes via events.
Source§

fn place_orders(&mut self, cmds: Vec<PlaceOrder>)

Place multiple orders in a single batch. Returns immediately; acceptance/rejection comes via events.
Source§

fn cancel_order(&mut self, cmd: CancelOrder)

Cancel an existing order by client_id.
Source§

fn cancel_all(&mut self, cmd: CancelAll)

Cancel all open orders (optionally for an instrument).
Source§

fn stop_strategy(&mut self, strategy_id: StrategyId, reason: &str)

Request strategy stop. This will trigger on_stop callback after current event processing.
Source§

fn set_timer(&mut self, delay: Duration) -> TimerId

Register a one-shot timer that fires after delay.
Source§

fn set_interval(&mut self, interval: Duration) -> TimerId

Register a repeating timer that fires every interval.
Source§

fn cancel_timer(&mut self, timer_id: TimerId)

Cancel a previously set timer.
Source§

fn mid_price(&self, instrument: &InstrumentId) -> Option<Price>

Get the current mid price for an instrument (if available from quote poller)
Source§

fn quote(&self, instrument: &InstrumentId) -> Option<Quote>

Get the current best bid/ask quote for an instrument
Source§

fn instrument_meta(&self, instrument: &InstrumentId) -> Option<&InstrumentMeta>

Get instrument metadata
Source§

fn balance(&self, asset: &AssetId) -> Balance

Get this strategy’s current balance for an asset
Source§

fn position(&self, instrument: &InstrumentId) -> Position

Get the current position for an instrument
Source§

fn exchange_health(&self, exchange: &ExchangeInstance) -> ExchangeHealth

Check if exchange is Active or Halted
Source§

fn order(&self, client_id: &ClientOrderId) -> Option<&LiveOrder>

Get an order by client_id (if tracked)
Source§

fn now_ms(&self) -> i64

Current time in milliseconds (deterministic in backtests)
Source§

fn log_info(&self, msg: &str)

Log an info message
Source§

fn log_warn(&self, msg: &str)

Log a warning message
Source§

fn log_error(&self, msg: &str)

Log an error message
Source§

fn log_debug(&self, msg: &str)

Log a debug message

Auto Trait Implementations§

§

impl<'a> Freeze for EngineContext<'a>

§

impl<'a> RefUnwindSafe for EngineContext<'a>

§

impl<'a> Send for EngineContext<'a>

§

impl<'a> Sync for EngineContext<'a>

§

impl<'a> Unpin for EngineContext<'a>

§

impl<'a> UnsafeUnpin for EngineContext<'a>

§

impl<'a> UnwindSafe for EngineContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more