binance/spot/
enums.rs

1//! ENUM Definitions
2//!
3//! This will apply for both REST API and WebSocket API.
4
5use rust_decimal::Decimal;
6use serde::{Deserialize, Serialize};
7
8/// Symbol status.
9#[derive(Debug, Deserialize, Serialize, PartialEq)]
10#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
11pub enum SymbolStatus {
12    Trading,
13    EndOfDay,
14    Halt,
15    Break,
16}
17
18/// Order status.
19#[derive(Debug, Deserialize, Serialize, PartialEq)]
20#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
21pub enum OrderStatus {
22    /// The order has been accepted by the engine.
23    New,
24    /// The order is in a pending phase until the working order of an order list has been fully filled.
25    PendingNew,
26    /// A part of the order has been filled.
27    PartiallyFilled,
28    /// The order has been completed.
29    Filled,
30    /// The order has been canceled by the user.
31    Canceled,
32    /// Currently unused
33    PendingCancel,
34    /// The order was not accepted by the engine and not processed.
35    Rejected,
36    /// The order was canceled according to the order type's rules (e.g. LIMIT FOK orders with no fill, LIMIT IOC or MARKET orders that partially fill)
37    /// or by the exchange, (e.g. orders canceled during liquidation, orders canceled during maintenance)
38    Expired,
39    /// The order was expired by the exchange due to STP. (e.g. an order with EXPIRE_TAKER will match with existing orders on the book with the same account or same tradeGroupId)
40    ExpiredInMatch,
41}
42
43/// Order List Status.
44#[derive(Debug, Deserialize, Serialize, PartialEq)]
45#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
46pub enum OrderListStatus {
47    /// This is used when the ListStatus is responding to a failed action. (E.g. order list placement or cancellation)
48    Response,
49    /// The order list has been placed or there is an update to the order list status.
50    ExecStarted,
51    /// The clientOrderId of an order in the order list has been changed.
52    Updated,
53    /// The order list has finished executing and thus is no longer active.
54    AllDone,
55}
56
57/// Order List Order Status.
58#[derive(Debug, Deserialize, Serialize, PartialEq)]
59#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
60pub enum OrderListOrderStatus {
61    /// Either an order list has been placed or there is an update to the status of the list.
62    Executing,
63    /// An order list has completed execution and thus no longer active.
64    AllDone,
65    /// The List Status is responding to a failed action either during order placement or order canceled.
66    Reject,
67}
68
69/// ContingencyType
70#[derive(Debug, Deserialize, Serialize, PartialEq)]
71pub enum ContingencyType {
72    OCO,
73    OTO,
74}
75
76/// Allocation type.
77#[derive(Debug, Deserialize, Serialize, PartialEq)]
78pub enum AllocationType {
79    SOR,
80}
81
82/// Order types.
83#[derive(Debug, Deserialize, Serialize, PartialEq)]
84#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
85pub enum OrderType {
86    Limit,
87    Market,
88    StopLoss,
89    StopLossLimit,
90    TakeProfit,
91    TakeProfitLimit,
92    LimitMaker,
93}
94
95/// Order Response Type.
96#[derive(Debug, Deserialize, Serialize, PartialEq)]
97pub enum OrderResponseType {
98    ACK,
99    RESULT,
100    FULL,
101}
102
103/// Working Floor.
104#[derive(Debug, Deserialize, Serialize, PartialEq)]
105pub enum WorkingFloor {
106    EXCHANGE,
107    SOR,
108}
109
110/// Order side.
111#[derive(Debug, Deserialize, Serialize, PartialEq)]
112pub enum OrderSide {
113    BUY,
114    SELL,
115}
116
117/// Time in force.
118/// This sets how long an order will be active before expiration.
119#[derive(Debug, Deserialize, Serialize, PartialEq)]
120pub enum TimeInForce {
121    /// Good Til Canceled
122    /// An order will be on the book unless the order is canceled.
123    GTC,
124    /// Immediate Or Cancel
125    /// An order will try to fill the order as much as it can before the order expires.
126    IOC,
127    /// Fill or Kill
128    /// An order will expire if the full order cannot be filled upon execution.
129    FOK,
130}
131
132/// Rate limiter.
133#[derive(Debug, Deserialize, Serialize, PartialEq)]
134#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
135pub enum RateLimiter {
136    RequestWeight,
137    Orders,
138    RawRequests,
139}
140
141/// Rate limit interval.
142#[derive(Debug, Deserialize, Serialize, PartialEq)]
143#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
144pub enum RateLimitInterval {
145    Second,
146    Minute,
147    Day,
148}
149
150#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
151pub enum KlineInterval {
152    #[serde(rename = "1s")]
153    Second1,
154    #[serde(rename = "1m")]
155    Minute1,
156    #[serde(rename = "3m")]
157    Minute3,
158    #[serde(rename = "5m")]
159    Minute5,
160    #[serde(rename = "15m")]
161    Minute15,
162    #[serde(rename = "30m")]
163    Minute30,
164    #[serde(rename = "1h")]
165    Hour1,
166    #[serde(rename = "2h")]
167    Hour2,
168    #[serde(rename = "4h")]
169    Hour4,
170    #[serde(rename = "6h")]
171    Hour6,
172    #[serde(rename = "8h")]
173    Hour8,
174    #[serde(rename = "12h")]
175    Hour12,
176    #[serde(rename = "1d")]
177    Day1,
178    #[serde(rename = "3d")]
179    Day3,
180    #[serde(rename = "1w")]
181    Week1,
182    #[serde(rename = "1M")]
183    Month1,
184}
185
186impl std::fmt::Display for KlineInterval {
187    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
188        let value = match self {
189            Self::Second1 => "1s",
190            Self::Minute1 => "1m",
191            Self::Minute3 => "3m",
192            Self::Minute5 => "5m",
193            Self::Minute15 => "15m",
194            Self::Minute30 => "30m",
195            Self::Hour1 => "1h",
196            Self::Hour2 => "2h",
197            Self::Hour4 => "4h",
198            Self::Hour6 => "6h",
199            Self::Hour8 => "8h",
200            Self::Hour12 => "12h",
201            Self::Day1 => "1d",
202            Self::Day3 => "3d",
203            Self::Week1 => "1w",
204            Self::Month1 => "1M",
205        };
206        write!(f, "{value}")
207    }
208}
209
210/// Self trade prevention (STP) Mode.
211#[derive(Debug, Deserialize, Serialize, PartialEq)]
212#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
213pub enum STPMode {
214    None,
215    ExpireMaker,
216    ExpireTaker,
217    ExpireBoth,
218    Decrement,
219}
220
221#[derive(Debug, Deserialize, Serialize, PartialEq)]
222#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
223pub enum SecurityType {
224    /// Endpoint can be accessed freely.
225    None,
226    /// Endpoint requires sending a valid API-Key and signature.
227    Trade,
228    /// Endpoint requires sending a valid API-Key and signature.
229    UserData,
230    /// Endpoint requires sending a valid API-Key.
231    UserStream,
232}
233
234#[derive(Debug, Deserialize, PartialEq)]
235#[serde(tag = "filterType", rename_all = "SCREAMING_SNAKE_CASE")]
236pub enum ExchangeFilter {
237    PriceFilter { tick_size: Decimal },
238    LotSize { step_size: Decimal },
239    // TODO:
240}
241
242#[derive(Debug, Deserialize, Serialize, PartialEq)]
243#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
244pub enum AccountType {
245    Spot,
246}