pub trait TokenSwaps<Account> {
    type CurrencyId;
    type BalanceOut;
    type BalanceIn;
    type Ratio;
    type OrderId;

    // Required methods
    fn place_order(
        account: Account,
        currency_in: Self::CurrencyId,
        currency_out: Self::CurrencyId,
        amount_out: Self::BalanceOut,
        ratio: OrderRatio<Self::Ratio>
    ) -> Result<Self::OrderId, DispatchError>;
    fn update_order(
        order_id: Self::OrderId,
        amount_out: Self::BalanceOut,
        ratio: OrderRatio<Self::Ratio>
    ) -> DispatchResult;
    fn fill_order(
        account: Account,
        order_id: Self::OrderId,
        amount: Self::BalanceOut
    ) -> DispatchResult;
    fn cancel_order(order: Self::OrderId) -> DispatchResult;
    fn get_order_details(
        order: Self::OrderId
    ) -> Option<OrderInfo<Self::BalanceOut, Self::CurrencyId, Self::Ratio>>;
    fn convert_by_market(
        currency_in: Self::CurrencyId,
        currency_out: Self::CurrencyId,
        amount_out: Self::BalanceOut
    ) -> Result<Self::BalanceIn, DispatchError>;
    fn market_ratio(
        currency_in: Self::CurrencyId,
        currency_out: Self::CurrencyId
    ) -> Result<Self::Ratio, DispatchError>;
}

Required Associated Types§

Required Methods§

source

fn place_order( account: Account, currency_in: Self::CurrencyId, currency_out: Self::CurrencyId, amount_out: Self::BalanceOut, ratio: OrderRatio<Self::Ratio> ) -> Result<Self::OrderId, DispatchError>

Swap tokens selling amount_out of currency_out and buying currency_in given an order ratio.

source

fn update_order( order_id: Self::OrderId, amount_out: Self::BalanceOut, ratio: OrderRatio<Self::Ratio> ) -> DispatchResult

Update an existing active order.

source

fn fill_order( account: Account, order_id: Self::OrderId, amount: Self::BalanceOut ) -> DispatchResult

Fill an existing order up to the provided amount.

  • If amount equals the order.amount_out, the order is completely fulfilled.
  • Else, the order is partially fulfilled for amount / order.amount_out%.
source

fn cancel_order(order: Self::OrderId) -> DispatchResult

Cancel an already active order.

source

fn get_order_details( order: Self::OrderId ) -> Option<OrderInfo<Self::BalanceOut, Self::CurrencyId, Self::Ratio>>

Retrieve the details of the order if it exists.

source

fn convert_by_market( currency_in: Self::CurrencyId, currency_out: Self::CurrencyId, amount_out: Self::BalanceOut ) -> Result<Self::BalanceIn, DispatchError>

Makes a conversion between 2 currencies using the market ratio between them.

source

fn market_ratio( currency_in: Self::CurrencyId, currency_out: Self::CurrencyId ) -> Result<Self::Ratio, DispatchError>

Returns the conversion ratio to convert currency out into currency in,

Object Safety§

This trait is not object safe.

Implementors§