fireblocks_sdk/apis/
connected_accounts_beta_api.rs

1// Fireblocks API
2//
3// Fireblocks provides a suite of applications to manage digital asset operations and a complete development platform to build your business on the blockchain.  - Visit our website for more information: [Fireblocks Website](https://fireblocks.com) - Visit our developer docs: [Fireblocks DevPortal](https://developers.fireblocks.com)
4//
5// The version of the OpenAPI document: 1.8.0
6// Contact: developers@fireblocks.com
7// Generated by: https://openapi-generator.tech
8
9use {
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 ConnectedAccountsBetaApi: Send + Sync {
23    /// GET /connected_accounts/{accountId}
24    ///
25    /// Retrieve detailed information about a specific connected account by ID.
26    /// **Note:** This endpoint is currently in beta and might be subject to
27    /// changes.
28    async fn get_connected_account(
29        &self,
30        params: GetConnectedAccountParams,
31    ) -> Result<models::ConnectedSingleAccountResponse, Error<GetConnectedAccountError>>;
32
33    /// GET /connected_accounts/{accountId}/balances
34    ///
35    /// Retrieve current asset balances for a specific connected account as a
36    /// flat list (one row per `assetId`, `balanceType`).  **Note:** This
37    /// endpoint is currently in beta and might be subject to changes.
38    async fn get_connected_account_balances(
39        &self,
40        params: GetConnectedAccountBalancesParams,
41    ) -> Result<models::ConnectedAccountBalancesResponse, Error<GetConnectedAccountBalancesError>>;
42
43    /// GET /connected_accounts/{accountId}/rates
44    ///
45    /// Retrieve current exchange rates for converting between specific assets
46    /// in a connected account.  **Note:** This endpoint is currently in beta
47    /// and might be subject to changes.
48    async fn get_connected_account_rates(
49        &self,
50        params: GetConnectedAccountRatesParams,
51    ) -> Result<models::ConnectedAccountRateResponse, Error<GetConnectedAccountRatesError>>;
52
53    /// GET /connected_accounts/{accountId}/manifest/capabilities/trading/pairs
54    ///
55    /// Retrieve all asset trading pairs supported by a specific connected
56    /// account, including the pair type (`quote`, `market`, `onOffRamp`).
57    /// **Note:** This endpoint is currently in beta and might be subject to
58    /// changes.
59    async fn get_connected_account_trading_pairs(
60        &self,
61        params: GetConnectedAccountTradingPairsParams,
62    ) -> Result<
63        models::ConnectedAccountTradingPairsResponse,
64        Error<GetConnectedAccountTradingPairsError>,
65    >;
66
67    /// GET /connected_accounts
68    ///
69    /// Returns all connected accounts.  **Note:** This endpoint is currently in
70    /// beta and might be subject to changes.
71    async fn get_connected_accounts(
72        &self,
73        params: GetConnectedAccountsParams,
74    ) -> Result<models::ConnectedAccountsResponse, Error<GetConnectedAccountsError>>;
75}
76
77pub struct ConnectedAccountsBetaApiClient {
78    configuration: Arc<configuration::Configuration>,
79}
80
81impl ConnectedAccountsBetaApiClient {
82    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
83        Self { configuration }
84    }
85}
86
87/// struct for passing parameters to the method
88/// [`ConnectedAccountsBetaApi::get_connected_account`]
89#[derive(Clone, Debug)]
90#[cfg_attr(feature = "bon", derive(::bon::Builder))]
91pub struct GetConnectedAccountParams {
92    /// The ID of the account to fetch.
93    pub account_id: String,
94}
95
96/// struct for passing parameters to the method
97/// [`ConnectedAccountsBetaApi::get_connected_account_balances`]
98#[derive(Clone, Debug)]
99#[cfg_attr(feature = "bon", derive(::bon::Builder))]
100pub struct GetConnectedAccountBalancesParams {
101    /// The ID of the account to fetch balances for.
102    pub account_id: String,
103    /// Page size for pagination.
104    pub page_size: Option<u16>,
105    /// Page cursor for pagination.
106    pub page_cursor: Option<String>,
107}
108
109/// struct for passing parameters to the method
110/// [`ConnectedAccountsBetaApi::get_connected_account_rates`]
111#[derive(Clone, Debug)]
112#[cfg_attr(feature = "bon", derive(::bon::Builder))]
113pub struct GetConnectedAccountRatesParams {
114    /// The ID of the account to fetch rates for.
115    pub account_id: String,
116    /// The ID of the asset to fetch rates for.
117    pub base_asset_id: String,
118    /// The ID of the asset to get the rates nominally.
119    pub quote_asset_id: String,
120}
121
122/// struct for passing parameters to the method
123/// [`ConnectedAccountsBetaApi::get_connected_account_trading_pairs`]
124#[derive(Clone, Debug)]
125#[cfg_attr(feature = "bon", derive(::bon::Builder))]
126pub struct GetConnectedAccountTradingPairsParams {
127    /// The ID of the account to fetch supported pairs for.
128    pub account_id: String,
129    /// Page size for pagination.
130    pub page_size: Option<u8>,
131    /// Page cursor for pagination.
132    pub page_cursor: Option<String>,
133}
134
135/// struct for passing parameters to the method
136/// [`ConnectedAccountsBetaApi::get_connected_accounts`]
137#[derive(Clone, Debug)]
138#[cfg_attr(feature = "bon", derive(::bon::Builder))]
139pub struct GetConnectedAccountsParams {
140    /// Whether to include only main accounts in the response.
141    pub main_accounts: Option<bool>,
142    /// Page size for pagination.
143    pub page_size: Option<u8>,
144    /// Page cursor for pagination.
145    pub page_cursor: Option<String>,
146}
147
148#[async_trait]
149impl ConnectedAccountsBetaApi for ConnectedAccountsBetaApiClient {
150    /// Retrieve detailed information about a specific connected account by ID.
151    /// **Note:** This endpoint is currently in beta and might be subject to
152    /// changes.
153    async fn get_connected_account(
154        &self,
155        params: GetConnectedAccountParams,
156    ) -> Result<models::ConnectedSingleAccountResponse, Error<GetConnectedAccountError>> {
157        let GetConnectedAccountParams { account_id } = params;
158
159        let local_var_configuration = &self.configuration;
160
161        let local_var_client = &local_var_configuration.client;
162
163        let local_var_uri_str = format!(
164            "{}/connected_accounts/{accountId}",
165            local_var_configuration.base_path,
166            accountId = crate::apis::urlencode(account_id)
167        );
168        let mut local_var_req_builder =
169            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
170
171        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
172            local_var_req_builder = local_var_req_builder
173                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
174        }
175
176        let local_var_req = local_var_req_builder.build()?;
177        let local_var_resp = local_var_client.execute(local_var_req).await?;
178
179        let local_var_status = local_var_resp.status();
180        let local_var_content_type = local_var_resp
181            .headers()
182            .get("content-type")
183            .and_then(|v| v.to_str().ok())
184            .unwrap_or("application/octet-stream");
185        let local_var_content_type = super::ContentType::from(local_var_content_type);
186        let local_var_content = local_var_resp.text().await?;
187
188        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
189            match local_var_content_type {
190                ContentType::Json => {
191                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
192                }
193                ContentType::Text => {
194                    return Err(Error::from(serde_json::Error::custom(
195                        "Received `text/plain` content type response that cannot be converted to \
196                         `models::ConnectedSingleAccountResponse`",
197                    )));
198                }
199                ContentType::Unsupported(local_var_unknown_type) => {
200                    return Err(Error::from(serde_json::Error::custom(format!(
201                        "Received `{local_var_unknown_type}` content type response that cannot be \
202                         converted to `models::ConnectedSingleAccountResponse`"
203                    ))));
204                }
205            }
206        } else {
207            let local_var_entity: Option<GetConnectedAccountError> =
208                serde_json::from_str(&local_var_content).ok();
209            let local_var_error = ResponseContent {
210                status: local_var_status,
211                content: local_var_content,
212                entity: local_var_entity,
213            };
214            Err(Error::ResponseError(local_var_error))
215        }
216    }
217
218    /// Retrieve current asset balances for a specific connected account as a
219    /// flat list (one row per `assetId`, `balanceType`).  **Note:** This
220    /// endpoint is currently in beta and might be subject to changes.
221    async fn get_connected_account_balances(
222        &self,
223        params: GetConnectedAccountBalancesParams,
224    ) -> Result<models::ConnectedAccountBalancesResponse, Error<GetConnectedAccountBalancesError>>
225    {
226        let GetConnectedAccountBalancesParams {
227            account_id,
228            page_size,
229            page_cursor,
230        } = params;
231
232        let local_var_configuration = &self.configuration;
233
234        let local_var_client = &local_var_configuration.client;
235
236        let local_var_uri_str = format!(
237            "{}/connected_accounts/{accountId}/balances",
238            local_var_configuration.base_path,
239            accountId = crate::apis::urlencode(account_id)
240        );
241        let mut local_var_req_builder =
242            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
243
244        if let Some(ref param_value) = page_size {
245            local_var_req_builder =
246                local_var_req_builder.query(&[("pageSize", &param_value.to_string())]);
247        }
248        if let Some(ref param_value) = page_cursor {
249            local_var_req_builder =
250                local_var_req_builder.query(&[("pageCursor", &param_value.to_string())]);
251        }
252        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
253            local_var_req_builder = local_var_req_builder
254                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
255        }
256
257        let local_var_req = local_var_req_builder.build()?;
258        let local_var_resp = local_var_client.execute(local_var_req).await?;
259
260        let local_var_status = local_var_resp.status();
261        let local_var_content_type = local_var_resp
262            .headers()
263            .get("content-type")
264            .and_then(|v| v.to_str().ok())
265            .unwrap_or("application/octet-stream");
266        let local_var_content_type = super::ContentType::from(local_var_content_type);
267        let local_var_content = local_var_resp.text().await?;
268
269        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
270            match local_var_content_type {
271                ContentType::Json => {
272                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
273                }
274                ContentType::Text => {
275                    return Err(Error::from(serde_json::Error::custom(
276                        "Received `text/plain` content type response that cannot be converted to \
277                         `models::ConnectedAccountBalancesResponse`",
278                    )));
279                }
280                ContentType::Unsupported(local_var_unknown_type) => {
281                    return Err(Error::from(serde_json::Error::custom(format!(
282                        "Received `{local_var_unknown_type}` content type response that cannot be \
283                         converted to `models::ConnectedAccountBalancesResponse`"
284                    ))));
285                }
286            }
287        } else {
288            let local_var_entity: Option<GetConnectedAccountBalancesError> =
289                serde_json::from_str(&local_var_content).ok();
290            let local_var_error = ResponseContent {
291                status: local_var_status,
292                content: local_var_content,
293                entity: local_var_entity,
294            };
295            Err(Error::ResponseError(local_var_error))
296        }
297    }
298
299    /// Retrieve current exchange rates for converting between specific assets
300    /// in a connected account.  **Note:** This endpoint is currently in beta
301    /// and might be subject to changes.
302    async fn get_connected_account_rates(
303        &self,
304        params: GetConnectedAccountRatesParams,
305    ) -> Result<models::ConnectedAccountRateResponse, Error<GetConnectedAccountRatesError>> {
306        let GetConnectedAccountRatesParams {
307            account_id,
308            base_asset_id,
309            quote_asset_id,
310        } = params;
311
312        let local_var_configuration = &self.configuration;
313
314        let local_var_client = &local_var_configuration.client;
315
316        let local_var_uri_str = format!(
317            "{}/connected_accounts/{accountId}/rates",
318            local_var_configuration.base_path,
319            accountId = crate::apis::urlencode(account_id)
320        );
321        let mut local_var_req_builder =
322            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
323
324        local_var_req_builder =
325            local_var_req_builder.query(&[("baseAssetId", &base_asset_id.to_string())]);
326        local_var_req_builder =
327            local_var_req_builder.query(&[("quoteAssetId", &quote_asset_id.to_string())]);
328        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
329            local_var_req_builder = local_var_req_builder
330                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
331        }
332
333        let local_var_req = local_var_req_builder.build()?;
334        let local_var_resp = local_var_client.execute(local_var_req).await?;
335
336        let local_var_status = local_var_resp.status();
337        let local_var_content_type = local_var_resp
338            .headers()
339            .get("content-type")
340            .and_then(|v| v.to_str().ok())
341            .unwrap_or("application/octet-stream");
342        let local_var_content_type = super::ContentType::from(local_var_content_type);
343        let local_var_content = local_var_resp.text().await?;
344
345        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
346            match local_var_content_type {
347                ContentType::Json => {
348                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
349                }
350                ContentType::Text => {
351                    return Err(Error::from(serde_json::Error::custom(
352                        "Received `text/plain` content type response that cannot be converted to \
353                         `models::ConnectedAccountRateResponse`",
354                    )));
355                }
356                ContentType::Unsupported(local_var_unknown_type) => {
357                    return Err(Error::from(serde_json::Error::custom(format!(
358                        "Received `{local_var_unknown_type}` content type response that cannot be \
359                         converted to `models::ConnectedAccountRateResponse`"
360                    ))));
361                }
362            }
363        } else {
364            let local_var_entity: Option<GetConnectedAccountRatesError> =
365                serde_json::from_str(&local_var_content).ok();
366            let local_var_error = ResponseContent {
367                status: local_var_status,
368                content: local_var_content,
369                entity: local_var_entity,
370            };
371            Err(Error::ResponseError(local_var_error))
372        }
373    }
374
375    /// Retrieve all asset trading pairs supported by a specific connected
376    /// account, including the pair type (`quote`, `market`, `onOffRamp`).
377    /// **Note:** This endpoint is currently in beta and might be subject to
378    /// changes.
379    async fn get_connected_account_trading_pairs(
380        &self,
381        params: GetConnectedAccountTradingPairsParams,
382    ) -> Result<
383        models::ConnectedAccountTradingPairsResponse,
384        Error<GetConnectedAccountTradingPairsError>,
385    > {
386        let GetConnectedAccountTradingPairsParams {
387            account_id,
388            page_size,
389            page_cursor,
390        } = params;
391
392        let local_var_configuration = &self.configuration;
393
394        let local_var_client = &local_var_configuration.client;
395
396        let local_var_uri_str = format!(
397            "{}/connected_accounts/{accountId}/manifest/capabilities/trading/pairs",
398            local_var_configuration.base_path,
399            accountId = crate::apis::urlencode(account_id)
400        );
401        let mut local_var_req_builder =
402            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
403
404        if let Some(ref param_value) = page_size {
405            local_var_req_builder =
406                local_var_req_builder.query(&[("pageSize", &param_value.to_string())]);
407        }
408        if let Some(ref param_value) = page_cursor {
409            local_var_req_builder =
410                local_var_req_builder.query(&[("pageCursor", &param_value.to_string())]);
411        }
412        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
413            local_var_req_builder = local_var_req_builder
414                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
415        }
416
417        let local_var_req = local_var_req_builder.build()?;
418        let local_var_resp = local_var_client.execute(local_var_req).await?;
419
420        let local_var_status = local_var_resp.status();
421        let local_var_content_type = local_var_resp
422            .headers()
423            .get("content-type")
424            .and_then(|v| v.to_str().ok())
425            .unwrap_or("application/octet-stream");
426        let local_var_content_type = super::ContentType::from(local_var_content_type);
427        let local_var_content = local_var_resp.text().await?;
428
429        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
430            match local_var_content_type {
431                ContentType::Json => {
432                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
433                }
434                ContentType::Text => {
435                    return Err(Error::from(serde_json::Error::custom(
436                        "Received `text/plain` content type response that cannot be converted to \
437                         `models::ConnectedAccountTradingPairsResponse`",
438                    )));
439                }
440                ContentType::Unsupported(local_var_unknown_type) => {
441                    return Err(Error::from(serde_json::Error::custom(format!(
442                        "Received `{local_var_unknown_type}` content type response that cannot be \
443                         converted to `models::ConnectedAccountTradingPairsResponse`"
444                    ))));
445                }
446            }
447        } else {
448            let local_var_entity: Option<GetConnectedAccountTradingPairsError> =
449                serde_json::from_str(&local_var_content).ok();
450            let local_var_error = ResponseContent {
451                status: local_var_status,
452                content: local_var_content,
453                entity: local_var_entity,
454            };
455            Err(Error::ResponseError(local_var_error))
456        }
457    }
458
459    /// Returns all connected accounts.  **Note:** This endpoint is currently in
460    /// beta and might be subject to changes.
461    async fn get_connected_accounts(
462        &self,
463        params: GetConnectedAccountsParams,
464    ) -> Result<models::ConnectedAccountsResponse, Error<GetConnectedAccountsError>> {
465        let GetConnectedAccountsParams {
466            main_accounts,
467            page_size,
468            page_cursor,
469        } = params;
470
471        let local_var_configuration = &self.configuration;
472
473        let local_var_client = &local_var_configuration.client;
474
475        let local_var_uri_str = format!("{}/connected_accounts", local_var_configuration.base_path);
476        let mut local_var_req_builder =
477            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
478
479        if let Some(ref param_value) = main_accounts {
480            local_var_req_builder =
481                local_var_req_builder.query(&[("mainAccounts", &param_value.to_string())]);
482        }
483        if let Some(ref param_value) = page_size {
484            local_var_req_builder =
485                local_var_req_builder.query(&[("pageSize", &param_value.to_string())]);
486        }
487        if let Some(ref param_value) = page_cursor {
488            local_var_req_builder =
489                local_var_req_builder.query(&[("pageCursor", &param_value.to_string())]);
490        }
491        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
492            local_var_req_builder = local_var_req_builder
493                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
494        }
495
496        let local_var_req = local_var_req_builder.build()?;
497        let local_var_resp = local_var_client.execute(local_var_req).await?;
498
499        let local_var_status = local_var_resp.status();
500        let local_var_content_type = local_var_resp
501            .headers()
502            .get("content-type")
503            .and_then(|v| v.to_str().ok())
504            .unwrap_or("application/octet-stream");
505        let local_var_content_type = super::ContentType::from(local_var_content_type);
506        let local_var_content = local_var_resp.text().await?;
507
508        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
509            match local_var_content_type {
510                ContentType::Json => {
511                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
512                }
513                ContentType::Text => {
514                    return Err(Error::from(serde_json::Error::custom(
515                        "Received `text/plain` content type response that cannot be converted to \
516                         `models::ConnectedAccountsResponse`",
517                    )));
518                }
519                ContentType::Unsupported(local_var_unknown_type) => {
520                    return Err(Error::from(serde_json::Error::custom(format!(
521                        "Received `{local_var_unknown_type}` content type response that cannot be \
522                         converted to `models::ConnectedAccountsResponse`"
523                    ))));
524                }
525            }
526        } else {
527            let local_var_entity: Option<GetConnectedAccountsError> =
528                serde_json::from_str(&local_var_content).ok();
529            let local_var_error = ResponseContent {
530                status: local_var_status,
531                content: local_var_content,
532                entity: local_var_entity,
533            };
534            Err(Error::ResponseError(local_var_error))
535        }
536    }
537}
538
539/// struct for typed errors of method
540/// [`ConnectedAccountsBetaApi::get_connected_account`]
541#[derive(Debug, Clone, Serialize, Deserialize)]
542#[serde(untagged)]
543pub enum GetConnectedAccountError {
544    DefaultResponse(models::ErrorSchema),
545    UnknownValue(serde_json::Value),
546}
547
548/// struct for typed errors of method
549/// [`ConnectedAccountsBetaApi::get_connected_account_balances`]
550#[derive(Debug, Clone, Serialize, Deserialize)]
551#[serde(untagged)]
552pub enum GetConnectedAccountBalancesError {
553    DefaultResponse(models::ErrorSchema),
554    UnknownValue(serde_json::Value),
555}
556
557/// struct for typed errors of method
558/// [`ConnectedAccountsBetaApi::get_connected_account_rates`]
559#[derive(Debug, Clone, Serialize, Deserialize)]
560#[serde(untagged)]
561pub enum GetConnectedAccountRatesError {
562    DefaultResponse(models::ErrorSchema),
563    UnknownValue(serde_json::Value),
564}
565
566/// struct for typed errors of method
567/// [`ConnectedAccountsBetaApi::get_connected_account_trading_pairs`]
568#[derive(Debug, Clone, Serialize, Deserialize)]
569#[serde(untagged)]
570pub enum GetConnectedAccountTradingPairsError {
571    DefaultResponse(models::ErrorSchema),
572    UnknownValue(serde_json::Value),
573}
574
575/// struct for typed errors of method
576/// [`ConnectedAccountsBetaApi::get_connected_accounts`]
577#[derive(Debug, Clone, Serialize, Deserialize)]
578#[serde(untagged)]
579pub enum GetConnectedAccountsError {
580    DefaultResponse(models::ErrorSchema),
581    UnknownValue(serde_json::Value),
582}