pub struct ReduceOnlyBook { /* private fields */ }Expand description
One instrument’s record of which orders were sent reduce-only. Plain data with no locking and no I/O, so the owner keeps it behind whatever synchronisation it already has, one book for each instrument.
The owner calls, for each order:
registerwhen the open request is sent,acknowledgewhen the venue reports the order’s id, andretirewhen the order ends. Every order must be retired, or the book keeps it for good.
Then lookup finds the flag of a fill’s order.
A retired order stays findable only if it was reduce-only, and only the last
RETIRED_CAPACITY of those, oldest dropped first, so that a late
fill of one is still recognised and ordinary orders do not push them out. A late fill of any
other retired order is not found: read that as not reduce-only.
§Serialised form
{"live": {<cid>: {"reduce_only": bool, "venue_id": <id>|null}}, "retired": {<cid>: <id>|null}},
each map in order, either part optional. It is stored as part of its owner’s state, so a
change to it is a breaking change. A book loaded with more retired orders than
RETIRED_CAPACITY keeps the latest.
Implementations§
Source§impl ReduceOnlyBook
impl ReduceOnlyBook
Sourcepub const RETIRED_CAPACITY: usize = 64
pub const RETIRED_CAPACITY: usize = 64
How many retired reduce-only orders the book keeps.
Sourcepub fn live_len(&self) -> usize
pub fn live_len(&self) -> usize
How many orders are live: registered and not yet retired. An owner that retires every order sees this fall back to the number it has open.
Sourcepub fn has_reduce_only(&self) -> bool
pub fn has_reduce_only(&self) -> bool
Whether any order the book holds is reduce-only, live or retired. When it is not, every
lookup finds no reduce-only order, so a caller can skip it. O(1).
Sourcepub fn register(&mut self, cid: &ClientOrderId, reduce_only: bool)
pub fn register(&mut self, cid: &ClientOrderId, reduce_only: bool)
Record that the open request cid is being sent, reduce-only or not.
A client order id reused for a new order replaces everything an earlier order under it left, live or retired, so its flag does not outlive the order. The new order counts as the latest registered. Registering a client order id that is still live replaces that order, dropping the venue order id it was acknowledged with, so register once for each order sent.
Sourcepub fn acknowledge(&mut self, cid: &ClientOrderId, venue_id: &OrderId)
pub fn acknowledge(&mut self, cid: &ClientOrderId, venue_id: &OrderId)
Record the venue’s order id for cid, live or retired, so a fill that names only that id
finds the order. Replaces an id given before. Does nothing for an order the book does not
hold.
An order can end before its id is known, such as one filled on its acknowledgement, so a retired order takes it too.
Sourcepub fn retire(&mut self, cid: &ClientOrderId)
pub fn retire(&mut self, cid: &ClientOrderId)
Record that the order cid ended. Does nothing for an order the book does not hold.
A reduce-only order moves to the retired orders, dropping the oldest of them when there
are RETIRED_CAPACITY. Any other order is forgotten.
Sourcepub fn retire_untracked(
&mut self,
is_tracked: impl FnMut(&ClientOrderId) -> bool,
)
pub fn retire_untracked( &mut self, is_tracked: impl FnMut(&ClientOrderId) -> bool, )
retire every live order for which is_tracked is false, in the order
they were registered, so which retirement is dropped first never depends on hashing.
One pass over the live orders, so O(live orders), and it allocates only when a reduce-only order ended.
Sourcepub fn lookup<AssetKey, InstrumentKey>(
&self,
trade: &Trade<AssetKey, InstrumentKey>,
) -> Option<BookedOrder<'_>>
pub fn lookup<AssetKey, InstrumentKey>( &self, trade: &Trade<AssetKey, InstrumentKey>, ) -> Option<BookedOrder<'_>>
Find the order a fill belongs to.
By the fill’s client order id if it has one, and else by its venue order id: a live order first, then a retired one. A client order id the book does not hold finds nothing, and does not fall back to the venue’s id.
Sourcepub fn lookup_ids(
&self,
cid: Option<&ClientOrderId>,
order_id: &OrderId,
) -> Option<BookedOrder<'_>>
pub fn lookup_ids( &self, cid: Option<&ClientOrderId>, order_id: &OrderId, ) -> Option<BookedOrder<'_>>
lookup for the ids of a fill, for a caller that resolved the client order
id itself. A cid the book does not hold finds nothing and does not fall back to
order_id; pass None to look up by the venue’s id alone.
Sourcepub fn is_reduce_only<AssetKey, InstrumentKey>(
&self,
trade: &Trade<AssetKey, InstrumentKey>,
) -> bool
pub fn is_reduce_only<AssetKey, InstrumentKey>( &self, trade: &Trade<AssetKey, InstrumentKey>, ) -> bool
Whether trade is a fill of an order sent reduce-only: lookup with an
order the book does not hold counted as not.
Trait Implementations§
Source§impl Clone for ReduceOnlyBook
impl Clone for ReduceOnlyBook
Source§impl Debug for ReduceOnlyBook
impl Debug for ReduceOnlyBook
Source§impl Default for ReduceOnlyBook
impl Default for ReduceOnlyBook
Source§impl<'de> Deserialize<'de> for ReduceOnlyBook
impl<'de> Deserialize<'de> for ReduceOnlyBook
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for ReduceOnlyBook
Source§impl PartialEq for ReduceOnlyBook
impl PartialEq for ReduceOnlyBook
Source§impl Serialize for ReduceOnlyBook
impl Serialize for ReduceOnlyBook
impl StructuralPartialEq for ReduceOnlyBook
Auto Trait Implementations§
impl Freeze for ReduceOnlyBook
impl RefUnwindSafe for ReduceOnlyBook
impl Send for ReduceOnlyBook
impl Sync for ReduceOnlyBook
impl Unpin for ReduceOnlyBook
impl UnsafeUnpin for ReduceOnlyBook
impl UnwindSafe for ReduceOnlyBook
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> JsonSchemaMaybe for T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.