Trait order_book::traits::DataLayer
source · pub trait DataLayer<T>where
T: Config,{
// Required methods
fn get_limit_order(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>,
order_id: T::OrderId
) -> Result<LimitOrder<T>, DispatchError>;
fn get_all_limit_orders(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>
) -> Vec<LimitOrder<T>> ⓘ;
fn insert_limit_order(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>,
order: LimitOrder<T>
) -> Result<(), DispatchError>;
fn update_limit_order_amount(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>,
order_id: T::OrderId,
new_amount: OrderVolume
) -> Result<(), DispatchError>;
fn delete_limit_order(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>,
order_id: T::OrderId
) -> Result<(), DispatchError>;
fn get_bids(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>,
price: &OrderPrice
) -> Option<PriceOrders<T::OrderId, T::MaxLimitOrdersForPrice>>;
fn get_asks(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>,
price: &OrderPrice
) -> Option<PriceOrders<T::OrderId, T::MaxLimitOrdersForPrice>>;
fn get_aggregated_bids(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>
) -> MarketSide<T::MaxSidePriceCount>;
fn get_aggregated_asks(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>
) -> MarketSide<T::MaxSidePriceCount>;
fn get_user_limit_orders(
&mut self,
account: &T::AccountId,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>
) -> Option<UserOrders<T::OrderId, T::MaxOpenedLimitOrdersPerUser>>;
fn get_all_user_limit_orders(
&mut self,
account: &T::AccountId
) -> BTreeMap<OrderBookId<AssetIdOf<T>, T::DEXId>, UserOrders<T::OrderId, T::MaxOpenedLimitOrdersPerUser>>;
// Provided method
fn get_limit_orders_by_price(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>,
side: PriceVariant,
price: &OrderPrice
) -> Option<PriceOrders<T::OrderId, T::MaxLimitOrdersForPrice>> { ... }
}
Expand description
This trait is used by Order Book as a storage to get limit orders and their derived data and to change them
Required Methods§
sourcefn get_limit_order(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>,
order_id: T::OrderId
) -> Result<LimitOrder<T>, DispatchError>
fn get_limit_order( &mut self, order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>, order_id: T::OrderId ) -> Result<LimitOrder<T>, DispatchError>
Returns the limit order if exists, otherwise returns error.
sourcefn get_all_limit_orders(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>
) -> Vec<LimitOrder<T>> ⓘ
fn get_all_limit_orders( &mut self, order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId> ) -> Vec<LimitOrder<T>> ⓘ
Returns all limit orders of order book
sourcefn insert_limit_order(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>,
order: LimitOrder<T>
) -> Result<(), DispatchError>
fn insert_limit_order( &mut self, order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>, order: LimitOrder<T> ) -> Result<(), DispatchError>
Inserts limit order consistently in all necessary storages.
Must check before call. If returns error, it means we have problems with data consistency.
If order_id already exists - returns error. Use update_limit_order
to update the existing order.
sourcefn update_limit_order_amount(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>,
order_id: T::OrderId,
new_amount: OrderVolume
) -> Result<(), DispatchError>
fn update_limit_order_amount( &mut self, order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>, order_id: T::OrderId, new_amount: OrderVolume ) -> Result<(), DispatchError>
Updates the amount of the limit order. If order doesn’t exist - return error
sourcefn delete_limit_order(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>,
order_id: T::OrderId
) -> Result<(), DispatchError>
fn delete_limit_order( &mut self, order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>, order_id: T::OrderId ) -> Result<(), DispatchError>
Deletes limit order consistently from all necessary storages. If order doesn’t exist - return error Must check before call. If returns error, it means we have problems with data consistency.
sourcefn get_bids(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>,
price: &OrderPrice
) -> Option<PriceOrders<T::OrderId, T::MaxLimitOrdersForPrice>>
fn get_bids( &mut self, order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>, price: &OrderPrice ) -> Option<PriceOrders<T::OrderId, T::MaxLimitOrdersForPrice>>
Returns order ids of orders inside the bid price
sourcefn get_asks(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>,
price: &OrderPrice
) -> Option<PriceOrders<T::OrderId, T::MaxLimitOrdersForPrice>>
fn get_asks( &mut self, order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>, price: &OrderPrice ) -> Option<PriceOrders<T::OrderId, T::MaxLimitOrdersForPrice>>
Returns order ids of orders inside the ask price
sourcefn get_aggregated_bids(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>
) -> MarketSide<T::MaxSidePriceCount>
fn get_aggregated_bids( &mut self, order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId> ) -> MarketSide<T::MaxSidePriceCount>
Returns all bid prices with their volumes
sourcefn get_aggregated_asks(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>
) -> MarketSide<T::MaxSidePriceCount>
fn get_aggregated_asks( &mut self, order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId> ) -> MarketSide<T::MaxSidePriceCount>
Returns all ask prices with their volumes
sourcefn get_user_limit_orders(
&mut self,
account: &T::AccountId,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>
) -> Option<UserOrders<T::OrderId, T::MaxOpenedLimitOrdersPerUser>>
fn get_user_limit_orders( &mut self, account: &T::AccountId, order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId> ) -> Option<UserOrders<T::OrderId, T::MaxOpenedLimitOrdersPerUser>>
Returns order ids of user from the order book with order_book_id
sourcefn get_all_user_limit_orders(
&mut self,
account: &T::AccountId
) -> BTreeMap<OrderBookId<AssetIdOf<T>, T::DEXId>, UserOrders<T::OrderId, T::MaxOpenedLimitOrdersPerUser>>
fn get_all_user_limit_orders( &mut self, account: &T::AccountId ) -> BTreeMap<OrderBookId<AssetIdOf<T>, T::DEXId>, UserOrders<T::OrderId, T::MaxOpenedLimitOrdersPerUser>>
Returns order ids of user from all order books
Provided Methods§
sourcefn get_limit_orders_by_price(
&mut self,
order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>,
side: PriceVariant,
price: &OrderPrice
) -> Option<PriceOrders<T::OrderId, T::MaxLimitOrdersForPrice>>
fn get_limit_orders_by_price( &mut self, order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId>, side: PriceVariant, price: &OrderPrice ) -> Option<PriceOrders<T::OrderId, T::MaxLimitOrdersForPrice>>
Returns order ids of orders inside the bid or ask price