Skip to main content

Order

Struct Order 

Source
pub struct Order {
    pub id: Option<OrderId>,
    pub order_type: OrderType,
    pub quantity: Quantity,
    pub side: OrderSide,
    pub symbol: Symbol,
}
Expand description

A trading order in the Central Limit Order Book.

§Example

use clob_sync::order::{Order, OrderType, OrderSide, Quantity, Price, Symbol};
use fastnum::D128 as Dec;
use fastnum::decimal::Context;
use std::str::FromStr;

let order = Order::new(
    OrderType::Limit(Price::try_from("50000.50").unwrap()),
    Quantity::try_from("1.5").unwrap(),
    OrderSide::Buy,
    Symbol::from("BTC-USD"),
);

Fields§

§id: Option<OrderId>§order_type: OrderType§quantity: Quantity§side: OrderSide§symbol: Symbol

Implementations§

Source§

impl Order

Source

pub fn new( order_type: OrderType, quantity: Quantity, side: OrderSide, symbol: Symbol, ) -> Order

Creates a new order without an ID. The order must be assigned an ID before it can be executed.

§Arguments
  • order_type - The type of order (Limit or Market)
  • quantity - The quantity to trade
  • side - Whether this is a Buy or Sell order
  • symbol - The trading symbol (e.g., “BTC-USD”)
§Example
use clob_sync::order::{Order, OrderType, OrderSide, Quantity, Price, Symbol};
use fastnum::D128 as Dec;
use fastnum::decimal::Context;
use std::str::FromStr;

let order = Order::new(
    OrderType::Limit(Price::try_from("50000.00").unwrap()),
    Quantity::from(1u64),
    OrderSide::Buy,
    Symbol::from("BTC-USD"),
);
assert!(order.id.is_none());
Source

pub fn with_id(self) -> Self

Assigns a time-based UUIDv7 order ID to this order.

UUIDv7 guarantees monotonic ordering within the same millisecond, making it suitable for order priority determination.

§Example
use clob_sync::order::{Order, OrderType, OrderSide, Quantity, Price, Symbol};
use fastnum::D128 as Dec;
use fastnum::decimal::Context;
use std::str::FromStr;

let mut order = Order::new(
    OrderType::Limit(Price::try_from("50000.00").unwrap()),
    Quantity::from(1u64),
    OrderSide::Buy,
    Symbol::from("BTC-USD"),
);
order = order.with_id();
assert!(order.id.is_some());
Source

pub fn get_id(&self) -> OrderId

Returns the order ID.

§Panics

Panics if the order has not been assigned an ID via with_id.

§Example
use clob_sync::order::{Order, OrderType, OrderSide, Quantity, Price, Symbol};
use fastnum::D128 as Dec;
use fastnum::decimal::Context;
use std::str::FromStr;

let order = Order::new(
    OrderType::Limit(Price::try_from("50000.00").unwrap()),
    Quantity::from(1u64),
    OrderSide::Buy,
    Symbol::from("BTC-USD"),
).with_id();

let _id = order.get_id();
Source

pub fn with_reduced_quantity(&self, quantity: &Quantity) -> Order

Creates a new order with the quantity reduced by the specified amount.

This is useful when an order is partially filled and the remaining quantity needs to be tracked.

§Arguments
  • quantity - The quantity to subtract from this order’s quantity
§Example
use clob_sync::order::{Order, OrderType, OrderSide, Quantity, Price, Symbol};
use fastnum::D128 as Dec;
use fastnum::decimal::Context;
use std::str::FromStr;

let order = Order::new(
    OrderType::Limit(Price::try_from("50000.00").unwrap()),
    Quantity::try_from("10.0").unwrap(),
    OrderSide::Buy,
    Symbol::from("BTC-USD"),
);

let remaining = order.with_reduced_quantity(&Quantity::try_from("3.0").unwrap());
assert_eq!(remaining.quantity, Quantity::try_from("7.0").unwrap());
Source§

impl Order

Source

pub fn with_quantity(&self, quantity: Quantity) -> Order

Trait Implementations§

Source§

impl Clone for Order

Source§

fn clone(&self) -> Order

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Order

Source§

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

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

impl Ord for Order

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Order

Source§

fn eq(&self, other: &Order) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 PartialOrd for Order

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Order

Source§

impl StructuralPartialEq for Order

Auto Trait Implementations§

§

impl Freeze for Order

§

impl RefUnwindSafe for Order

§

impl Send for Order

§

impl Sync for Order

§

impl Unpin for Order

§

impl UnsafeUnpin for Order

§

impl UnwindSafe for Order

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<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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> 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> 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, 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