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§

source

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.

source

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

source

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.

source

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

source

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.

source

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

source

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

source

fn get_aggregated_bids( &mut self, order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId> ) -> MarketSide<T::MaxSidePriceCount>

Returns all bid prices with their volumes

source

fn get_aggregated_asks( &mut self, order_book_id: &OrderBookId<AssetIdOf<T>, T::DEXId> ) -> MarketSide<T::MaxSidePriceCount>

Returns all ask prices with their volumes

source

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

source

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§

source

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

Implementors§