Skip to main content

replace_order

Function replace_order 

Source
pub async fn replace_order<U: OrderExecutor + ?Sized>(
    ud: &U,
    supports_replace: bool,
    id: &InstrumentId,
    price: Price,
    new_price: Price,
)
Expand description

replace: where the broker has it the order moves to a new cid, where it has not, replace says Unsupported.

supports_replace is what the adapter reports in its capabilities. The scenario places a buy limit order (two lots, at price) and then replaces it with a new cid, four lots and price new_price.

With supports_replace == true:

  • the ack carries the new cid;
  • active_orders() lists the new cid with four lots and price new_price, and no longer lists the old one;
  • order_state(new cid) is not Rejected or Cancelled.

With supports_replace == false:

  • replace returns [brokapi_core::Error::Unsupported];
  • the original order is still active. It is then cancelled.

Rate-limit refusals are waited out and retried. Both prices must be far from the market and accepted by the mock. The command gate must be open, so call reconcile first.

§Panics

With [conformance:replace_order] <reason> when a check fails. Passing the wrong supports_replace for the adapter fails the scenario: true for an adapter without replace gives a replace error, false for one with replace gives “replace must be Unsupported where the broker has none”.

§Examples

brokapi_conformance::reconcile(&ud).await;
assert!(ud.caps().supports_replace);
brokapi_conformance::replace_order(&ud, true, &sber, Price::from(100), Price::from(101)).await;

Claiming that BCS has no replace fails the scenario:

ⓘ
brokapi_conformance::reconcile(&ud).await;
// panics: [conformance:replace_order] replace must be Unsupported where the broker has none, got ...
brokapi_conformance::replace_order(&ud, false, &sber, Price::from(100), Price::from(101)).await;