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>
    ) -> Result<(), DispatchError>;
    fn fill_order(
        account: Account,
        order_id: Self::OrderId,
        amount: Self::BalanceOut
    ) -> Result<(), DispatchError>;
    fn cancel_order(order: Self::OrderId) -> Result<(), DispatchError>;
    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§

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.

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

Update an existing active order.

fn fill_order( account: Account, order_id: Self::OrderId, amount: Self::BalanceOut ) -> Result<(), DispatchError>

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

fn cancel_order(order: Self::OrderId) -> Result<(), DispatchError>

Cancel an already active order.

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

Retrieve the details of the order if it exists.

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.

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§