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: SymbolImplementations§
Source§impl Order
impl Order
Sourcepub fn new(
order_type: OrderType,
quantity: Quantity,
side: OrderSide,
symbol: Symbol,
) -> Order
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 tradeside- Whether this is a Buy or Sell ordersymbol- 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());Sourcepub fn with_id(self) -> Self
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());Sourcepub fn get_id(&self) -> OrderId
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();Sourcepub fn with_reduced_quantity(&self, quantity: &Quantity) -> Order
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());Trait Implementations§
Source§impl Ord for Order
impl Ord for Order
Source§impl PartialOrd for Order
impl PartialOrd for Order
impl Eq for Order
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> 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
Mutably borrows from an owned value. Read more