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 ExchangeAccountsApi: Send + Sync {
23 async fn add_exchange_account(
27 &self,
28 params: AddExchangeAccountParams,
29 ) -> Result<models::AddExchangeAccountResponse, Error<AddExchangeAccountError>>;
30
31 async fn convert_assets(
35 &self,
36 params: ConvertAssetsParams,
37 ) -> Result<models::ConvertAssetsResponse, Error<ConvertAssetsError>>;
38
39 async fn get_exchange_account(
44 &self,
45 params: GetExchangeAccountParams,
46 ) -> Result<models::ExchangeAccount, Error<GetExchangeAccountError>>;
47
48 async fn get_exchange_account_asset(
53 &self,
54 params: GetExchangeAccountAssetParams,
55 ) -> Result<models::ExchangeAsset, Error<GetExchangeAccountAssetError>>;
56
57 async fn get_paged_exchange_accounts(
62 &self,
63 params: GetPagedExchangeAccountsParams,
64 ) -> Result<Vec<models::ExchangeAccountsPaged>, Error<GetPagedExchangeAccountsError>>;
65
66 async fn internal_transfer(
70 &self,
71 params: InternalTransferParams,
72 ) -> Result<models::InternalTransferResponse, Error<InternalTransferError>>;
73}
74
75pub struct ExchangeAccountsApiClient {
76 configuration: Arc<configuration::Configuration>,
77}
78
79impl ExchangeAccountsApiClient {
80 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
81 Self { configuration }
82 }
83}
84
85#[derive(Clone, Debug)]
88#[cfg_attr(feature = "bon", derive(::bon::Builder))]
89pub struct AddExchangeAccountParams {
90 pub add_exchange_account_request: models::AddExchangeAccountRequest,
91 pub idempotency_key: Option<String>,
96}
97
98#[derive(Clone, Debug)]
101#[cfg_attr(feature = "bon", derive(::bon::Builder))]
102pub struct ConvertAssetsParams {
103 pub exchange_account_id: String,
107 pub idempotency_key: Option<String>,
112 pub convert_assets_request: Option<models::ConvertAssetsRequest>,
113}
114
115#[derive(Clone, Debug)]
118#[cfg_attr(feature = "bon", derive(::bon::Builder))]
119pub struct GetExchangeAccountParams {
120 pub exchange_account_id: String,
122}
123
124#[derive(Clone, Debug)]
127#[cfg_attr(feature = "bon", derive(::bon::Builder))]
128pub struct GetExchangeAccountAssetParams {
129 pub exchange_account_id: String,
131 pub asset_id: String,
133}
134
135#[derive(Clone, Debug)]
138#[cfg_attr(feature = "bon", derive(::bon::Builder))]
139pub struct GetPagedExchangeAccountsParams {
140 pub limit: f64,
142 pub before: Option<String>,
143 pub after: Option<String>,
144}
145
146#[derive(Clone, Debug)]
149#[cfg_attr(feature = "bon", derive(::bon::Builder))]
150pub struct InternalTransferParams {
151 pub exchange_account_id: String,
153 pub idempotency_key: Option<String>,
158 pub create_internal_transfer_request: Option<models::CreateInternalTransferRequest>,
159}
160
161#[async_trait]
162impl ExchangeAccountsApi for ExchangeAccountsApiClient {
163 async fn add_exchange_account(
165 &self,
166 params: AddExchangeAccountParams,
167 ) -> Result<models::AddExchangeAccountResponse, Error<AddExchangeAccountError>> {
168 let AddExchangeAccountParams {
169 add_exchange_account_request,
170 idempotency_key,
171 } = params;
172
173 let local_var_configuration = &self.configuration;
174
175 let local_var_client = &local_var_configuration.client;
176
177 let local_var_uri_str = format!("{}/exchange_accounts", local_var_configuration.base_path);
178 let mut local_var_req_builder =
179 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
180
181 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
182 local_var_req_builder = local_var_req_builder
183 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
184 }
185 if let Some(local_var_param_value) = idempotency_key {
186 local_var_req_builder =
187 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
188 }
189 local_var_req_builder = local_var_req_builder.json(&add_exchange_account_request);
190
191 let local_var_req = local_var_req_builder.build()?;
192 let local_var_resp = local_var_client.execute(local_var_req).await?;
193
194 let local_var_status = local_var_resp.status();
195 let local_var_content_type = local_var_resp
196 .headers()
197 .get("content-type")
198 .and_then(|v| v.to_str().ok())
199 .unwrap_or("application/octet-stream");
200 let local_var_content_type = super::ContentType::from(local_var_content_type);
201 let local_var_content = local_var_resp.text().await?;
202
203 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
204 match local_var_content_type {
205 ContentType::Json => {
206 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
207 }
208 ContentType::Text => {
209 return Err(Error::from(serde_json::Error::custom(
210 "Received `text/plain` content type response that cannot be converted to \
211 `models::AddExchangeAccountResponse`",
212 )));
213 }
214 ContentType::Unsupported(local_var_unknown_type) => {
215 return Err(Error::from(serde_json::Error::custom(format!(
216 "Received `{local_var_unknown_type}` content type response that cannot be \
217 converted to `models::AddExchangeAccountResponse`"
218 ))));
219 }
220 }
221 } else {
222 let local_var_entity: Option<AddExchangeAccountError> =
223 serde_json::from_str(&local_var_content).ok();
224 let local_var_error = ResponseContent {
225 status: local_var_status,
226 content: local_var_content,
227 entity: local_var_entity,
228 };
229 Err(Error::ResponseError(local_var_error))
230 }
231 }
232
233 async fn convert_assets(
235 &self,
236 params: ConvertAssetsParams,
237 ) -> Result<models::ConvertAssetsResponse, Error<ConvertAssetsError>> {
238 let ConvertAssetsParams {
239 exchange_account_id,
240 idempotency_key,
241 convert_assets_request,
242 } = params;
243
244 let local_var_configuration = &self.configuration;
245
246 let local_var_client = &local_var_configuration.client;
247
248 let local_var_uri_str = format!(
249 "{}/exchange_accounts/{exchangeAccountId}/convert",
250 local_var_configuration.base_path,
251 exchangeAccountId = crate::apis::urlencode(exchange_account_id)
252 );
253 let mut local_var_req_builder =
254 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
255
256 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
257 local_var_req_builder = local_var_req_builder
258 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
259 }
260 if let Some(local_var_param_value) = idempotency_key {
261 local_var_req_builder =
262 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
263 }
264 local_var_req_builder = local_var_req_builder.json(&convert_assets_request);
265
266 let local_var_req = local_var_req_builder.build()?;
267 let local_var_resp = local_var_client.execute(local_var_req).await?;
268
269 let local_var_status = local_var_resp.status();
270 let local_var_content_type = local_var_resp
271 .headers()
272 .get("content-type")
273 .and_then(|v| v.to_str().ok())
274 .unwrap_or("application/octet-stream");
275 let local_var_content_type = super::ContentType::from(local_var_content_type);
276 let local_var_content = local_var_resp.text().await?;
277
278 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
279 match local_var_content_type {
280 ContentType::Json => {
281 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
282 }
283 ContentType::Text => {
284 return Err(Error::from(serde_json::Error::custom(
285 "Received `text/plain` content type response that cannot be converted to \
286 `models::ConvertAssetsResponse`",
287 )));
288 }
289 ContentType::Unsupported(local_var_unknown_type) => {
290 return Err(Error::from(serde_json::Error::custom(format!(
291 "Received `{local_var_unknown_type}` content type response that cannot be \
292 converted to `models::ConvertAssetsResponse`"
293 ))));
294 }
295 }
296 } else {
297 let local_var_entity: Option<ConvertAssetsError> =
298 serde_json::from_str(&local_var_content).ok();
299 let local_var_error = ResponseContent {
300 status: local_var_status,
301 content: local_var_content,
302 entity: local_var_entity,
303 };
304 Err(Error::ResponseError(local_var_error))
305 }
306 }
307
308 async fn get_exchange_account(
311 &self,
312 params: GetExchangeAccountParams,
313 ) -> Result<models::ExchangeAccount, Error<GetExchangeAccountError>> {
314 let GetExchangeAccountParams {
315 exchange_account_id,
316 } = params;
317
318 let local_var_configuration = &self.configuration;
319
320 let local_var_client = &local_var_configuration.client;
321
322 let local_var_uri_str = format!(
323 "{}/exchange_accounts/{exchangeAccountId}",
324 local_var_configuration.base_path,
325 exchangeAccountId = crate::apis::urlencode(exchange_account_id)
326 );
327 let mut local_var_req_builder =
328 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
329
330 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
331 local_var_req_builder = local_var_req_builder
332 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
333 }
334
335 let local_var_req = local_var_req_builder.build()?;
336 let local_var_resp = local_var_client.execute(local_var_req).await?;
337
338 let local_var_status = local_var_resp.status();
339 let local_var_content_type = local_var_resp
340 .headers()
341 .get("content-type")
342 .and_then(|v| v.to_str().ok())
343 .unwrap_or("application/octet-stream");
344 let local_var_content_type = super::ContentType::from(local_var_content_type);
345 let local_var_content = local_var_resp.text().await?;
346
347 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
348 match local_var_content_type {
349 ContentType::Json => {
350 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
351 }
352 ContentType::Text => {
353 return Err(Error::from(serde_json::Error::custom(
354 "Received `text/plain` content type response that cannot be converted to \
355 `models::ExchangeAccount`",
356 )));
357 }
358 ContentType::Unsupported(local_var_unknown_type) => {
359 return Err(Error::from(serde_json::Error::custom(format!(
360 "Received `{local_var_unknown_type}` content type response that cannot be \
361 converted to `models::ExchangeAccount`"
362 ))));
363 }
364 }
365 } else {
366 let local_var_entity: Option<GetExchangeAccountError> =
367 serde_json::from_str(&local_var_content).ok();
368 let local_var_error = ResponseContent {
369 status: local_var_status,
370 content: local_var_content,
371 entity: local_var_entity,
372 };
373 Err(Error::ResponseError(local_var_error))
374 }
375 }
376
377 async fn get_exchange_account_asset(
380 &self,
381 params: GetExchangeAccountAssetParams,
382 ) -> Result<models::ExchangeAsset, Error<GetExchangeAccountAssetError>> {
383 let GetExchangeAccountAssetParams {
384 exchange_account_id,
385 asset_id,
386 } = params;
387
388 let local_var_configuration = &self.configuration;
389
390 let local_var_client = &local_var_configuration.client;
391
392 let local_var_uri_str = format!(
393 "{}/exchange_accounts/{exchangeAccountId}/{assetId}",
394 local_var_configuration.base_path,
395 exchangeAccountId = crate::apis::urlencode(exchange_account_id),
396 assetId = crate::apis::urlencode(asset_id)
397 );
398 let mut local_var_req_builder =
399 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
400
401 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
402 local_var_req_builder = local_var_req_builder
403 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
404 }
405
406 let local_var_req = local_var_req_builder.build()?;
407 let local_var_resp = local_var_client.execute(local_var_req).await?;
408
409 let local_var_status = local_var_resp.status();
410 let local_var_content_type = local_var_resp
411 .headers()
412 .get("content-type")
413 .and_then(|v| v.to_str().ok())
414 .unwrap_or("application/octet-stream");
415 let local_var_content_type = super::ContentType::from(local_var_content_type);
416 let local_var_content = local_var_resp.text().await?;
417
418 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
419 match local_var_content_type {
420 ContentType::Json => {
421 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
422 }
423 ContentType::Text => {
424 return Err(Error::from(serde_json::Error::custom(
425 "Received `text/plain` content type response that cannot be converted to \
426 `models::ExchangeAsset`",
427 )));
428 }
429 ContentType::Unsupported(local_var_unknown_type) => {
430 return Err(Error::from(serde_json::Error::custom(format!(
431 "Received `{local_var_unknown_type}` content type response that cannot be \
432 converted to `models::ExchangeAsset`"
433 ))));
434 }
435 }
436 } else {
437 let local_var_entity: Option<GetExchangeAccountAssetError> =
438 serde_json::from_str(&local_var_content).ok();
439 let local_var_error = ResponseContent {
440 status: local_var_status,
441 content: local_var_content,
442 entity: local_var_entity,
443 };
444 Err(Error::ResponseError(local_var_error))
445 }
446 }
447
448 async fn get_paged_exchange_accounts(
451 &self,
452 params: GetPagedExchangeAccountsParams,
453 ) -> Result<Vec<models::ExchangeAccountsPaged>, Error<GetPagedExchangeAccountsError>> {
454 let GetPagedExchangeAccountsParams {
455 limit,
456 before,
457 after,
458 } = params;
459
460 let local_var_configuration = &self.configuration;
461
462 let local_var_client = &local_var_configuration.client;
463
464 let local_var_uri_str = format!(
465 "{}/exchange_accounts/paged",
466 local_var_configuration.base_path
467 );
468 let mut local_var_req_builder =
469 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
470
471 if let Some(ref param_value) = before {
472 local_var_req_builder =
473 local_var_req_builder.query(&[("before", ¶m_value.to_string())]);
474 }
475 if let Some(ref param_value) = after {
476 local_var_req_builder =
477 local_var_req_builder.query(&[("after", ¶m_value.to_string())]);
478 }
479 local_var_req_builder = local_var_req_builder.query(&[("limit", &limit.to_string())]);
480 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
481 local_var_req_builder = local_var_req_builder
482 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
483 }
484
485 let local_var_req = local_var_req_builder.build()?;
486 let local_var_resp = local_var_client.execute(local_var_req).await?;
487
488 let local_var_status = local_var_resp.status();
489 let local_var_content_type = local_var_resp
490 .headers()
491 .get("content-type")
492 .and_then(|v| v.to_str().ok())
493 .unwrap_or("application/octet-stream");
494 let local_var_content_type = super::ContentType::from(local_var_content_type);
495 let local_var_content = local_var_resp.text().await?;
496
497 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
498 match local_var_content_type {
499 ContentType::Json => {
500 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
501 }
502 ContentType::Text => {
503 return Err(Error::from(serde_json::Error::custom(
504 "Received `text/plain` content type response that cannot be converted to \
505 `Vec<models::ExchangeAccountsPaged>`",
506 )));
507 }
508 ContentType::Unsupported(local_var_unknown_type) => {
509 return Err(Error::from(serde_json::Error::custom(format!(
510 "Received `{local_var_unknown_type}` content type response that cannot be \
511 converted to `Vec<models::ExchangeAccountsPaged>`"
512 ))));
513 }
514 }
515 } else {
516 let local_var_entity: Option<GetPagedExchangeAccountsError> =
517 serde_json::from_str(&local_var_content).ok();
518 let local_var_error = ResponseContent {
519 status: local_var_status,
520 content: local_var_content,
521 entity: local_var_entity,
522 };
523 Err(Error::ResponseError(local_var_error))
524 }
525 }
526
527 async fn internal_transfer(
529 &self,
530 params: InternalTransferParams,
531 ) -> Result<models::InternalTransferResponse, Error<InternalTransferError>> {
532 let InternalTransferParams {
533 exchange_account_id,
534 idempotency_key,
535 create_internal_transfer_request,
536 } = params;
537
538 let local_var_configuration = &self.configuration;
539
540 let local_var_client = &local_var_configuration.client;
541
542 let local_var_uri_str = format!(
543 "{}/exchange_accounts/{exchangeAccountId}/internal_transfer",
544 local_var_configuration.base_path,
545 exchangeAccountId = crate::apis::urlencode(exchange_account_id)
546 );
547 let mut local_var_req_builder =
548 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
549
550 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
551 local_var_req_builder = local_var_req_builder
552 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
553 }
554 if let Some(local_var_param_value) = idempotency_key {
555 local_var_req_builder =
556 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
557 }
558 local_var_req_builder = local_var_req_builder.json(&create_internal_transfer_request);
559
560 let local_var_req = local_var_req_builder.build()?;
561 let local_var_resp = local_var_client.execute(local_var_req).await?;
562
563 let local_var_status = local_var_resp.status();
564 let local_var_content_type = local_var_resp
565 .headers()
566 .get("content-type")
567 .and_then(|v| v.to_str().ok())
568 .unwrap_or("application/octet-stream");
569 let local_var_content_type = super::ContentType::from(local_var_content_type);
570 let local_var_content = local_var_resp.text().await?;
571
572 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
573 match local_var_content_type {
574 ContentType::Json => {
575 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
576 }
577 ContentType::Text => {
578 return Err(Error::from(serde_json::Error::custom(
579 "Received `text/plain` content type response that cannot be converted to \
580 `models::InternalTransferResponse`",
581 )));
582 }
583 ContentType::Unsupported(local_var_unknown_type) => {
584 return Err(Error::from(serde_json::Error::custom(format!(
585 "Received `{local_var_unknown_type}` content type response that cannot be \
586 converted to `models::InternalTransferResponse`"
587 ))));
588 }
589 }
590 } else {
591 let local_var_entity: Option<InternalTransferError> =
592 serde_json::from_str(&local_var_content).ok();
593 let local_var_error = ResponseContent {
594 status: local_var_status,
595 content: local_var_content,
596 entity: local_var_entity,
597 };
598 Err(Error::ResponseError(local_var_error))
599 }
600 }
601}
602
603#[derive(Debug, Clone, Serialize, Deserialize)]
606#[serde(untagged)]
607pub enum AddExchangeAccountError {
608 DefaultResponse(models::ErrorSchema),
609 UnknownValue(serde_json::Value),
610}
611
612#[derive(Debug, Clone, Serialize, Deserialize)]
614#[serde(untagged)]
615pub enum ConvertAssetsError {
616 DefaultResponse(models::ErrorSchema),
617 UnknownValue(serde_json::Value),
618}
619
620#[derive(Debug, Clone, Serialize, Deserialize)]
623#[serde(untagged)]
624pub enum GetExchangeAccountError {
625 DefaultResponse(models::ErrorSchema),
626 UnknownValue(serde_json::Value),
627}
628
629#[derive(Debug, Clone, Serialize, Deserialize)]
632#[serde(untagged)]
633pub enum GetExchangeAccountAssetError {
634 DefaultResponse(models::ErrorSchema),
635 UnknownValue(serde_json::Value),
636}
637
638#[derive(Debug, Clone, Serialize, Deserialize)]
641#[serde(untagged)]
642pub enum GetPagedExchangeAccountsError {
643 DefaultResponse(models::ErrorSchema),
644 UnknownValue(serde_json::Value),
645}
646
647#[derive(Debug, Clone, Serialize, Deserialize)]
649#[serde(untagged)]
650pub enum InternalTransferError {
651 DefaultResponse(models::ErrorSchema),
652 UnknownValue(serde_json::Value),
653}