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