binance_async/models/
order.rs

1use crate::parser::{string_or_decimal, string_or_decimal_opt};
2use rust_decimal::Decimal;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Serialize, Deserialize, Clone)]
6#[serde(rename_all = "camelCase")]
7pub struct Order {
8    pub symbol: String,
9    pub order_id: u64,
10    pub client_order_id: String,
11    #[serde(with = "rust_decimal::serde::str")]
12    pub price: Decimal,
13    pub orig_qty: String,
14    pub executed_qty: String,
15    pub status: String,
16    pub time_in_force: String,
17    #[serde(rename = "type")]
18    pub r#type: String,
19    pub side: String,
20    #[serde(with = "rust_decimal::serde::str")]
21    pub stop_price: Decimal,
22    pub iceberg_qty: String,
23    pub time: u64,
24}
25
26#[derive(Debug, Serialize, Deserialize, Clone)]
27#[serde(rename_all = "camelCase")]
28pub struct OrderCanceled {
29    pub symbol: String,
30    pub orig_client_order_id: String,
31    pub order_id: u64,
32    pub client_order_id: String,
33}
34
35#[derive(Debug, Serialize, Deserialize, Clone)]
36#[serde(rename_all = "camelCase")]
37pub struct OrderInfo {
38    pub symbol: String,
39    pub order_id: u64,
40    pub order_list_id: Option<i64>,
41    pub client_order_id: String,
42    pub transact_time: u64,
43    #[serde(with = "rust_decimal::serde::str")]
44    pub price: Decimal,
45    #[serde(with = "rust_decimal::serde::str")]
46    pub orig_qty: Decimal,
47    #[serde(with = "rust_decimal::serde::str")]
48    pub executed_qty: Decimal,
49    #[serde(with = "rust_decimal::serde::str")]
50    pub cummulative_quote_qty: Decimal,
51    #[serde(with = "rust_decimal::serde::str", default = "default_stop_price")]
52    pub stop_price: Decimal,
53    pub status: String,
54    pub time_in_force: String,
55    #[serde(rename = "type")]
56    pub type_name: String,
57    pub side: String,
58    pub fills: Option<Vec<FillInfo>>,
59}
60
61fn default_stop_price() -> Decimal {
62    Decimal::ZERO
63}
64
65#[derive(Debug, Serialize, Deserialize, Clone)]
66#[serde(rename_all = "camelCase")]
67pub struct FillInfo {
68    #[serde(with = "rust_decimal::serde::str")]
69    pub price: Decimal,
70    #[serde(with = "rust_decimal::serde::str")]
71    pub qty: Decimal,
72    #[serde(with = "rust_decimal::serde::str")]
73    pub commission: Decimal,
74    pub commission_asset: String,
75    pub trade_id: Option<u64>,
76}
77
78#[derive(Serialize, Deserialize, Clone, Debug)]
79#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
80pub enum OrderType {
81    Market,
82    Limit,
83    StopLoss,
84    StopLossLimit,
85    TakeProfit,
86    TakeProfitLimit,
87    LimitMaker,
88}
89
90impl Default for OrderType {
91    fn default() -> Self {
92        OrderType::Market
93    }
94}
95
96#[derive(Serialize, Deserialize, Clone, Debug)]
97#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
98pub enum OrderSide {
99    Buy,
100    Sell,
101}
102
103impl Default for OrderSide {
104    fn default() -> Self {
105        OrderSide::Buy
106    }
107}
108
109#[derive(Debug, Serialize, Deserialize, Clone)]
110#[serde(rename_all = "camelCase")]
111pub struct CanceledOrder {
112    pub client_order_id: String,
113    #[serde(with = "string_or_decimal")]
114    pub cum_qty: Decimal,
115    #[serde(with = "string_or_decimal")]
116    pub cum_quote: Decimal,
117    #[serde(with = "string_or_decimal")]
118    pub executed_qty: Decimal,
119    pub order_id: u64,
120    #[serde(with = "string_or_decimal")]
121    pub orig_qty: Decimal,
122    pub orig_type: String,
123    #[serde(with = "string_or_decimal")]
124    pub price: Decimal,
125    pub reduce_only: bool,
126    pub side: String,
127    pub position_side: String,
128    pub status: String,
129    #[serde(with = "string_or_decimal")]
130    pub stop_price: Decimal,
131    pub close_position: bool,
132    pub symbol: String,
133    pub time_in_force: String,
134    #[serde(rename = "type")]
135    pub type_name: String,
136    #[serde(default)]
137    #[serde(with = "string_or_decimal_opt")]
138    pub activate_price: Option<Decimal>,
139    #[serde(default)]
140    #[serde(with = "string_or_decimal_opt")]
141    pub price_rate: Option<Decimal>,
142    pub update_time: u64,
143    pub working_type: String,
144    price_protect: bool,
145}
146
147#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
148#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
149pub enum PositionSide {
150    Both,
151    Long,
152    Short,
153}
154
155#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
156#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
157pub enum WorkingType {
158    MarkPrice,
159    ContractPrice,
160}