pub struct MockExchange { /* private fields */ }Expand description
Mock Exchange - stateful simulation for testing
Implementations§
Source§impl MockExchange
impl MockExchange
Sourcepub fn new_with_balances(balances: HashMap<AssetId, Decimal>) -> Self
pub fn new_with_balances(balances: HashMap<AssetId, Decimal>) -> Self
Create a new mock exchange with initial balances
Sourcepub async fn set_fail_mode(&self, mode: OrderFailMode)
pub async fn set_fail_mode(&self, mode: OrderFailMode)
Set order failure behavior.
Sourcepub async fn set_exchange_health(&self, health: ExchangeHealth)
pub async fn set_exchange_health(&self, health: ExchangeHealth)
Set simulated exchange health.
Sourcepub async fn set_should_timeout(&self, should_timeout: bool)
pub async fn set_should_timeout(&self, should_timeout: bool)
Enable or disable simulated request timeouts.
Sourcepub async fn queue_place_order_error(&self, error: ExchangeError)
pub async fn queue_place_order_error(&self, error: ExchangeError)
Queue one placement error for the next order batch.
Sourcepub async fn queue_place_order_success(&self)
pub async fn queue_place_order_success(&self)
Queue one placement success for the next order batch.
Sourcepub async fn set_fill_all_immediately(&self, fill: bool)
pub async fn set_fill_all_immediately(&self, fill: bool)
Enable immediate fill mode for all orders (for backtesting)
Sourcepub async fn set_balance(&self, asset: AssetId, amount: Decimal)
pub async fn set_balance(&self, asset: AssetId, amount: Decimal)
Set an asset balance.
Sourcepub async fn placed_orders(&self) -> Vec<OrderInput>
pub async fn placed_orders(&self) -> Vec<OrderInput>
Return all placed orders recorded by the mock.
Sourcepub async fn queue_quotes(&self, quotes: Vec<Quote>)
pub async fn queue_quotes(&self, quotes: Vec<Quote>)
Queue historical quotes for backtesting. These will be returned by poll_quotes() in FIFO order, one per call.
Sourcepub async fn has_queued_quotes(&self) -> bool
pub async fn has_queued_quotes(&self) -> bool
Check if there are queued quotes remaining
Trait Implementations§
Source§impl Default for MockExchange
impl Default for MockExchange
Source§impl Exchange for MockExchange
impl Exchange for MockExchange
Source§fn exchange_id(&self) -> &ExchangeId
fn exchange_id(&self) -> &ExchangeId
Get the exchange ID
Source§fn environment(&self) -> Environment
fn environment(&self) -> Environment
Get the environment (mainnet/testnet)
Source§fn place_orders<'life0, 'life1, 'async_trait>(
&'life0 self,
orders: &'life1 [OrderInput],
) -> Pin<Box<dyn Future<Output = Result<Vec<PlaceOrderResult>, ExchangeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn place_orders<'life0, 'life1, 'async_trait>(
&'life0 self,
orders: &'life1 [OrderInput],
) -> Pin<Box<dyn Future<Output = Result<Vec<PlaceOrderResult>, ExchangeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Place multiple limit orders in a single batch API call.
Returns a Vec of results, one for each order in the same order as the input.
Source§fn cancel_order<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
_instrument: &'life1 InstrumentId,
_market_index: &'life2 MarketIndex,
_client_id: &'life3 ClientOrderId,
_exchange_order_id: Option<&'life4 ExchangeOrderId>,
) -> Pin<Box<dyn Future<Output = Result<(), ExchangeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn cancel_order<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
_instrument: &'life1 InstrumentId,
_market_index: &'life2 MarketIndex,
_client_id: &'life3 ClientOrderId,
_exchange_order_id: Option<&'life4 ExchangeOrderId>,
) -> Pin<Box<dyn Future<Output = Result<(), ExchangeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Cancel an order by client_id or exchange_order_id.
Source§fn cancel_all_orders<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_instrument: &'life1 InstrumentId,
_market_index: &'life2 MarketIndex,
) -> Pin<Box<dyn Future<Output = Result<u32, ExchangeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn cancel_all_orders<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_instrument: &'life1 InstrumentId,
_market_index: &'life2 MarketIndex,
) -> Pin<Box<dyn Future<Output = Result<u32, ExchangeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Cancel all orders for an instrument.
Returns number of orders canceled.
Source§fn poll_user_fills<'life0, 'life1, 'async_trait>(
&'life0 self,
_cursor: Option<&'life1 str>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Fill>, ExchangeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn poll_user_fills<'life0, 'life1, 'async_trait>(
&'life0 self,
_cursor: Option<&'life1 str>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Fill>, ExchangeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Poll user fills since cursor.
This is the primary execution event source.
cursor is opaque string (implementation-specific).
Source§fn poll_quotes<'life0, 'life1, 'async_trait>(
&'life0 self,
instruments: &'life1 [InstrumentId],
) -> Pin<Box<dyn Future<Output = Result<Vec<Quote>, ExchangeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn poll_quotes<'life0, 'life1, 'async_trait>(
&'life0 self,
instruments: &'life1 [InstrumentId],
) -> Pin<Box<dyn Future<Output = Result<Vec<Quote>, ExchangeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Poll current quotes/prices.
Source§fn poll_account_state<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<AccountState, ExchangeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn poll_account_state<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<AccountState, ExchangeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Poll account state (absolute).
Used for snapshot-based synchronization.
Source§fn instance(&self) -> ExchangeInstance
fn instance(&self) -> ExchangeInstance
Get the exchange instance key
Source§fn init<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExchangeError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn init<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExchangeError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Initialize the exchange connection and perform startup validations.
Called by the runner before entering the main loop.
Implementations can validate: connectivity, vault ownership, account balance, etc.
Auto Trait Implementations§
impl !RefUnwindSafe for MockExchange
impl !UnwindSafe for MockExchange
impl Freeze for MockExchange
impl Send for MockExchange
impl Sync for MockExchange
impl Unpin for MockExchange
impl UnsafeUnpin for MockExchange
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more