Skip to main content

order_state_events

Function order_state_events 

Source
pub async fn order_state_events<U: OrderExecutor + ?Sized>(
    ud: &U,
    rx: &mut Receiver<Envelope>,
    source: &str,
    id: &InstrumentId,
    price: Price,
)
Expand description

The order stream: placing an order gives an event for our cid, cancelling it gives a Cancelled event.

Steps and checks:

  1. subscribe_order_state.
  2. Place a buy limit order, one lot, at price, under a fresh cid. A local rate-limit refusal is waited out and retried under a fresh cid (a cid is never sent twice).
  3. An [brokapi_core::Event::Order] for our cid arrives. Its source is source, its sub is the subscription from step 1, and its state is not Rejected.
  4. Cancel the order. An order event with state Cancelled for the same cid arrives on the same subscription.

Each wait is limited to EVENT_TIMEOUT. price must be far from the market and accepted by the mock. The command gate must be open, so call reconcile first. The mock must push an order event when an order is placed and when it is cancelled. If the adapter opens its order event socket in the background, wait until it is connected before running this scenario, otherwise the first event can be missed.

§Panics

With [conformance:order_state_events] <reason> when a call fails, an event does not arrive, or a check fails.

§Examples

brokapi_conformance::reconcile(&ud).await;
brokapi_conformance::order_state_events(&ud, &mut rx, "bcs-ud", &sber, Price::from(100)).await;