drm_core/exchange/
traits.rs1use async_trait::async_trait;
2use std::collections::HashMap;
3
4use crate::error::DrmError;
5use crate::models::{Market, Order, OrderSide, Position};
6
7use super::config::{FetchMarketsParams, FetchOrdersParams};
8
9#[async_trait]
10pub trait Exchange: Send + Sync {
11 fn id(&self) -> &'static str;
12 fn name(&self) -> &'static str;
13
14 async fn fetch_markets(
15 &self,
16 params: Option<FetchMarketsParams>,
17 ) -> Result<Vec<Market>, DrmError>;
18
19 async fn fetch_market(&self, market_id: &str) -> Result<Market, DrmError>;
20
21 async fn fetch_markets_by_slug(&self, slug: &str) -> Result<Vec<Market>, DrmError> {
22 let _ = slug;
23 Err(DrmError::Exchange(
24 crate::error::ExchangeError::NotSupported("fetch_markets_by_slug".into()),
25 ))
26 }
27
28 async fn create_order(
29 &self,
30 market_id: &str,
31 outcome: &str,
32 side: OrderSide,
33 price: f64,
34 size: f64,
35 params: HashMap<String, String>,
36 ) -> Result<Order, DrmError>;
37
38 async fn cancel_order(
39 &self,
40 order_id: &str,
41 market_id: Option<&str>,
42 ) -> Result<Order, DrmError>;
43
44 async fn fetch_order(&self, order_id: &str, market_id: Option<&str>)
45 -> Result<Order, DrmError>;
46
47 async fn fetch_open_orders(
48 &self,
49 params: Option<FetchOrdersParams>,
50 ) -> Result<Vec<Order>, DrmError>;
51
52 async fn fetch_positions(&self, market_id: Option<&str>) -> Result<Vec<Position>, DrmError>;
53
54 async fn fetch_balance(&self) -> Result<HashMap<String, f64>, DrmError>;
55
56 fn describe(&self) -> ExchangeInfo {
57 ExchangeInfo {
58 id: self.id(),
59 name: self.name(),
60 has_fetch_markets: true,
61 has_create_order: true,
62 has_websocket: false,
63 }
64 }
65}
66
67#[derive(Debug, Clone)]
68pub struct ExchangeInfo {
69 pub id: &'static str,
70 pub name: &'static str,
71 pub has_fetch_markets: bool,
72 pub has_create_order: bool,
73 pub has_websocket: bool,
74}