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