pub struct L3 {
pub price_head: BTreeMap<u64, OrderId>,
pub price_tail: BTreeMap<u64, OrderId>,
pub order_nodes: HashMap<OrderId, Node>,
pub orders: HashMap<OrderId, Order>,
pub dust: u64,
pub dormant_order: Option<OrderId>,
}Fields§
§price_head: BTreeMap<u64, OrderId>Mapping price -> head of the linked list in a price level.
price_tail: BTreeMap<u64, OrderId>Mapping price -> last of the linked list in a price level.
order_nodes: HashMap<OrderId, Node>Order details keyed by id. Mapping order_id -> Order.
orders: HashMap<OrderId, Order>Mapping order_id -> Order.
dust: u64dust limit to determine if the order should be deleted
dormant_order: Option<OrderId>Last displaced order when IDs collide.
Implementations§
Source§impl L3
impl L3
pub fn new() -> Self
Sourcepub fn set_dust(&mut self, dust: u64)
pub fn set_dust(&mut self, dust: u64)
Sets the dust limit to determine if the order should be deleted
Sourcepub fn insert_id(
&mut self,
price: u64,
id: OrderId,
_amount: u128,
) -> Result<(), L3Error>
pub fn insert_id( &mut self, price: u64, id: OrderId, _amount: u128, ) -> Result<(), L3Error>
Inserts an order id into the linked structure for a given price level, keeping FIFO (append at tail).
Sourcepub fn pop_front(
&mut self,
price: u64,
) -> Result<(Option<Order>, bool), L3Error>
pub fn pop_front( &mut self, price: u64, ) -> Result<(Option<Order>, bool), L3Error>
Removes and returns the first order id at the given price level. returns (order_id, is_empty)
order_idis the id of the first order in the price level.is_emptyis true when the price level becomes empty.
pub fn set_iceberg_quantity( &mut self, id: OrderId, iqty: u64, ) -> Result<Order, L3Error>
Sourcepub fn create_order(
&mut self,
cid: impl Into<Vec<u8>>,
owner: impl Into<Vec<u8>>,
is_bid: bool,
price: u64,
amnt: u64,
iqty: u64,
timestamp: i64,
expires_at: i64,
maker_fee_bps: i16,
) -> Result<Order, L3Error>
pub fn create_order( &mut self, cid: impl Into<Vec<u8>>, owner: impl Into<Vec<u8>>, is_bid: bool, price: u64, amnt: u64, iqty: u64, timestamp: i64, expires_at: i64, maker_fee_bps: i16, ) -> Result<Order, L3Error>
Creates a new order, assigning the next id. Returns the new order id.
Sourcepub fn decrease_order(
&mut self,
id: OrderId,
amount: u64,
dust: u64,
clear: bool,
) -> Result<(u64, Option<u64>), L3Error>
pub fn decrease_order( &mut self, id: OrderId, amount: u64, dust: u64, clear: bool, ) -> Result<(u64, Option<u64>), L3Error>
Decreases the deposit amount for a given order id.
If the order is the order that needs to be cleared by floating point precision, the amount_to_send will be the full amount of the order.
Returns (amount_to_send, deleted_price_if_level_empty) where:
amount_to_sendis the liquidity that should be returned to the caller. based on the dust limit and the clear flag.deleted_price_if_level_emptyisSome(price)when the price level becomes empty.
Sourcepub fn delete_order(&mut self, id: OrderId) -> Result<Option<u64>, L3Error>
pub fn delete_order(&mut self, id: OrderId) -> Result<Option<u64>, L3Error>
Deletes an order from the storage, returning the price level if it becomes empty.
- returns the price level if it becomes empty.
Sourcepub fn next_make_id(&self) -> OrderId
pub fn next_make_id(&self) -> OrderId
Returns the next id that would be assigned on order creation.
Sourcepub fn get_order_ids(&self, price: u64, n: u32) -> Vec<OrderId> ⓘ
pub fn get_order_ids(&self, price: u64, n: u32) -> Vec<OrderId> ⓘ
Collects up to n order ids from the front of the specified price level.
Sourcepub fn get_orders(&self, price: u64, n: u32) -> Vec<Order>
pub fn get_orders(&self, price: u64, n: u32) -> Vec<Order>
Collects up to n orders from the front of the specified price level.
Sourcepub fn get_orders_in_range(
&self,
price: u64,
start: u32,
end: u32,
) -> Vec<Order>
pub fn get_orders_in_range( &self, price: u64, start: u32, end: u32, ) -> Vec<Order>
Collects orders within the [start, end) window from the specified price level.