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 TradingBetaApi: Send + Sync {
23 async fn create_order(
33 &self,
34 params: CreateOrderParams,
35 ) -> Result<models::OrderDetails, Error<CreateOrderError>>;
36
37 async fn create_quote(
47 &self,
48 params: CreateQuoteParams,
49 ) -> Result<models::QuotesResponse, Error<CreateQuoteError>>;
50
51 async fn get_order(
60 &self,
61 params: GetOrderParams,
62 ) -> Result<models::OrderDetails, Error<GetOrderError>>;
63
64 async fn get_orders(
74 &self,
75 params: GetOrdersParams,
76 ) -> Result<models::GetOrdersResponse, Error<GetOrdersError>>;
77
78 async fn get_trading_providers(
88 &self,
89 params: GetTradingProvidersParams,
90 ) -> Result<models::ProvidersListResponse, Error<GetTradingProvidersError>>;
91}
92
93pub struct TradingBetaApiClient {
94 configuration: Arc<configuration::Configuration>,
95}
96
97impl TradingBetaApiClient {
98 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
99 Self { configuration }
100 }
101}
102
103#[derive(Clone, Debug)]
105#[cfg_attr(feature = "bon", derive(::bon::Builder))]
106pub struct CreateOrderParams {
107 pub create_order_request: models::CreateOrderRequest,
108 pub idempotency_key: Option<String>,
113}
114
115#[derive(Clone, Debug)]
117#[cfg_attr(feature = "bon", derive(::bon::Builder))]
118pub struct CreateQuoteParams {
119 pub create_quote: models::CreateQuote,
120 pub idempotency_key: Option<String>,
125}
126
127#[derive(Clone, Debug)]
129#[cfg_attr(feature = "bon", derive(::bon::Builder))]
130pub struct GetOrderParams {
131 pub order_id: String,
133}
134
135#[derive(Clone, Debug)]
137#[cfg_attr(feature = "bon", derive(::bon::Builder))]
138pub struct GetOrdersParams {
139 pub page_size: u8,
141 pub page_cursor: Option<String>,
142 pub order: Option<String>,
144 pub account_id: Option<Vec<String>>,
146 pub provider_id: Option<Vec<String>>,
148 pub statuses: Option<Vec<models::OrderStatus>>,
150 pub start_time: Option<u32>,
151 pub end_time: Option<u32>,
152 pub asset_conversion_type: Option<String>,
153}
154
155#[derive(Clone, Debug)]
158#[cfg_attr(feature = "bon", derive(::bon::Builder))]
159pub struct GetTradingProvidersParams {
160 pub page_size: Option<u8>,
162 pub page_cursor: Option<String>,
164}
165
166#[async_trait]
167impl TradingBetaApi for TradingBetaApiClient {
168 async fn create_order(
176 &self,
177 params: CreateOrderParams,
178 ) -> Result<models::OrderDetails, Error<CreateOrderError>> {
179 let CreateOrderParams {
180 create_order_request,
181 idempotency_key,
182 } = params;
183
184 let local_var_configuration = &self.configuration;
185
186 let local_var_client = &local_var_configuration.client;
187
188 let local_var_uri_str = format!("{}/trading/orders", local_var_configuration.base_path);
189 let mut local_var_req_builder =
190 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
191
192 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
193 local_var_req_builder = local_var_req_builder
194 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
195 }
196 if let Some(local_var_param_value) = idempotency_key {
197 local_var_req_builder =
198 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
199 }
200 local_var_req_builder = local_var_req_builder.json(&create_order_request);
201
202 let local_var_req = local_var_req_builder.build()?;
203 let local_var_resp = local_var_client.execute(local_var_req).await?;
204
205 let local_var_status = local_var_resp.status();
206 let local_var_content_type = local_var_resp
207 .headers()
208 .get("content-type")
209 .and_then(|v| v.to_str().ok())
210 .unwrap_or("application/octet-stream");
211 let local_var_content_type = super::ContentType::from(local_var_content_type);
212 let local_var_content = local_var_resp.text().await?;
213
214 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
215 match local_var_content_type {
216 ContentType::Json => {
217 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
218 }
219 ContentType::Text => {
220 return Err(Error::from(serde_json::Error::custom(
221 "Received `text/plain` content type response that cannot be converted to \
222 `models::OrderDetails`",
223 )));
224 }
225 ContentType::Unsupported(local_var_unknown_type) => {
226 return Err(Error::from(serde_json::Error::custom(format!(
227 "Received `{local_var_unknown_type}` content type response that cannot be \
228 converted to `models::OrderDetails`"
229 ))));
230 }
231 }
232 } else {
233 let local_var_entity: Option<CreateOrderError> =
234 serde_json::from_str(&local_var_content).ok();
235 let local_var_error = ResponseContent {
236 status: local_var_status,
237 content: local_var_content,
238 entity: local_var_entity,
239 };
240 Err(Error::ResponseError(local_var_error))
241 }
242 }
243
244 async fn create_quote(
252 &self,
253 params: CreateQuoteParams,
254 ) -> Result<models::QuotesResponse, Error<CreateQuoteError>> {
255 let CreateQuoteParams {
256 create_quote,
257 idempotency_key,
258 } = params;
259
260 let local_var_configuration = &self.configuration;
261
262 let local_var_client = &local_var_configuration.client;
263
264 let local_var_uri_str = format!("{}/trading/quotes", local_var_configuration.base_path);
265 let mut local_var_req_builder =
266 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
267
268 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
269 local_var_req_builder = local_var_req_builder
270 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
271 }
272 if let Some(local_var_param_value) = idempotency_key {
273 local_var_req_builder =
274 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
275 }
276 local_var_req_builder = local_var_req_builder.json(&create_quote);
277
278 let local_var_req = local_var_req_builder.build()?;
279 let local_var_resp = local_var_client.execute(local_var_req).await?;
280
281 let local_var_status = local_var_resp.status();
282 let local_var_content_type = local_var_resp
283 .headers()
284 .get("content-type")
285 .and_then(|v| v.to_str().ok())
286 .unwrap_or("application/octet-stream");
287 let local_var_content_type = super::ContentType::from(local_var_content_type);
288 let local_var_content = local_var_resp.text().await?;
289
290 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
291 match local_var_content_type {
292 ContentType::Json => {
293 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
294 }
295 ContentType::Text => {
296 return Err(Error::from(serde_json::Error::custom(
297 "Received `text/plain` content type response that cannot be converted to \
298 `models::QuotesResponse`",
299 )));
300 }
301 ContentType::Unsupported(local_var_unknown_type) => {
302 return Err(Error::from(serde_json::Error::custom(format!(
303 "Received `{local_var_unknown_type}` content type response that cannot be \
304 converted to `models::QuotesResponse`"
305 ))));
306 }
307 }
308 } else {
309 let local_var_entity: Option<CreateQuoteError> =
310 serde_json::from_str(&local_var_content).ok();
311 let local_var_error = ResponseContent {
312 status: local_var_status,
313 content: local_var_content,
314 entity: local_var_entity,
315 };
316 Err(Error::ResponseError(local_var_error))
317 }
318 }
319
320 async fn get_order(
327 &self,
328 params: GetOrderParams,
329 ) -> Result<models::OrderDetails, Error<GetOrderError>> {
330 let GetOrderParams { order_id } = params;
331
332 let local_var_configuration = &self.configuration;
333
334 let local_var_client = &local_var_configuration.client;
335
336 let local_var_uri_str = format!(
337 "{}/trading/orders/{orderId}",
338 local_var_configuration.base_path,
339 orderId = crate::apis::urlencode(order_id)
340 );
341 let mut local_var_req_builder =
342 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
343
344 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
345 local_var_req_builder = local_var_req_builder
346 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
347 }
348
349 let local_var_req = local_var_req_builder.build()?;
350 let local_var_resp = local_var_client.execute(local_var_req).await?;
351
352 let local_var_status = local_var_resp.status();
353 let local_var_content_type = local_var_resp
354 .headers()
355 .get("content-type")
356 .and_then(|v| v.to_str().ok())
357 .unwrap_or("application/octet-stream");
358 let local_var_content_type = super::ContentType::from(local_var_content_type);
359 let local_var_content = local_var_resp.text().await?;
360
361 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
362 match local_var_content_type {
363 ContentType::Json => {
364 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
365 }
366 ContentType::Text => {
367 return Err(Error::from(serde_json::Error::custom(
368 "Received `text/plain` content type response that cannot be converted to \
369 `models::OrderDetails`",
370 )));
371 }
372 ContentType::Unsupported(local_var_unknown_type) => {
373 return Err(Error::from(serde_json::Error::custom(format!(
374 "Received `{local_var_unknown_type}` content type response that cannot be \
375 converted to `models::OrderDetails`"
376 ))));
377 }
378 }
379 } else {
380 let local_var_entity: Option<GetOrderError> =
381 serde_json::from_str(&local_var_content).ok();
382 let local_var_error = ResponseContent {
383 status: local_var_status,
384 content: local_var_content,
385 entity: local_var_entity,
386 };
387 Err(Error::ResponseError(local_var_error))
388 }
389 }
390
391 async fn get_orders(
399 &self,
400 params: GetOrdersParams,
401 ) -> Result<models::GetOrdersResponse, Error<GetOrdersError>> {
402 let GetOrdersParams {
403 page_size,
404 page_cursor,
405 order,
406 account_id,
407 provider_id,
408 statuses,
409 start_time,
410 end_time,
411 asset_conversion_type,
412 } = params;
413
414 let local_var_configuration = &self.configuration;
415
416 let local_var_client = &local_var_configuration.client;
417
418 let local_var_uri_str = format!("{}/trading/orders", local_var_configuration.base_path);
419 let mut local_var_req_builder =
420 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
421
422 local_var_req_builder =
423 local_var_req_builder.query(&[("pageSize", &page_size.to_string())]);
424 if let Some(ref param_value) = page_cursor {
425 local_var_req_builder =
426 local_var_req_builder.query(&[("pageCursor", ¶m_value.to_string())]);
427 }
428 if let Some(ref param_value) = order {
429 local_var_req_builder =
430 local_var_req_builder.query(&[("order", ¶m_value.to_string())]);
431 }
432 if let Some(ref param_value) = account_id {
433 local_var_req_builder = match "multi" {
434 "multi" => local_var_req_builder.query(
435 ¶m_value
436 .into_iter()
437 .map(|p| ("accountId".to_owned(), p.to_string()))
438 .collect::<Vec<(std::string::String, std::string::String)>>(),
439 ),
440 _ => local_var_req_builder.query(&[(
441 "accountId",
442 ¶m_value
443 .into_iter()
444 .map(|p| p.to_string())
445 .collect::<Vec<String>>()
446 .join(",")
447 .to_string(),
448 )]),
449 };
450 }
451 if let Some(ref param_value) = provider_id {
452 local_var_req_builder = match "multi" {
453 "multi" => local_var_req_builder.query(
454 ¶m_value
455 .into_iter()
456 .map(|p| ("providerId".to_owned(), p.to_string()))
457 .collect::<Vec<(std::string::String, std::string::String)>>(),
458 ),
459 _ => local_var_req_builder.query(&[(
460 "providerId",
461 ¶m_value
462 .into_iter()
463 .map(|p| p.to_string())
464 .collect::<Vec<String>>()
465 .join(",")
466 .to_string(),
467 )]),
468 };
469 }
470 if let Some(ref param_value) = statuses {
471 local_var_req_builder = match "multi" {
472 "multi" => local_var_req_builder.query(
473 ¶m_value
474 .into_iter()
475 .map(|p| ("statuses".to_owned(), p.to_string()))
476 .collect::<Vec<(std::string::String, std::string::String)>>(),
477 ),
478 _ => local_var_req_builder.query(&[(
479 "statuses",
480 ¶m_value
481 .into_iter()
482 .map(|p| p.to_string())
483 .collect::<Vec<String>>()
484 .join(",")
485 .to_string(),
486 )]),
487 };
488 }
489 if let Some(ref param_value) = start_time {
490 local_var_req_builder =
491 local_var_req_builder.query(&[("startTime", ¶m_value.to_string())]);
492 }
493 if let Some(ref param_value) = end_time {
494 local_var_req_builder =
495 local_var_req_builder.query(&[("endTime", ¶m_value.to_string())]);
496 }
497 if let Some(ref param_value) = asset_conversion_type {
498 local_var_req_builder =
499 local_var_req_builder.query(&[("assetConversionType", ¶m_value.to_string())]);
500 }
501 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
502 local_var_req_builder = local_var_req_builder
503 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
504 }
505
506 let local_var_req = local_var_req_builder.build()?;
507 let local_var_resp = local_var_client.execute(local_var_req).await?;
508
509 let local_var_status = local_var_resp.status();
510 let local_var_content_type = local_var_resp
511 .headers()
512 .get("content-type")
513 .and_then(|v| v.to_str().ok())
514 .unwrap_or("application/octet-stream");
515 let local_var_content_type = super::ContentType::from(local_var_content_type);
516 let local_var_content = local_var_resp.text().await?;
517
518 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
519 match local_var_content_type {
520 ContentType::Json => {
521 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
522 }
523 ContentType::Text => {
524 return Err(Error::from(serde_json::Error::custom(
525 "Received `text/plain` content type response that cannot be converted to \
526 `models::GetOrdersResponse`",
527 )));
528 }
529 ContentType::Unsupported(local_var_unknown_type) => {
530 return Err(Error::from(serde_json::Error::custom(format!(
531 "Received `{local_var_unknown_type}` content type response that cannot be \
532 converted to `models::GetOrdersResponse`"
533 ))));
534 }
535 }
536 } else {
537 let local_var_entity: Option<GetOrdersError> =
538 serde_json::from_str(&local_var_content).ok();
539 let local_var_error = ResponseContent {
540 status: local_var_status,
541 content: local_var_content,
542 entity: local_var_entity,
543 };
544 Err(Error::ResponseError(local_var_error))
545 }
546 }
547
548 async fn get_trading_providers(
556 &self,
557 params: GetTradingProvidersParams,
558 ) -> Result<models::ProvidersListResponse, Error<GetTradingProvidersError>> {
559 let GetTradingProvidersParams {
560 page_size,
561 page_cursor,
562 } = params;
563
564 let local_var_configuration = &self.configuration;
565
566 let local_var_client = &local_var_configuration.client;
567
568 let local_var_uri_str = format!("{}/trading/providers", local_var_configuration.base_path);
569 let mut local_var_req_builder =
570 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
571
572 if let Some(ref param_value) = page_size {
573 local_var_req_builder =
574 local_var_req_builder.query(&[("pageSize", ¶m_value.to_string())]);
575 }
576 if let Some(ref param_value) = page_cursor {
577 local_var_req_builder =
578 local_var_req_builder.query(&[("pageCursor", ¶m_value.to_string())]);
579 }
580 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
581 local_var_req_builder = local_var_req_builder
582 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
583 }
584
585 let local_var_req = local_var_req_builder.build()?;
586 let local_var_resp = local_var_client.execute(local_var_req).await?;
587
588 let local_var_status = local_var_resp.status();
589 let local_var_content_type = local_var_resp
590 .headers()
591 .get("content-type")
592 .and_then(|v| v.to_str().ok())
593 .unwrap_or("application/octet-stream");
594 let local_var_content_type = super::ContentType::from(local_var_content_type);
595 let local_var_content = local_var_resp.text().await?;
596
597 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
598 match local_var_content_type {
599 ContentType::Json => {
600 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
601 }
602 ContentType::Text => {
603 return Err(Error::from(serde_json::Error::custom(
604 "Received `text/plain` content type response that cannot be converted to \
605 `models::ProvidersListResponse`",
606 )));
607 }
608 ContentType::Unsupported(local_var_unknown_type) => {
609 return Err(Error::from(serde_json::Error::custom(format!(
610 "Received `{local_var_unknown_type}` content type response that cannot be \
611 converted to `models::ProvidersListResponse`"
612 ))));
613 }
614 }
615 } else {
616 let local_var_entity: Option<GetTradingProvidersError> =
617 serde_json::from_str(&local_var_content).ok();
618 let local_var_error = ResponseContent {
619 status: local_var_status,
620 content: local_var_content,
621 entity: local_var_entity,
622 };
623 Err(Error::ResponseError(local_var_error))
624 }
625 }
626}
627
628#[derive(Debug, Clone, Serialize, Deserialize)]
630#[serde(untagged)]
631pub enum CreateOrderError {
632 Status404(models::TradingErrorResponse),
633 Status401(models::TradingErrorResponse),
634 Status5XX(models::TradingErrorResponse),
635 UnknownValue(serde_json::Value),
636}
637
638#[derive(Debug, Clone, Serialize, Deserialize)]
640#[serde(untagged)]
641pub enum CreateQuoteError {
642 Status404(models::TradingErrorResponse),
643 Status401(models::TradingErrorResponse),
644 Status5XX(models::TradingErrorResponse),
645 UnknownValue(serde_json::Value),
646}
647
648#[derive(Debug, Clone, Serialize, Deserialize)]
650#[serde(untagged)]
651pub enum GetOrderError {
652 Status404(models::TradingErrorResponse),
653 Status401(models::TradingErrorResponse),
654 Status5XX(models::TradingErrorResponse),
655 UnknownValue(serde_json::Value),
656}
657
658#[derive(Debug, Clone, Serialize, Deserialize)]
660#[serde(untagged)]
661pub enum GetOrdersError {
662 Status404(models::TradingErrorResponse),
663 Status401(models::TradingErrorResponse),
664 Status5XX(models::TradingErrorResponse),
665 UnknownValue(serde_json::Value),
666}
667
668#[derive(Debug, Clone, Serialize, Deserialize)]
670#[serde(untagged)]
671pub enum GetTradingProvidersError {
672 Status401(models::TradingErrorResponse),
673 Status5XX(models::TradingErrorResponse),
674 UnknownValue(serde_json::Value),
675}