pub enum OrderType<T> {
Standard {
id: Id,
price: Price,
quantity: Quantity,
side: Side,
user_id: Hash32,
timestamp: TimestampMs,
time_in_force: TimeInForce,
extra_fields: T,
},
IcebergOrder {
id: Id,
price: Price,
visible_quantity: Quantity,
hidden_quantity: Quantity,
side: Side,
user_id: Hash32,
timestamp: TimestampMs,
time_in_force: TimeInForce,
extra_fields: T,
},
PostOnly {
id: Id,
price: Price,
quantity: Quantity,
side: Side,
user_id: Hash32,
timestamp: TimestampMs,
time_in_force: TimeInForce,
extra_fields: T,
},
TrailingStop {
id: Id,
price: Price,
quantity: Quantity,
side: Side,
user_id: Hash32,
timestamp: TimestampMs,
time_in_force: TimeInForce,
trail_amount: Quantity,
last_reference_price: Price,
extra_fields: T,
},
PeggedOrder {
id: Id,
price: Price,
quantity: Quantity,
side: Side,
user_id: Hash32,
timestamp: TimestampMs,
time_in_force: TimeInForce,
reference_price_offset: i64,
reference_price_type: PegReferenceType,
extra_fields: T,
},
MarketToLimit {
id: Id,
price: Price,
quantity: Quantity,
side: Side,
user_id: Hash32,
timestamp: TimestampMs,
time_in_force: TimeInForce,
extra_fields: T,
},
ReserveOrder {
id: Id,
price: Price,
visible_quantity: Quantity,
hidden_quantity: Quantity,
side: Side,
user_id: Hash32,
timestamp: TimestampMs,
time_in_force: TimeInForce,
replenish_threshold: Quantity,
replenish_amount: Option<NonZeroU64>,
auto_replenish: bool,
extra_fields: T,
},
}Expand description
Represents different types of limit orders
Variants§
Standard
Standard limit order
Fields
timestamp: TimestampMsWhen the order was created
time_in_force: TimeInForceTime-in-force policy
extra_fields: TAdditional custom fields
IcebergOrder
Iceberg order with visible and hidden quantities
Fields
The hidden quantity of the order
timestamp: TimestampMsWhen the order was created
time_in_force: TimeInForceTime-in-force policy
extra_fields: TAdditional custom fields
PostOnly
Post-only order that won’t match immediately
Fields
timestamp: TimestampMsWhen the order was created
time_in_force: TimeInForceTime-in-force policy
extra_fields: TAdditional custom fields
TrailingStop
Trailing stop order that adjusts with market movement
Fields
timestamp: TimestampMsWhen the order was created
time_in_force: TimeInForceTime-in-force policy
extra_fields: TAdditional custom fields
PeggedOrder
Pegged order that adjusts based on reference price
Fields
timestamp: TimestampMsWhen the order was created
time_in_force: TimeInForceTime-in-force policy
reference_price_type: PegReferenceTypeType of reference price to track
extra_fields: TAdditional custom fields
MarketToLimit
Market-to-limit order that converts to limit after initial execution
Fields
timestamp: TimestampMsWhen the order was created
time_in_force: TimeInForceTime-in-force policy
extra_fields: TAdditional custom fields
ReserveOrder
Reserve order with custom replenishment
if replenish_amount is None, it uses DEFAULT_RESERVE_REPLENISH_AMOUNT
if auto_replenish is false, and visible quantity is below threshold, it will not replenish
if auto_replenish is false and visible quantity is zero it will be removed from the book
if auto_replenish is true, and replenish_threshold is 0, it will use 1
Fields
The hidden quantity of the order
timestamp: TimestampMsWhen the order was created
time_in_force: TimeInForceTime-in-force policy
replenish_amount: Option<NonZeroU64>Optional amount to replenish by, in quantity units. If None, uses
DEFAULT_RESERVE_REPLENISH_AMOUNT. A replenish amount is
structurally non-zero (NonZeroU64): a zero replenish would draw
an empty visible tranche from hidden.
auto_replenish: boolWhether to replenish automatically when below threshold. If false, only replenish on next match
extra_fields: TAdditional custom fields
Implementations§
Source§impl<T: Clone> OrderType<T>
impl<T: Clone> OrderType<T>
Sourcepub fn visible_quantity(&self) -> Quantity
pub fn visible_quantity(&self) -> Quantity
Get the visible quantity, in quantity units.
Get the hidden quantity, in quantity units.
Order types without a hidden tranche return Quantity::ZERO.
Sourcepub fn is_matchable(&self) -> bool
pub fn is_matchable(&self) -> bool
Returns true if this resting order can yield a fill for a crossing
taker, i.e. a positive taker would take some quantity from it.
This is the single source of truth for “matchable depth” shared by the
post-only pre-check (has_matchable_depth) and the fill-or-kill dry run
(matchable_quantity), so the two can never disagree about the same level
(those are private price-level helpers, named here as plain spans rather
than doc links):
- Any order with positive visible quantity is matchable.
- A zero-visible iceberg with hidden quantity is matchable: the sweep replenishes its entire hidden into visible and then fills it.
- A zero-visible reserve with hidden quantity is matchable only if
auto_replenishis set; without auto-replenish a drained reserve is dropped by the sweep without ever filling, so it is not matchable depth. - Every other zero-visible order (no hidden to draw on) is not matchable.
Sourcepub fn time_in_force(&self) -> TimeInForce
pub fn time_in_force(&self) -> TimeInForce
Get the time in force
Sourcepub fn timestamp(&self) -> TimestampMs
pub fn timestamp(&self) -> TimestampMs
Get the timestamp at which the order was created, in milliseconds.
Sourcepub fn is_immediate(&self) -> bool
pub fn is_immediate(&self) -> bool
Check if the order is immediate-or-cancel
Sourcepub fn is_fill_or_kill(&self) -> bool
pub fn is_fill_or_kill(&self) -> bool
Check if the order is fill-or-kill
Sourcepub fn is_post_only(&self) -> bool
pub fn is_post_only(&self) -> bool
Check if this is a post-only order
Sourcepub fn with_reduced_quantity(&self, new_quantity: u64) -> Self
pub fn with_reduced_quantity(&self, new_quantity: u64) -> Self
Create a new standard order with reduced quantity
Sourcepub fn refresh_iceberg(&self, refresh_amount: NonZeroU64) -> (Self, u64)
pub fn refresh_iceberg(&self, refresh_amount: NonZeroU64) -> (Self, u64)
Update an iceberg or reserve order, refreshing the visible part from hidden.
refresh_amount is the tranche size to draw from the hidden quantity,
in quantity units. It is NonZeroU64 because a zero refresh would
draw an empty visible tranche, silently leaving nothing visible. The
amount actually drawn is capped at the remaining hidden quantity.
Returns the refreshed order and the quantity drawn from hidden. For a
non-iceberg / non-reserve order the order is returned unchanged with a
drawn quantity of 0.
Source§impl<T: Clone> OrderType<T>
impl<T: Clone> OrderType<T>
Sourcepub fn match_against(
&self,
incoming_quantity: u64,
) -> (u64, Option<Self>, u64, u64)
pub fn match_against( &self, incoming_quantity: u64, ) -> (u64, Option<Self>, u64, u64)
Matches this order against an incoming quantity
Returns a tuple containing:
- The quantity consumed from the incoming order
- Optionally, an updated version of this order (if partially filled)
- The quantity that was reduced from hidden portion (for iceberg/reserve orders)
- The remaining quantity of the incoming order
Source§impl<T> OrderType<T>
impl<T> OrderType<T>
Sourcepub fn extra_fields(&self) -> &T
pub fn extra_fields(&self) -> &T
Get the extra fields
Sourcepub fn extra_fields_mut(&mut self) -> &mut T
pub fn extra_fields_mut(&mut self) -> &mut T
Get mutable reference to extra fields
Sourcepub fn map_extra_fields<U, F>(self, f: F) -> OrderType<U>where
F: FnOnce(T) -> U,
pub fn map_extra_fields<U, F>(self, f: F) -> OrderType<U>where
F: FnOnce(T) -> U,
Transform the extra fields type using a function
Trait Implementations§
impl<T: Copy> Copy for OrderType<T>
Source§impl<'de, T> Deserialize<'de> for OrderType<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for OrderType<T>where
T: Deserialize<'de>,
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<T: Eq> Eq for OrderType<T>
Source§impl<T: Default> FromStr for OrderType<T>
Expected string format:
ORDER_TYPE:id=<id>;price=<price>;quantity=<qty>;side=<BUY|SELL>;timestamp=<ts>;time_in_force=<tif>;[additional fields]
impl<T: Default> FromStr for OrderType<T>
Expected string format:
ORDER_TYPE:id=<id>;price=<price>;quantity=<qty>;side=<BUY|SELL>;timestamp=<ts>;time_in_force=<tif>;[additional fields]
Examples:
- Standard:id=123;price=10000;quantity=5;side=BUY;timestamp=1616823000000;time_in_force=GTC
- IcebergOrder:id=124;price=10000;visible_quantity=1;hidden_quantity=4;side=SELL;timestamp=1616823000000;time_in_force=GTC