Skip to main content

L3

Struct L3 

Source
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: u64

dust limit to determine if the order should be deleted

§dormant_order: Option<OrderId>

Last displaced order when IDs collide.

Implementations§

Source§

impl L3

Source

pub fn new() -> Self

Source

pub fn set_dust(&mut self, dust: u64)

Sets the dust limit to determine if the order should be deleted

Source

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).

Source

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_id is the id of the first order in the price level.
  • is_empty is true when the price level becomes empty.
Source

pub fn set_iceberg_quantity( &mut self, id: OrderId, iqty: u64, ) -> Result<Order, L3Error>

Source

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.

Source

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_send is the liquidity that should be returned to the caller. based on the dust limit and the clear flag.
  • deleted_price_if_level_empty is Some(price) when the price level becomes empty.
Source

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

pub fn next_make_id(&self) -> OrderId

Returns the next id that would be assigned on order creation.

Source

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.

Source

pub fn get_orders(&self, price: u64, n: u32) -> Vec<Order>

Collects up to n orders from the front of the specified price level.

Source

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.

Source

pub fn head(&self, price: u64) -> Option<OrderId>

Source

pub fn tail(&self, price: u64) -> Option<OrderId>

Source

pub fn is_empty(&self, price: u64) -> bool

Source

pub fn next(&self, _price: u64, current: OrderId) -> Option<OrderId>

Source

pub fn get_order(&self, id: OrderId) -> Result<&Order, L3Error>

Source

pub fn remove_dormant_orders(&mut self, now: i64) -> Vec<(OrderId, Order)>

Remove orders that have expired. Returns removed order ids.

Trait Implementations§

Source§

impl Clone for L3

Source§

fn clone(&self) -> Self

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 Debug for L3

Source§

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

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

impl Default for L3

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for L3

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 Eq for L3

Source§

impl PartialEq for L3

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for L3

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 StructuralPartialEq for L3

Auto Trait Implementations§

§

impl Forget for L3

§

impl Freeze for L3

§

impl RefUnwindSafe for L3

§

impl Send for L3

§

impl Sync for L3

§

impl Unpin for L3

§

impl UnsafeUnpin for L3

§

impl UnwindSafe for L3

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<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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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