Skip to main content

mkt_core/
stream.rs

1use async_trait::async_trait;
2use mkt_types::{
3    Balance, ExchangeId, Fill, Kline, KlineRequest, LastPrice, Order, OrderBook, Position, Symbol,
4    Trade,
5};
6
7use crate::Result;
8
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub enum Subscription {
11    LastPrice(Symbol),
12    OrderBook { symbol: Symbol, depth: Option<u32> },
13    Trades(Symbol),
14    Klines(KlineRequest),
15}
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub enum PrivateSubscription {
19    Orders,
20    Fills,
21    Balances,
22    Positions,
23}
24
25#[derive(Debug, Clone, PartialEq)]
26pub enum MarketDataEvent {
27    LastPrice(LastPrice),
28    OrderBook(OrderBook),
29    Trade(Trade),
30    Kline(Kline),
31    Raw {
32        exchange_id: ExchangeId,
33        payload: RawPayload,
34    },
35}
36
37#[derive(Debug, Clone, PartialEq)]
38pub enum PrivateEvent {
39    Order(Order),
40    Fill(Fill),
41    Balance(Balance),
42    Position(Position),
43    Raw {
44        exchange_id: ExchangeId,
45        payload: RawPayload,
46    },
47}
48
49#[derive(Debug, Clone, PartialEq, Eq)]
50pub enum RawPayload {
51    Text(String),
52    Binary(Vec<u8>),
53}
54
55#[async_trait]
56pub trait EventStream: Send {
57    async fn next(&mut self) -> Result<Option<MarketDataEvent>>;
58}
59
60#[async_trait]
61pub trait PrivateEventStream: Send {
62    async fn next(&mut self) -> Result<Option<PrivateEvent>>;
63}