1use {
10 super::{Error, configuration},
11 crate::{
12 apis::{ContentType, ResponseContent},
13 models,
14 },
15 async_trait::async_trait,
16 reqwest,
17 serde::{Deserialize, Serialize, de::Error as _},
18 std::sync::Arc,
19};
20
21#[async_trait]
22pub trait OffExchangeApi: Send + Sync {
23 async fn add_off_exchange(
27 &self,
28 params: AddOffExchangeParams,
29 ) -> Result<models::CreateTransactionResponse, Error<AddOffExchangeError>>;
30
31 async fn get_off_exchange_collateral_accounts(
36 &self,
37 params: GetOffExchangeCollateralAccountsParams,
38 ) -> Result<models::ExchangeAccount, Error<GetOffExchangeCollateralAccountsError>>;
39
40 async fn get_off_exchange_settlement_transactions(
45 &self,
46 params: GetOffExchangeSettlementTransactionsParams,
47 ) -> Result<
48 models::ExchangeSettlementTransactionsResponse,
49 Error<GetOffExchangeSettlementTransactionsError>,
50 >;
51
52 async fn remove_off_exchange(
57 &self,
58 params: RemoveOffExchangeParams,
59 ) -> Result<models::CreateTransactionResponse, Error<RemoveOffExchangeError>>;
60
61 async fn settle_off_exchange_trades(
65 &self,
66 params: SettleOffExchangeTradesParams,
67 ) -> Result<models::SettlementResponse, Error<SettleOffExchangeTradesError>>;
68}
69
70pub struct OffExchangeApiClient {
71 configuration: Arc<configuration::Configuration>,
72}
73
74impl OffExchangeApiClient {
75 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
76 Self { configuration }
77 }
78}
79
80#[derive(Clone, Debug)]
82#[cfg_attr(feature = "bon", derive(::bon::Builder))]
83pub struct AddOffExchangeParams {
84 pub idempotency_key: Option<String>,
89 pub add_collateral_request_body: Option<models::AddCollateralRequestBody>,
90}
91
92#[derive(Clone, Debug)]
95#[cfg_attr(feature = "bon", derive(::bon::Builder))]
96pub struct GetOffExchangeCollateralAccountsParams {
97 pub main_exchange_account_id: String,
100}
101
102#[derive(Clone, Debug)]
105#[cfg_attr(feature = "bon", derive(::bon::Builder))]
106pub struct GetOffExchangeSettlementTransactionsParams {
107 pub main_exchange_account_id: String,
108}
109
110#[derive(Clone, Debug)]
112#[cfg_attr(feature = "bon", derive(::bon::Builder))]
113pub struct RemoveOffExchangeParams {
114 pub idempotency_key: Option<String>,
119 pub remove_collateral_request_body: Option<models::RemoveCollateralRequestBody>,
120}
121
122#[derive(Clone, Debug)]
124#[cfg_attr(feature = "bon", derive(::bon::Builder))]
125pub struct SettleOffExchangeTradesParams {
126 pub idempotency_key: Option<String>,
131 pub settlement_request_body: Option<models::SettlementRequestBody>,
132}
133
134#[async_trait]
135impl OffExchangeApi for OffExchangeApiClient {
136 async fn add_off_exchange(
138 &self,
139 params: AddOffExchangeParams,
140 ) -> Result<models::CreateTransactionResponse, Error<AddOffExchangeError>> {
141 let AddOffExchangeParams {
142 idempotency_key,
143 add_collateral_request_body,
144 } = params;
145
146 let local_var_configuration = &self.configuration;
147
148 let local_var_client = &local_var_configuration.client;
149
150 let local_var_uri_str = format!("{}/off_exchange/add", local_var_configuration.base_path);
151 let mut local_var_req_builder =
152 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
153
154 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
155 local_var_req_builder = local_var_req_builder
156 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
157 }
158 if let Some(local_var_param_value) = idempotency_key {
159 local_var_req_builder =
160 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
161 }
162 local_var_req_builder = local_var_req_builder.json(&add_collateral_request_body);
163
164 let local_var_req = local_var_req_builder.build()?;
165 let local_var_resp = local_var_client.execute(local_var_req).await?;
166
167 let local_var_status = local_var_resp.status();
168 let local_var_content_type = local_var_resp
169 .headers()
170 .get("content-type")
171 .and_then(|v| v.to_str().ok())
172 .unwrap_or("application/octet-stream");
173 let local_var_content_type = super::ContentType::from(local_var_content_type);
174 let local_var_content = local_var_resp.text().await?;
175
176 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
177 match local_var_content_type {
178 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
179 ContentType::Text => {
180 return Err(Error::from(serde_json::Error::custom(
181 "Received `text/plain` content type response that cannot be converted to \
182 `models::CreateTransactionResponse`",
183 )));
184 }
185 ContentType::Unsupported(local_var_unknown_type) => {
186 return Err(Error::from(serde_json::Error::custom(format!(
187 "Received `{local_var_unknown_type}` content type response that cannot be \
188 converted to `models::CreateTransactionResponse`"
189 ))));
190 }
191 }
192 } else {
193 let local_var_entity: Option<AddOffExchangeError> =
194 serde_json::from_str(&local_var_content).ok();
195 let local_var_error = ResponseContent {
196 status: local_var_status,
197 content: local_var_content,
198 entity: local_var_entity,
199 };
200 Err(Error::ResponseError(local_var_error))
201 }
202 }
203
204 async fn get_off_exchange_collateral_accounts(
207 &self,
208 params: GetOffExchangeCollateralAccountsParams,
209 ) -> Result<models::ExchangeAccount, Error<GetOffExchangeCollateralAccountsError>> {
210 let GetOffExchangeCollateralAccountsParams {
211 main_exchange_account_id,
212 } = params;
213
214 let local_var_configuration = &self.configuration;
215
216 let local_var_client = &local_var_configuration.client;
217
218 let local_var_uri_str = format!(
219 "{}/off_exchange/collateral_accounts/{mainExchangeAccountId}",
220 local_var_configuration.base_path,
221 mainExchangeAccountId = crate::apis::urlencode(main_exchange_account_id)
222 );
223 let mut local_var_req_builder =
224 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
225
226 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
227 local_var_req_builder = local_var_req_builder
228 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
229 }
230
231 let local_var_req = local_var_req_builder.build()?;
232 let local_var_resp = local_var_client.execute(local_var_req).await?;
233
234 let local_var_status = local_var_resp.status();
235 let local_var_content_type = local_var_resp
236 .headers()
237 .get("content-type")
238 .and_then(|v| v.to_str().ok())
239 .unwrap_or("application/octet-stream");
240 let local_var_content_type = super::ContentType::from(local_var_content_type);
241 let local_var_content = local_var_resp.text().await?;
242
243 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
244 match local_var_content_type {
245 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
246 ContentType::Text => {
247 return Err(Error::from(serde_json::Error::custom(
248 "Received `text/plain` content type response that cannot be converted to \
249 `models::ExchangeAccount`",
250 )));
251 }
252 ContentType::Unsupported(local_var_unknown_type) => {
253 return Err(Error::from(serde_json::Error::custom(format!(
254 "Received `{local_var_unknown_type}` content type response that cannot be \
255 converted to `models::ExchangeAccount`"
256 ))));
257 }
258 }
259 } else {
260 let local_var_entity: Option<GetOffExchangeCollateralAccountsError> =
261 serde_json::from_str(&local_var_content).ok();
262 let local_var_error = ResponseContent {
263 status: local_var_status,
264 content: local_var_content,
265 entity: local_var_entity,
266 };
267 Err(Error::ResponseError(local_var_error))
268 }
269 }
270
271 async fn get_off_exchange_settlement_transactions(
274 &self,
275 params: GetOffExchangeSettlementTransactionsParams,
276 ) -> Result<
277 models::ExchangeSettlementTransactionsResponse,
278 Error<GetOffExchangeSettlementTransactionsError>,
279 > {
280 let GetOffExchangeSettlementTransactionsParams {
281 main_exchange_account_id,
282 } = params;
283
284 let local_var_configuration = &self.configuration;
285
286 let local_var_client = &local_var_configuration.client;
287
288 let local_var_uri_str = format!(
289 "{}/off_exchange/settlements/transactions",
290 local_var_configuration.base_path
291 );
292 let mut local_var_req_builder =
293 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
294
295 local_var_req_builder = local_var_req_builder.query(&[(
296 "mainExchangeAccountId",
297 &main_exchange_account_id.to_string(),
298 )]);
299 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
300 local_var_req_builder = local_var_req_builder
301 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
302 }
303
304 let local_var_req = local_var_req_builder.build()?;
305 let local_var_resp = local_var_client.execute(local_var_req).await?;
306
307 let local_var_status = local_var_resp.status();
308 let local_var_content_type = local_var_resp
309 .headers()
310 .get("content-type")
311 .and_then(|v| v.to_str().ok())
312 .unwrap_or("application/octet-stream");
313 let local_var_content_type = super::ContentType::from(local_var_content_type);
314 let local_var_content = local_var_resp.text().await?;
315
316 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
317 match local_var_content_type {
318 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
319 ContentType::Text => {
320 return Err(Error::from(serde_json::Error::custom(
321 "Received `text/plain` content type response that cannot be converted to \
322 `models::ExchangeSettlementTransactionsResponse`",
323 )));
324 }
325 ContentType::Unsupported(local_var_unknown_type) => {
326 return Err(Error::from(serde_json::Error::custom(format!(
327 "Received `{local_var_unknown_type}` content type response that cannot be \
328 converted to `models::ExchangeSettlementTransactionsResponse`"
329 ))));
330 }
331 }
332 } else {
333 let local_var_entity: Option<GetOffExchangeSettlementTransactionsError> =
334 serde_json::from_str(&local_var_content).ok();
335 let local_var_error = ResponseContent {
336 status: local_var_status,
337 content: local_var_content,
338 entity: local_var_entity,
339 };
340 Err(Error::ResponseError(local_var_error))
341 }
342 }
343
344 async fn remove_off_exchange(
347 &self,
348 params: RemoveOffExchangeParams,
349 ) -> Result<models::CreateTransactionResponse, Error<RemoveOffExchangeError>> {
350 let RemoveOffExchangeParams {
351 idempotency_key,
352 remove_collateral_request_body,
353 } = params;
354
355 let local_var_configuration = &self.configuration;
356
357 let local_var_client = &local_var_configuration.client;
358
359 let local_var_uri_str =
360 format!("{}/off_exchange/remove", local_var_configuration.base_path);
361 let mut local_var_req_builder =
362 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
363
364 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
365 local_var_req_builder = local_var_req_builder
366 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
367 }
368 if let Some(local_var_param_value) = idempotency_key {
369 local_var_req_builder =
370 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
371 }
372 local_var_req_builder = local_var_req_builder.json(&remove_collateral_request_body);
373
374 let local_var_req = local_var_req_builder.build()?;
375 let local_var_resp = local_var_client.execute(local_var_req).await?;
376
377 let local_var_status = local_var_resp.status();
378 let local_var_content_type = local_var_resp
379 .headers()
380 .get("content-type")
381 .and_then(|v| v.to_str().ok())
382 .unwrap_or("application/octet-stream");
383 let local_var_content_type = super::ContentType::from(local_var_content_type);
384 let local_var_content = local_var_resp.text().await?;
385
386 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
387 match local_var_content_type {
388 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
389 ContentType::Text => {
390 return Err(Error::from(serde_json::Error::custom(
391 "Received `text/plain` content type response that cannot be converted to \
392 `models::CreateTransactionResponse`",
393 )));
394 }
395 ContentType::Unsupported(local_var_unknown_type) => {
396 return Err(Error::from(serde_json::Error::custom(format!(
397 "Received `{local_var_unknown_type}` content type response that cannot be \
398 converted to `models::CreateTransactionResponse`"
399 ))));
400 }
401 }
402 } else {
403 let local_var_entity: Option<RemoveOffExchangeError> =
404 serde_json::from_str(&local_var_content).ok();
405 let local_var_error = ResponseContent {
406 status: local_var_status,
407 content: local_var_content,
408 entity: local_var_entity,
409 };
410 Err(Error::ResponseError(local_var_error))
411 }
412 }
413
414 async fn settle_off_exchange_trades(
416 &self,
417 params: SettleOffExchangeTradesParams,
418 ) -> Result<models::SettlementResponse, Error<SettleOffExchangeTradesError>> {
419 let SettleOffExchangeTradesParams {
420 idempotency_key,
421 settlement_request_body,
422 } = params;
423
424 let local_var_configuration = &self.configuration;
425
426 let local_var_client = &local_var_configuration.client;
427
428 let local_var_uri_str = format!(
429 "{}/off_exchange/settlements/trader",
430 local_var_configuration.base_path
431 );
432 let mut local_var_req_builder =
433 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
434
435 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
436 local_var_req_builder = local_var_req_builder
437 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
438 }
439 if let Some(local_var_param_value) = idempotency_key {
440 local_var_req_builder =
441 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
442 }
443 local_var_req_builder = local_var_req_builder.json(&settlement_request_body);
444
445 let local_var_req = local_var_req_builder.build()?;
446 let local_var_resp = local_var_client.execute(local_var_req).await?;
447
448 let local_var_status = local_var_resp.status();
449 let local_var_content_type = local_var_resp
450 .headers()
451 .get("content-type")
452 .and_then(|v| v.to_str().ok())
453 .unwrap_or("application/octet-stream");
454 let local_var_content_type = super::ContentType::from(local_var_content_type);
455 let local_var_content = local_var_resp.text().await?;
456
457 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
458 match local_var_content_type {
459 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
460 ContentType::Text => {
461 return Err(Error::from(serde_json::Error::custom(
462 "Received `text/plain` content type response that cannot be converted to \
463 `models::SettlementResponse`",
464 )));
465 }
466 ContentType::Unsupported(local_var_unknown_type) => {
467 return Err(Error::from(serde_json::Error::custom(format!(
468 "Received `{local_var_unknown_type}` content type response that cannot be \
469 converted to `models::SettlementResponse`"
470 ))));
471 }
472 }
473 } else {
474 let local_var_entity: Option<SettleOffExchangeTradesError> =
475 serde_json::from_str(&local_var_content).ok();
476 let local_var_error = ResponseContent {
477 status: local_var_status,
478 content: local_var_content,
479 entity: local_var_entity,
480 };
481 Err(Error::ResponseError(local_var_error))
482 }
483 }
484}
485
486#[derive(Debug, Clone, Serialize, Deserialize)]
488#[serde(untagged)]
489pub enum AddOffExchangeError {
490 DefaultResponse(models::ErrorSchema),
491 UnknownValue(serde_json::Value),
492}
493
494#[derive(Debug, Clone, Serialize, Deserialize)]
496#[serde(untagged)]
497pub enum GetOffExchangeCollateralAccountsError {
498 DefaultResponse(models::ErrorSchema),
499 UnknownValue(serde_json::Value),
500}
501
502#[derive(Debug, Clone, Serialize, Deserialize)]
505#[serde(untagged)]
506pub enum GetOffExchangeSettlementTransactionsError {
507 DefaultResponse(models::ErrorSchema),
508 UnknownValue(serde_json::Value),
509}
510
511#[derive(Debug, Clone, Serialize, Deserialize)]
513#[serde(untagged)]
514pub enum RemoveOffExchangeError {
515 DefaultResponse(models::ErrorSchema),
516 UnknownValue(serde_json::Value),
517}
518
519#[derive(Debug, Clone, Serialize, Deserialize)]
521#[serde(untagged)]
522pub enum SettleOffExchangeTradesError {
523 DefaultResponse(models::ErrorSchema),
524 UnknownValue(serde_json::Value),
525}