dex_connector/
lib.rs

1use std::fmt;
2
3use rust_decimal::Decimal;
4use serde::{Deserialize, Serialize};
5
6mod dex_connector;
7mod dex_request;
8mod dex_websocket;
9mod hyperliquid_connector;
10#[cfg(feature = "lighter-sdk")]
11pub mod lighter_connector;
12
13pub use dex_connector::DexConnector;
14pub use dex_request::DexError;
15pub use hyperliquid_connector::*;
16#[cfg(feature = "lighter-sdk")]
17pub use lighter_connector::*;
18
19#[derive(Debug, Clone, Copy, PartialEq, Default, Deserialize)]
20pub enum OrderSide {
21    #[default]
22    Long,
23    Short,
24}
25
26impl fmt::Display for OrderSide {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        match self {
29            OrderSide::Long => write!(f, "long"),
30            OrderSide::Short => write!(f, "short"),
31        }
32    }
33}
34
35#[derive(Deserialize, Debug, Default)]
36pub struct CommonErrorResponse {
37    pub message: Option<String>,
38}
39
40#[derive(Deserialize, Debug, Default)]
41pub struct TickerResponse {
42    pub symbol: String,
43    pub price: Decimal,
44    pub min_tick: Option<Decimal>,
45    pub min_order: Option<Decimal>,
46    pub volume: Option<Decimal>,
47    pub num_trades: Option<u64>,
48    pub open_interest: Option<Decimal>,
49    pub funding_rate: Option<Decimal>,
50    pub oracle_price: Option<Decimal>,
51}
52
53#[derive(Deserialize, Clone, Debug, Default)]
54pub struct FilledOrder {
55    pub order_id: String,
56    pub is_rejected: bool,
57    pub trade_id: String,
58    pub filled_side: Option<OrderSide>,
59    pub filled_size: Option<Decimal>,
60    pub filled_value: Option<Decimal>,
61    pub filled_fee: Option<Decimal>,
62}
63
64#[derive(Deserialize, Debug, Default)]
65pub struct FilledOrdersResponse {
66    pub orders: Vec<FilledOrder>,
67}
68
69#[derive(Debug, Deserialize, Clone)]
70pub struct CanceledOrder {
71    pub order_id: String,
72    pub canceled_timestamp: u64,
73}
74
75#[derive(Debug, Default, Deserialize)]
76pub struct CanceledOrdersResponse {
77    pub orders: Vec<CanceledOrder>,
78}
79
80#[derive(Debug, Clone, Deserialize)]
81pub struct OpenOrder {
82    pub order_id: String,
83    pub symbol: String,
84    pub side: OrderSide,
85    pub size: Decimal,
86    pub price: Decimal,
87    pub status: String,
88}
89
90#[derive(Debug, Default, Deserialize)]
91pub struct OpenOrdersResponse {
92    pub orders: Vec<OpenOrder>,
93}
94
95#[derive(Deserialize, Debug, Default)]
96pub struct BalanceResponse {
97    pub equity: Decimal,
98    pub balance: Decimal,
99    pub position_entry_price: Option<Decimal>,
100    pub position_sign: Option<i32>,
101}
102
103#[derive(Debug, Default)]
104pub struct CombinedBalanceResponse {
105    pub usd_balance: Decimal,
106    pub token_balances: std::collections::HashMap<String, BalanceResponse>,
107}
108
109#[derive(Deserialize, Debug, Default)]
110pub struct CreateOrderResponse {
111    pub order_id: String,
112    pub ordered_price: Decimal,
113    pub ordered_size: Decimal,
114}
115
116#[derive(Deserialize, Debug, Default, Clone)]
117pub struct LastTrade {
118    pub price: Decimal,
119}
120
121#[derive(Deserialize, Debug, Default)]
122pub struct LastTradesResponse {
123    pub trades: Vec<LastTrade>,
124}
125
126#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
127#[serde(rename_all = "camelCase")]
128pub struct Trigger {
129    /// If true, executes as a market order once triggered; otherwise limit.
130    pub is_market: bool,
131    /// The price at which the trigger fires.
132    pub trigger_px: String,
133    /// “tp” for take‐profit or “sl” for stop‐loss.
134    pub tpsl: String,
135}
136
137#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
138#[serde(rename_all = "lowercase")]
139pub enum TpSl {
140    /// Take‐Profit
141    Tp,
142    /// Stop‐Loss
143    Sl,
144}