Skip to main content

OrderType

Enum OrderType 

Source
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

§id: Id

The order ID

§price: Price

The price of the order

§quantity: Quantity

The quantity of the order

§side: Side

The side of the order (buy or sell)

§user_id: Hash32

Owner identifier for fast lookup (32 bytes)

§timestamp: TimestampMs

When the order was created

§time_in_force: TimeInForce

Time-in-force policy

§extra_fields: T

Additional custom fields

§

IcebergOrder

Iceberg order with visible and hidden quantities

Fields

§id: Id

The order ID

§price: Price

The price of the order

§visible_quantity: Quantity

The visible quantity of the order

§hidden_quantity: Quantity

The hidden quantity of the order

§side: Side

The side of the order (buy or sell)

§user_id: Hash32

Owner identifier for fast lookup (32 bytes)

§timestamp: TimestampMs

When the order was created

§time_in_force: TimeInForce

Time-in-force policy

§extra_fields: T

Additional custom fields

§

PostOnly

Post-only order that won’t match immediately

Fields

§id: Id

The order ID

§price: Price

The price of the order

§quantity: Quantity

The quantity of the order

§side: Side

The side of the order (buy or sell)

§user_id: Hash32

Owner identifier for fast lookup (32 bytes)

§timestamp: TimestampMs

When the order was created

§time_in_force: TimeInForce

Time-in-force policy

§extra_fields: T

Additional custom fields

§

TrailingStop

Trailing stop order that adjusts with market movement

Fields

§id: Id

The order ID

§price: Price

The price of the order

§quantity: Quantity

The quantity of the order

§side: Side

The side of the order (buy or sell)

§user_id: Hash32

Owner identifier for fast lookup (32 bytes)

§timestamp: TimestampMs

When the order was created

§time_in_force: TimeInForce

Time-in-force policy

§trail_amount: Quantity

Amount to trail the market price

§last_reference_price: Price

Last reference price

§extra_fields: T

Additional custom fields

§

PeggedOrder

Pegged order that adjusts based on reference price

Fields

§id: Id

The order ID

§price: Price

The price of the order

§quantity: Quantity

The quantity of the order

§side: Side

The side of the order (buy or sell)

§user_id: Hash32

Owner identifier for fast lookup (32 bytes)

§timestamp: TimestampMs

When the order was created

§time_in_force: TimeInForce

Time-in-force policy

§reference_price_offset: i64

Offset from the reference price

§reference_price_type: PegReferenceType

Type of reference price to track

§extra_fields: T

Additional custom fields

§

MarketToLimit

Market-to-limit order that converts to limit after initial execution

Fields

§id: Id

The order ID

§price: Price

The price of the order

§quantity: Quantity

The quantity of the order

§side: Side

The side of the order (buy or sell)

§user_id: Hash32

Owner identifier for fast lookup (32 bytes)

§timestamp: TimestampMs

When the order was created

§time_in_force: TimeInForce

Time-in-force policy

§extra_fields: T

Additional 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

§id: Id

The order ID

§price: Price

The price of the order

§visible_quantity: Quantity

The visible quantity of the order

§hidden_quantity: Quantity

The hidden quantity of the order

§side: Side

The side of the order (buy or sell)

§user_id: Hash32

Owner identifier for fast lookup (32 bytes)

§timestamp: TimestampMs

When the order was created

§time_in_force: TimeInForce

Time-in-force policy

§replenish_threshold: Quantity

Threshold at which to replenish

§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: bool

Whether to replenish automatically when below threshold. If false, only replenish on next match

§extra_fields: T

Additional custom fields

Implementations§

Source§

impl<T: Clone> OrderType<T>

Source

pub fn id(&self) -> Id

Get the order ID

Source

pub fn user_id(&self) -> Hash32

Get the user ID associated with this order

Source

pub fn price(&self) -> Price

Get the price

Source

pub fn visible_quantity(&self) -> Quantity

Get the visible quantity, in quantity units.

Source

pub fn hidden_quantity(&self) -> Quantity

Get the hidden quantity, in quantity units.

Order types without a hidden tranche return Quantity::ZERO.

Source

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_replenish is 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.
Source

pub fn side(&self) -> Side

Get the order side

Source

pub fn time_in_force(&self) -> TimeInForce

Get the time in force

Source

pub fn timestamp(&self) -> TimestampMs

Get the timestamp at which the order was created, in milliseconds.

Source

pub fn is_immediate(&self) -> bool

Check if the order is immediate-or-cancel

Source

pub fn is_fill_or_kill(&self) -> bool

Check if the order is fill-or-kill

Source

pub fn is_post_only(&self) -> bool

Check if this is a post-only order

Source

pub fn with_reduced_quantity(&self, new_quantity: u64) -> Self

Create a new standard order with reduced quantity

Source

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>

Source

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>

Source

pub fn extra_fields(&self) -> &T

Get the extra fields

Source

pub fn extra_fields_mut(&mut self) -> &mut T

Get mutable reference to extra fields

Source

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§

Source§

impl<T: Clone> Clone for OrderType<T>

Source§

fn clone(&self) -> OrderType<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Copy> Copy for OrderType<T>

Source§

impl<T: Debug> Debug for OrderType<T>

Source§

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

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

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

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Display for OrderType<T>

Source§

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

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

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]

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
Source§

type Err = PriceLevelError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<T: PartialEq> PartialEq for OrderType<T>

Source§

fn eq(&self, other: &OrderType<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Serialize for OrderType<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for OrderType<T>

Auto Trait Implementations§

§

impl<T> Freeze for OrderType<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for OrderType<T>
where T: RefUnwindSafe,

§

impl<T> Send for OrderType<T>
where T: Send,

§

impl<T> Sync for OrderType<T>
where T: Sync,

§

impl<T> Unpin for OrderType<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for OrderType<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for OrderType<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more