1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
use super::{Rest, RestEndpoint, RestError};
use serde::Serialize;
pub mod usd_margin_futures;
pub mod spot;
#[derive(Debug, Clone)]
pub struct PlaceOrder {
pub(crate) inner: exc_core::types::PlaceOrder,
}
impl PlaceOrder {
fn dispatch(&self, endpoint: &RestEndpoint) -> Result<PlaceOrderKind, RestError> {
match endpoint {
RestEndpoint::UsdMarginFutures => Ok(PlaceOrderKind::UsdMarginFutures(
usd_margin_futures::PlaceOrder::try_from(&self.inner)?,
)),
RestEndpoint::Spot => Ok(PlaceOrderKind::Spot(spot::PlaceOrder::try_from(
&self.inner,
)?)),
}
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum PlaceOrderKind {
UsdMarginFutures(usd_margin_futures::PlaceOrder),
Spot(spot::PlaceOrder),
}
impl Rest for PlaceOrder {
fn method(&self, _endpoint: &RestEndpoint) -> Result<http::Method, RestError> {
Ok(http::Method::POST)
}
fn to_path(&self, endpoint: &RestEndpoint) -> Result<String, RestError> {
match endpoint {
RestEndpoint::UsdMarginFutures => Ok(format!("/fapi/v1/order")),
_ => Ok(format!("/api/v3/order")),
}
}
fn need_apikey(&self) -> bool {
true
}
fn need_sign(&self) -> bool {
true
}
fn serialize(&self, endpoint: &RestEndpoint) -> Result<serde_json::Value, RestError> {
Ok(serde_json::to_value(&self.dispatch(endpoint)?)?)
}
fn to_payload(&self) -> super::Payload {
super::Payload::new(self.clone())
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetOrderInner {
pub symbol: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub order_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub orig_client_order_id: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CancelOrder {
#[serde(flatten)]
pub inner: GetOrderInner,
}
impl Rest for CancelOrder {
fn method(&self, _endpoint: &RestEndpoint) -> Result<http::Method, RestError> {
Ok(http::Method::DELETE)
}
fn to_path(&self, endpoint: &RestEndpoint) -> Result<String, RestError> {
match endpoint {
RestEndpoint::UsdMarginFutures => Ok(format!("/fapi/v1/order")),
_ => Ok(format!("/api/v3/order")),
}
}
fn need_apikey(&self) -> bool {
true
}
fn need_sign(&self) -> bool {
true
}
fn serialize(&self, _endpoint: &RestEndpoint) -> Result<serde_json::Value, RestError> {
Ok(serde_json::to_value(self)?)
}
fn to_payload(&self) -> super::Payload {
super::Payload::new(self.clone())
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetOrder {
#[serde(flatten)]
pub inner: GetOrderInner,
}
impl Rest for GetOrder {
fn method(&self, _endpoint: &RestEndpoint) -> Result<http::Method, RestError> {
Ok(http::Method::GET)
}
fn to_path(&self, endpoint: &RestEndpoint) -> Result<String, RestError> {
match endpoint {
RestEndpoint::UsdMarginFutures => Ok(format!("/fapi/v1/order")),
_ => Ok(format!("/api/v3/order")),
}
}
fn need_apikey(&self) -> bool {
true
}
fn need_sign(&self) -> bool {
true
}
fn serialize(&self, _endpoint: &RestEndpoint) -> Result<serde_json::Value, RestError> {
Ok(serde_json::to_value(self)?)
}
fn to_payload(&self) -> super::Payload {
super::Payload::new(self.clone())
}
}