Skip to main content

OrderRegistry

Struct OrderRegistry 

Source
pub struct OrderRegistry { /* private fields */ }
Expand description

Many OrderFsms keyed by client order id.

§Examples

use std::time::{Duration, Instant};
use brokapi_core::{ClientOrderId, OrderState};
use brokapi_sansio::OrderRegistry;

let mut registry = OrderRegistry::new();
let t0 = Instant::now();
let (a, b) = (ClientOrderId::new_v4(), ClientOrderId::new_v4());
registry.register_place(a, t0);
registry.register_place(b, t0 + Duration::from_secs(20));

// 31 s after `a` was sent, with a 30 s limit: only `a` has gone silent.
let changed = registry.on_global_timeout(t0 + Duration::from_secs(31), Duration::from_secs(30));
assert_eq!(changed.len(), 1);
assert_eq!(changed[0].0, a);
assert!(matches!(changed[0].1, OrderState::Unknown { .. }));
assert_eq!(registry.in_flight_cids(), vec![b]);

Implementations§

Source§

impl OrderRegistry

Source

pub fn new() -> Self

Creates an empty registry.

Source

pub fn register_place(&mut self, cid: ClientOrderId, now: Instant)

Starts tracking cid as InFlight, sent at now. An order already tracked under this cid is replaced.

Source

pub fn apply( &mut self, cid: ClientOrderId, signal: OrderSignal, now: Instant, ) -> Result<Option<OrderState>, FsmError>

Applies a signal to the order cid, see OrderFsm::apply for the result.

§Errors

FsmError::UnknownOrder when cid is not tracked, and every error of OrderFsm::apply.

Source

pub fn get(&self, cid: ClientOrderId) -> Option<&OrderFsm>

The state machine of cid, if tracked.

Source

pub fn forget_finished(&mut self, cid: ClientOrderId) -> bool

Stops tracking cid, but only if its order is finished (Filled, Cancelled or Rejected). Returns true when it was removed. A live order, or an unknown cid, is left alone.

Source

pub fn len(&self) -> usize

How many orders are tracked, in any state.

Source

pub fn is_empty(&self) -> bool

true when no order is tracked.

Source

pub fn in_flight_cids(&self) -> Vec<ClientOrderId> ⓘ

The cids of all orders now in state InFlight, in no particular order.

Source

pub fn abandon_inflight( &mut self, now: Instant, ) -> Vec<(ClientOrderId, OrderState)>

Moves every InFlight order to Unknown now, whatever its age (shutdown).

Returns each changed cid with its new state. Nothing is sent to the broker.

Source

pub fn on_global_timeout( &mut self, now: Instant, timeout: Duration, ) -> Vec<(ClientOrderId, OrderState)>

Moves every InFlight order that has waited timeout or longer (since it was registered) to Unknown, and returns the changed ones with their new state.

Nothing is sent to the broker. Orders in other states are not touched.

Trait Implementations§

Source§

impl Debug for OrderRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for OrderRegistry

Source§

fn default() -> OrderRegistry

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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, 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, 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.