pub struct OrderBook {
pub l2: L2,
pub l3: L3,
pub fee_recipients: HashMap<Vec<u8>, Vec<u8>>,
pub dust: u64,
}Expand description
In-memory order book for spot markets.
l2is the L2 state of the orderbook.l3is the L3 state of the orderbook.fee_recipientsis the map of client id to fee recipient account id.dustis the dust limit to determine if the order should be deleted.
Fields§
§l2: L2§l3: L3§fee_recipients: HashMap<Vec<u8>, Vec<u8>>§dust: u64Implementations§
Source§impl OrderBook
impl OrderBook
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 get_required(
&self,
taker_order: Order,
price: u64,
amount: u64,
) -> Result<u64, OrderBookError>
pub fn get_required( &self, taker_order: Order, price: u64, amount: u64, ) -> Result<u64, OrderBookError>
Gets the required amount to match an order as taker to match with the maker order and clear it.
taker_orderis the taker order.priceis the price of the maker order.amountis the amount of the taker order to match with the maker order.
Sourcepub fn clear_empty_head(&mut self, is_bid: bool) -> Result<u64, OrderBookError>
pub fn clear_empty_head(&mut self, is_bid: bool) -> Result<u64, OrderBookError>
clears empty head of the order book where price is in linked list, but order is not in the price level
Sourcepub fn clear_empty_head_or_zero(&mut self, is_bid: bool) -> u64
pub fn clear_empty_head_or_zero(&mut self, is_bid: bool) -> u64
clears empty head of the order book, returns 0 if no head exists (matches Solidity behavior)
Sourcepub fn pop_front(&mut self, is_bid: bool) -> Result<Order, OrderBookError>
pub fn pop_front(&mut self, is_bid: bool) -> Result<Order, OrderBookError>
pop front on the orderbook
Sourcepub fn place_bid(
&mut self,
cid: impl Into<Vec<u8>>,
pair_id: impl Into<Vec<u8>>,
base_asset_id: impl Into<Vec<u8>>,
quote_asset_id: impl Into<Vec<u8>>,
owner: impl Into<Vec<u8>>,
price: u64,
amnt: u64,
iqty: u64,
timestamp: i64,
expires_at: i64,
maker_fee_bps: i16,
) -> Result<Order, OrderBookError>
pub fn place_bid( &mut self, cid: impl Into<Vec<u8>>, pair_id: impl Into<Vec<u8>>, base_asset_id: impl Into<Vec<u8>>, quote_asset_id: impl Into<Vec<u8>>, owner: impl Into<Vec<u8>>, price: u64, amnt: u64, iqty: u64, timestamp: i64, expires_at: i64, maker_fee_bps: i16, ) -> Result<Order, OrderBookError>
Places a bid order.
- returns the order id and if a dormant order was found.
cidis the client order id.owneris the owner of the order.priceis the price of the order.amountis the amount of the order.public_amountis the public amount of the order.timestampis the timestamp of the order.
Sourcepub fn place_ask(
&mut self,
cid: impl Into<Vec<u8>>,
pair_id: impl Into<Vec<u8>>,
base_asset_id: impl Into<Vec<u8>>,
quote_asset_id: impl Into<Vec<u8>>,
owner: impl Into<Vec<u8>>,
price: u64,
amnt: u64,
iqty: u64,
timestamp: i64,
expires_at: i64,
maker_fee_bps: i16,
) -> Result<Order, OrderBookError>
pub fn place_ask( &mut self, cid: impl Into<Vec<u8>>, pair_id: impl Into<Vec<u8>>, base_asset_id: impl Into<Vec<u8>>, quote_asset_id: impl Into<Vec<u8>>, owner: impl Into<Vec<u8>>, price: u64, amnt: u64, iqty: u64, timestamp: i64, expires_at: i64, maker_fee_bps: i16, ) -> Result<Order, OrderBookError>
Places an ask order.
- returns the order id and if a dormant order was found.
cidis the client order id.owneris the owner of the order.priceis the price of the order.amountis the amount of the order.public_amountis the public amount of the order.timestampis the timestamp of the order.
Sourcepub fn execute(
&mut self,
taker_order: Order,
maker_order: Order,
pair_id: impl Into<Vec<u8>>,
base_asset_id: impl Into<Vec<u8>>,
quote_asset_id: impl Into<Vec<u8>>,
now: i64,
) -> Result<(), OrderBookError>
pub fn execute( &mut self, taker_order: Order, maker_order: Order, pair_id: impl Into<Vec<u8>>, base_asset_id: impl Into<Vec<u8>>, quote_asset_id: impl Into<Vec<u8>>, now: i64, ) -> Result<(), OrderBookError>
Executes a trade.
- returns the trade details.
is_bidis whether the order from client is a bid order.taker_orderis the taker order.maker_orderis the maker order.pair_idis the pair id.base_asset_idis the base asset id.quote_asset_idis the quote asset id.managing_account_idis the managing account id.matching_amountis the amount of the taker order to match with the maker order.clearis whether to clear the order.
Sourcepub fn update_price_level(
&mut self,
pair_id: Vec<u8>,
is_placed: bool,
is_bid: bool,
price: u64,
delta_pqty: u64,
delta_cqty: u64,
delete_price: Option<u64>,
) -> Result<(), OrderBookError>
pub fn update_price_level( &mut self, pair_id: Vec<u8>, is_placed: bool, is_bid: bool, price: u64, delta_pqty: u64, delta_cqty: u64, delete_price: Option<u64>, ) -> Result<(), OrderBookError>
updates the levels on the orderbook in the price level linked list
cidis the client id.pair_idis the pair id.is_placedis whether the order is placed.is_bidis whether the order is a bid order.priceis the price of the order.delta_pqtyis the delta quantity of the public quantity.delta_cqtyis the delta quantity of the current quantity.delete_priceis an optional price that should be removed (when an order was fully consumed). Removes the price if the level becomes 0 or below.
Sourcepub fn cancel_order(
&mut self,
cid: impl Into<Vec<u8>>,
pair_id: impl Into<Vec<u8>>,
is_bid: bool,
order_id: OrderId,
owner: impl Into<Vec<u8>>,
) -> Result<(), OrderBookError>
pub fn cancel_order( &mut self, cid: impl Into<Vec<u8>>, pair_id: impl Into<Vec<u8>>, is_bid: bool, order_id: OrderId, owner: impl Into<Vec<u8>>, ) -> Result<(), OrderBookError>
Cancels an order.
- returns the amount to send and the delete price.
order_idis the id of the order to cancel.owneris the owner of the order.
pub fn expire_orders( &mut self, is_bid: bool, pair_id: impl Into<Vec<u8>>, base_asset_id: impl Into<Vec<u8>>, quote_asset_id: impl Into<Vec<u8>>, managing_account_id: impl Into<Vec<u8>>, now: i64, ) -> Result<(), OrderBookError>
pub fn set_iceberg_quantity( &mut self, cid: impl Into<Vec<u8>>, pair_id: impl Into<Vec<u8>>, is_bid: bool, order_id: OrderId, iqty: u64, ) -> Result<(), OrderBookError>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for OrderBook
impl<'de> Deserialize<'de> for OrderBook
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for OrderBook
impl StructuralPartialEq for OrderBook
Auto Trait Implementations§
impl Forget for OrderBook
impl Freeze for OrderBook
impl RefUnwindSafe for OrderBook
impl Send for OrderBook
impl Sync for OrderBook
impl Unpin for OrderBook
impl UnsafeUnpin for OrderBook
impl UnwindSafe for OrderBook
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