Skip to main content

Marketplace

Struct Marketplace 

Source
pub struct Marketplace {
    pub fee_bps: u64,
    pub protocol_fee_address: String,
    /* private fields */
}
Expand description

The marketplace engine.

Fields§

§fee_bps: u64

Fee in basis points (e.g. 25 = 0.25%) charged to the filled side.

§protocol_fee_address: String

Protocol address that collects marketplace fees.

Implementations§

Source§

impl Marketplace

Source

pub fn new(fee_bps: u64, protocol_fee_address: String) -> Marketplace

Source

pub fn place_order( &mut self, maker: &str, side: OrderSide, sell_asset: MarketAsset, buy_asset: MarketAsset, amount: u64, price: u64, ) -> String

Place a limit order. Returns the order ID.

Source

pub fn cancel_order(&mut self, order_id: &str) -> bool

Cancel an open order. Returns true if found and cancelled.

Source

pub fn get_order(&self, order_id: &str) -> Option<&Order>

Get a single order.

Source

pub fn order_book( &self, sell_asset: &MarketAsset, buy_asset: &MarketAsset, ) -> OrderBook

Get the order book for a given asset pair.

Source

pub fn orders_for_maker(&self, maker: &str) -> Vec<&Order>

Get all orders for a maker.

Source

pub fn try_match( &mut self, maker: &str, side: OrderSide, sell_asset: &MarketAsset, buy_asset: &MarketAsset, amount: u64, price: u64, ) -> Vec<Trade>

Try to match a new sell order against existing buy orders (and vice versa). Returns the trades that were executed. This is a simple price-time priority matching engine.

Source

pub fn place_and_match( &mut self, maker: &str, side: OrderSide, sell_asset: MarketAsset, buy_asset: MarketAsset, amount: u64, price: u64, ) -> (String, Vec<Trade>)

Place an order and immediately attempt to match it. Returns the order ID and any trades that were executed.

Source

pub fn trades(&self) -> &[Trade]

Get all trades.

Source

pub fn open_orders(&self) -> Vec<&Order>

Get all open orders.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more