Skip to main content

executions

Function executions 

Source
pub async fn executions<U, F, Fut>(
    ud: &U,
    rx: &mut Receiver<Envelope>,
    source: &str,
    id: &InstrumentId,
    price: Price,
    fill: F,
)
where U: OrderExecutor + ExecutionSource + ?Sized, F: FnOnce(ClientOrderId) -> Fut, Fut: Future<Output = ()>,
Expand description

Own executions: the history works, and a fill arrives as an Execution event and in the history.

Steps and checks:

  1. executions(range) over a very wide range succeeds on an empty account.
  2. subscribe_executions.
  3. Place a buy limit order, two lots, at price (rate-limit refusals are waited out and retried under a fresh cid), then call fill(cid).
  4. An [brokapi_core::Event::Execution] arrives. Its source is source, its sub is the executions subscription, its cid is ours, price and quantity are positive, the trade id is not empty and the instrument is id.
  5. executions(range) now lists at least one trade, each with a positive price, positive quantity and a trade id.

fill(cid) makes the mock execute the order. Each mock has its own way, so the adapter provides it. It may wait until the stream is open. It runs once. price must be far from the market and accepted by the mock, and the fill itself is the mock’s business. The command gate must be open, so call reconcile first, and wait for the adapter’s event socket if it connects in the background.

§Panics

With [conformance:executions] <reason> when a call fails, no execution arrives in time, or a check fails.

§Examples

brokapi_conformance::reconcile(&ud).await;
brokapi_conformance::executions(&ud, &mut rx, "bcs-ud", &sber, Price::from(100), |cid| {
    // The BCS mock executes an order when told: cid, quantity, price.
    let _ = server.fill(&cid.hyphenated().to_string(), brokapi_core::Qty::from(20), brokapi_core::Price::from(100));
    async {}
})
.await;

§use brokapi_core::{Qty};