Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Module: trait

Source: trait.rs

Exchange trait definitions and shared types. Defines [Exchange], [ExchangeError], [StreamMsg], [OrderStatus], and the [Stream] subscription handle used by all exchange backends.

Structs

pub struct Stream

#![allow(unused)]
fn main() {
pub struct Stream {
    pub rx: crossbeam_channel :: Receiver < StreamMsg >,
};
}

pub struct OrderRequest

#![allow(unused)]
fn main() {
pub struct OrderRequest {
    pub client_order_id: String,
    pub order: Order,
};
}

An order paired with the caller-generated idempotency key. The key is created by the engine before submission and must remain stable across transport failures. Adapters that support native client IDs must send it verbatim and expose lookup by it for reconciliation.

pub struct OrderStatus

#![allow(unused)]
fn main() {
pub struct OrderStatus {
    pub order_id: String,
    pub symbol: String,
    pub side: Side,
    pub qty: f64,
    pub filled_qty: f64,
    pub price: f64,
    pub avg_price: f64,
    pub status: String,
};
}

Enums

pub enum ExchangeError

#![allow(unused)]
fn main() {
pub enum ExchangeError {
    Ws(String,),
    Rest(String,),
    Auth(String,),
    Order(String,),
    Timeout,
    Disconnected,
}
}

pub enum StreamMsg

#![allow(unused)]
fn main() {
pub enum StreamMsg {
    Trade(Trade,),
    Depth(Depth,),
    MarkPrice(price: f64,
    time: chrono :: DateTime < chrono :: Utc >,),
    OpenInterest(qty: f64,
    time: chrono :: DateTime < chrono :: Utc >,),
    ForceOrder(Trade,),
    AccountUpdate(AccountInfo,),
    OrderUpdate(OrderFill,),
    ReconcileRequired(source: & 'static str,
    reason: String,),
}
}

Traits

pub trait Exchange

#![allow(unused)]
fn main() {
pub trait Exchange: Send: Sync {
    async fn subscribe (& self , symbols : & [String]) -> Result < Stream >;
    async fn place_order (& self , request : OrderRequest) -> Result < String >;
    async fn cancel_order (& self , symbol : & str , order_id : & str) -> Result < () >;
    async fn order_status (& self , symbol : & str , order_id : & str) -> Result < OrderStatus >;
    async fn order_status_by_client_id (& self , _symbol : & str , _client_order_id : & str ,) -> Result < OrderStatus > { ... }
    async fn account_info (& self) -> Result < AccountInfo >;
    async fn current_price (& self , symbol : & str) -> Result < f64 >;
}
}

Type Aliases

pub type Result

#![allow(unused)]
fn main() {
pub type Result = std :: result :: Result < T , ExchangeError >;
}