binance/options/apis/
market_maker_block_trade_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::options::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug, Default)]
19pub struct CreateBlockOrderCreateV1Params {
20 pub legs: Vec<String>,
21 pub liquidity: String,
22 pub price: String,
23 pub quantity: String,
24 pub side: String,
25 pub symbol: String,
26 pub timestamp: i32,
27 pub recv_window: Option<i32>
28}
29
30#[derive(Clone, Debug, Default)]
32pub struct DeleteBlockOrderCreateV1Params {
33 pub block_order_matching_key: String,
34 pub timestamp: i32,
35 pub recv_window: Option<i32>
37}
38
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum CreateBlockOrderCreateV1Error {
44 Status4XX(models::ApiError),
45 Status5XX(models::ApiError),
46 UnknownValue(serde_json::Value),
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum DeleteBlockOrderCreateV1Error {
53 Status4XX(models::ApiError),
54 Status5XX(models::ApiError),
55 UnknownValue(serde_json::Value),
56}
57
58
59pub async fn create_block_order_create_v1(configuration: &configuration::Configuration, params: CreateBlockOrderCreateV1Params) -> Result<models::OptionsCreateBlockOrderCreateV1Resp, Error<CreateBlockOrderCreateV1Error>> {
61
62 let uri_str = format!("{}/eapi/v1/block/order/create", configuration.base_path);
63 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
64
65 let mut query_params: Vec<(String, String)> = Vec::new();
67
68
69 let mut header_params = std::collections::HashMap::new();
71
72 if let Some(ref binance_auth) = configuration.binance_auth {
74 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
76
77 let body_string: Option<Vec<u8>> = None;
79
80 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
82 Ok(sig) => sig,
83 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
84 };
85
86 query_params.push(("signature".to_string(), signature));
88 }
89
90 if !query_params.is_empty() {
92 req_builder = req_builder.query(&query_params);
93 }
94
95
96 if let Some(ref user_agent) = configuration.user_agent {
98 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
99 }
100
101 for (header_name, header_value) in header_params {
103 req_builder = req_builder.header(&header_name, &header_value);
104 }
105
106 let mut multipart_form_params = std::collections::HashMap::new();
107 multipart_form_params.insert("legs", params.legs.into_iter().map(|p| serde_json::to_string(&p).unwrap_or_default()).collect::<Vec<String>>().join(",").to_string());
108 multipart_form_params.insert("liquidity", params.liquidity.to_string());
109 multipart_form_params.insert("price", params.price.to_string());
110 multipart_form_params.insert("quantity", params.quantity.to_string());
111 if let Some(param_value) = params.recv_window {
112 multipart_form_params.insert("recvWindow", param_value.to_string());
113 }
114 multipart_form_params.insert("side", params.side.to_string());
115 multipart_form_params.insert("symbol", params.symbol.to_string());
116 multipart_form_params.insert("timestamp", params.timestamp.to_string());
117 req_builder = req_builder.form(&multipart_form_params);
118
119 let req = req_builder.build()?;
120 let resp = configuration.client.execute(req).await?;
121
122 let status = resp.status();
123 let content_type = resp
124 .headers()
125 .get("content-type")
126 .and_then(|v| v.to_str().ok())
127 .unwrap_or("application/octet-stream");
128 let content_type = super::ContentType::from(content_type);
129
130 if !status.is_client_error() && !status.is_server_error() {
131 let content = resp.text().await?;
132 match content_type {
133 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
134 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OptionsCreateBlockOrderCreateV1Resp`"))),
135 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::OptionsCreateBlockOrderCreateV1Resp`")))),
136 }
137 } else {
138 let content = resp.text().await?;
139 let entity: Option<CreateBlockOrderCreateV1Error> = serde_json::from_str(&content).ok();
140 Err(Error::ResponseError(ResponseContent { status, content, entity }))
141 }
142}
143
144pub async fn delete_block_order_create_v1(configuration: &configuration::Configuration, params: DeleteBlockOrderCreateV1Params) -> Result<serde_json::Value, Error<DeleteBlockOrderCreateV1Error>> {
146
147 let uri_str = format!("{}/eapi/v1/block/order/create", configuration.base_path);
148 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
149
150 let mut query_params: Vec<(String, String)> = Vec::new();
152
153 query_params.push(("blockOrderMatchingKey".to_string(), params.block_order_matching_key.to_string()));
154 if let Some(ref param_value) = params.recv_window {
155 query_params.push(("recvWindow".to_string(), param_value.to_string()));
156 }
157 query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
158
159 let mut header_params = std::collections::HashMap::new();
161
162 if let Some(ref binance_auth) = configuration.binance_auth {
164 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
166
167 let body_string: Option<Vec<u8>> = None;
169
170 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
172 Ok(sig) => sig,
173 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
174 };
175
176 query_params.push(("signature".to_string(), signature));
178 }
179
180 if !query_params.is_empty() {
182 req_builder = req_builder.query(&query_params);
183 }
184
185
186 if let Some(ref user_agent) = configuration.user_agent {
188 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
189 }
190
191 for (header_name, header_value) in header_params {
193 req_builder = req_builder.header(&header_name, &header_value);
194 }
195
196
197 let req = req_builder.build()?;
198 let resp = configuration.client.execute(req).await?;
199
200 let status = resp.status();
201 let content_type = resp
202 .headers()
203 .get("content-type")
204 .and_then(|v| v.to_str().ok())
205 .unwrap_or("application/octet-stream");
206 let content_type = super::ContentType::from(content_type);
207
208 if !status.is_client_error() && !status.is_server_error() {
209 let content = resp.text().await?;
210 match content_type {
211 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
212 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
213 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
214 }
215 } else {
216 let content = resp.text().await?;
217 let entity: Option<DeleteBlockOrderCreateV1Error> = serde_json::from_str(&content).ok();
218 Err(Error::ResponseError(ResponseContent { status, content, entity }))
219 }
220}
221