fireblocks_sdk/apis/
off_exchange_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 OffExchangeApi: Send + Sync {
23    /// POST /off_exchange/add
24    ///
25    /// Add collateral and create deposit request. Learn more about Fireblocks Off Exchange in the following [guide](https://developers.fireblocks.com/docs/off-exchange). </br>Endpoint Permission: Admin, Non-Signing Admin, Signer, Approver, Editor.
26    async fn add_off_exchange(
27        &self,
28        params: AddOffExchangeParams,
29    ) -> Result<models::CreateTransactionResponse, Error<AddOffExchangeError>>;
30
31    /// GET /off_exchange/collateral_accounts/{mainExchangeAccountId}
32    ///
33    /// Returns a collateral account by mainExchangeAccountId. </br>Endpoint
34    /// Permission: Admin, Non-Signing Admin, Signer, Approver, Editor.
35    async fn get_off_exchange_collateral_accounts(
36        &self,
37        params: GetOffExchangeCollateralAccountsParams,
38    ) -> Result<models::ExchangeAccount, Error<GetOffExchangeCollateralAccountsError>>;
39
40    /// GET /off_exchange/settlements/transactions
41    ///
42    /// Get settlements transactions from exchange. </br>Endpoint Permission:
43    /// Admin, Non-Signing Admin, Signer, Approver, Editor.
44    async fn get_off_exchange_settlement_transactions(
45        &self,
46        params: GetOffExchangeSettlementTransactionsParams,
47    ) -> Result<
48        models::ExchangeSettlementTransactionsResponse,
49        Error<GetOffExchangeSettlementTransactionsError>,
50    >;
51
52    /// POST /off_exchange/remove
53    ///
54    /// Remove collateral and create withdraw request. </br>Endpoint Permission:
55    /// Admin, Non-Signing Admin, Signer, Approver, Editor.
56    async fn remove_off_exchange(
57        &self,
58        params: RemoveOffExchangeParams,
59    ) -> Result<models::CreateTransactionResponse, Error<RemoveOffExchangeError>>;
60
61    /// POST /off_exchange/settlements/trader
62    ///
63    /// Create settlement for a trader. Learn more about Fireblocks Off Exchange in the following [guide](https://developers.fireblocks.com/docs/off-exchange). </br>Endpoint Permission: Admin, Non-Signing Admin, Signer, Approver, Editor.
64    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/// struct for passing parameters to the method
81/// [`OffExchangeApi::add_off_exchange`]
82#[derive(Clone, Debug)]
83#[cfg_attr(feature = "bon", derive(::bon::Builder))]
84pub struct AddOffExchangeParams {
85    /// A unique identifier for the request. If the request is sent multiple
86    /// times with the same idempotency key, the server will return the same
87    /// response as the first request. The idempotency key is valid for 24
88    /// hours.
89    pub idempotency_key: Option<String>,
90    pub add_collateral_request_body: Option<models::AddCollateralRequestBody>,
91}
92
93/// struct for passing parameters to the method
94/// [`OffExchangeApi::get_off_exchange_collateral_accounts`]
95#[derive(Clone, Debug)]
96#[cfg_attr(feature = "bon", derive(::bon::Builder))]
97pub struct GetOffExchangeCollateralAccountsParams {
98    /// The id of the main exchange account for which the requested collateral
99    /// account is associated with
100    pub main_exchange_account_id: String,
101}
102
103/// struct for passing parameters to the method
104/// [`OffExchangeApi::get_off_exchange_settlement_transactions`]
105#[derive(Clone, Debug)]
106#[cfg_attr(feature = "bon", derive(::bon::Builder))]
107pub struct GetOffExchangeSettlementTransactionsParams {
108    pub main_exchange_account_id: String,
109}
110
111/// struct for passing parameters to the method
112/// [`OffExchangeApi::remove_off_exchange`]
113#[derive(Clone, Debug)]
114#[cfg_attr(feature = "bon", derive(::bon::Builder))]
115pub struct RemoveOffExchangeParams {
116    /// A unique identifier for the request. If the request is sent multiple
117    /// times with the same idempotency key, the server will return the same
118    /// response as the first request. The idempotency key is valid for 24
119    /// hours.
120    pub idempotency_key: Option<String>,
121    pub remove_collateral_request_body: Option<models::RemoveCollateralRequestBody>,
122}
123
124/// struct for passing parameters to the method
125/// [`OffExchangeApi::settle_off_exchange_trades`]
126#[derive(Clone, Debug)]
127#[cfg_attr(feature = "bon", derive(::bon::Builder))]
128pub struct SettleOffExchangeTradesParams {
129    /// A unique identifier for the request. If the request is sent multiple
130    /// times with the same idempotency key, the server will return the same
131    /// response as the first request. The idempotency key is valid for 24
132    /// hours.
133    pub idempotency_key: Option<String>,
134    pub settlement_request_body: Option<models::SettlementRequestBody>,
135}
136
137#[async_trait]
138impl OffExchangeApi for OffExchangeApiClient {
139    /// Add collateral and create deposit request. Learn more about Fireblocks Off Exchange in the following [guide](https://developers.fireblocks.com/docs/off-exchange). </br>Endpoint Permission: Admin, Non-Signing Admin, Signer, Approver, Editor.
140    async fn add_off_exchange(
141        &self,
142        params: AddOffExchangeParams,
143    ) -> Result<models::CreateTransactionResponse, Error<AddOffExchangeError>> {
144        let AddOffExchangeParams {
145            idempotency_key,
146            add_collateral_request_body,
147        } = params;
148
149        let local_var_configuration = &self.configuration;
150
151        let local_var_client = &local_var_configuration.client;
152
153        let local_var_uri_str = format!("{}/off_exchange/add", local_var_configuration.base_path);
154        let mut local_var_req_builder =
155            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
156
157        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
158            local_var_req_builder = local_var_req_builder
159                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
160        }
161        if let Some(local_var_param_value) = idempotency_key {
162            local_var_req_builder =
163                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
164        }
165        local_var_req_builder = local_var_req_builder.json(&add_collateral_request_body);
166
167        let local_var_req = local_var_req_builder.build()?;
168        let local_var_resp = local_var_client.execute(local_var_req).await?;
169
170        let local_var_status = local_var_resp.status();
171        let local_var_content_type = local_var_resp
172            .headers()
173            .get("content-type")
174            .and_then(|v| v.to_str().ok())
175            .unwrap_or("application/octet-stream");
176        let local_var_content_type = super::ContentType::from(local_var_content_type);
177        let local_var_content = local_var_resp.text().await?;
178
179        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
180            match local_var_content_type {
181                ContentType::Json => {
182                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
183                }
184                ContentType::Text => {
185                    return Err(Error::from(serde_json::Error::custom(
186                        "Received `text/plain` content type response that cannot be converted to \
187                         `models::CreateTransactionResponse`",
188                    )));
189                }
190                ContentType::Unsupported(local_var_unknown_type) => {
191                    return Err(Error::from(serde_json::Error::custom(format!(
192                        "Received `{local_var_unknown_type}` content type response that cannot be \
193                         converted to `models::CreateTransactionResponse`"
194                    ))));
195                }
196            }
197        } else {
198            let local_var_entity: Option<AddOffExchangeError> =
199                serde_json::from_str(&local_var_content).ok();
200            let local_var_error = ResponseContent {
201                status: local_var_status,
202                content: local_var_content,
203                entity: local_var_entity,
204            };
205            Err(Error::ResponseError(local_var_error))
206        }
207    }
208
209    /// Returns a collateral account by mainExchangeAccountId. </br>Endpoint
210    /// Permission: Admin, Non-Signing Admin, Signer, Approver, Editor.
211    async fn get_off_exchange_collateral_accounts(
212        &self,
213        params: GetOffExchangeCollateralAccountsParams,
214    ) -> Result<models::ExchangeAccount, Error<GetOffExchangeCollateralAccountsError>> {
215        let GetOffExchangeCollateralAccountsParams {
216            main_exchange_account_id,
217        } = params;
218
219        let local_var_configuration = &self.configuration;
220
221        let local_var_client = &local_var_configuration.client;
222
223        let local_var_uri_str = format!(
224            "{}/off_exchange/collateral_accounts/{mainExchangeAccountId}",
225            local_var_configuration.base_path,
226            mainExchangeAccountId = crate::apis::urlencode(main_exchange_account_id)
227        );
228        let mut local_var_req_builder =
229            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
230
231        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
232            local_var_req_builder = local_var_req_builder
233                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
234        }
235
236        let local_var_req = local_var_req_builder.build()?;
237        let local_var_resp = local_var_client.execute(local_var_req).await?;
238
239        let local_var_status = local_var_resp.status();
240        let local_var_content_type = local_var_resp
241            .headers()
242            .get("content-type")
243            .and_then(|v| v.to_str().ok())
244            .unwrap_or("application/octet-stream");
245        let local_var_content_type = super::ContentType::from(local_var_content_type);
246        let local_var_content = local_var_resp.text().await?;
247
248        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
249            match local_var_content_type {
250                ContentType::Json => {
251                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
252                }
253                ContentType::Text => {
254                    return Err(Error::from(serde_json::Error::custom(
255                        "Received `text/plain` content type response that cannot be converted to \
256                         `models::ExchangeAccount`",
257                    )));
258                }
259                ContentType::Unsupported(local_var_unknown_type) => {
260                    return Err(Error::from(serde_json::Error::custom(format!(
261                        "Received `{local_var_unknown_type}` content type response that cannot be \
262                         converted to `models::ExchangeAccount`"
263                    ))));
264                }
265            }
266        } else {
267            let local_var_entity: Option<GetOffExchangeCollateralAccountsError> =
268                serde_json::from_str(&local_var_content).ok();
269            let local_var_error = ResponseContent {
270                status: local_var_status,
271                content: local_var_content,
272                entity: local_var_entity,
273            };
274            Err(Error::ResponseError(local_var_error))
275        }
276    }
277
278    /// Get settlements transactions from exchange. </br>Endpoint Permission:
279    /// Admin, Non-Signing Admin, Signer, Approver, Editor.
280    async fn get_off_exchange_settlement_transactions(
281        &self,
282        params: GetOffExchangeSettlementTransactionsParams,
283    ) -> Result<
284        models::ExchangeSettlementTransactionsResponse,
285        Error<GetOffExchangeSettlementTransactionsError>,
286    > {
287        let GetOffExchangeSettlementTransactionsParams {
288            main_exchange_account_id,
289        } = params;
290
291        let local_var_configuration = &self.configuration;
292
293        let local_var_client = &local_var_configuration.client;
294
295        let local_var_uri_str = format!(
296            "{}/off_exchange/settlements/transactions",
297            local_var_configuration.base_path
298        );
299        let mut local_var_req_builder =
300            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
301
302        local_var_req_builder = local_var_req_builder.query(&[(
303            "mainExchangeAccountId",
304            &main_exchange_account_id.to_string(),
305        )]);
306        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
307            local_var_req_builder = local_var_req_builder
308                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
309        }
310
311        let local_var_req = local_var_req_builder.build()?;
312        let local_var_resp = local_var_client.execute(local_var_req).await?;
313
314        let local_var_status = local_var_resp.status();
315        let local_var_content_type = local_var_resp
316            .headers()
317            .get("content-type")
318            .and_then(|v| v.to_str().ok())
319            .unwrap_or("application/octet-stream");
320        let local_var_content_type = super::ContentType::from(local_var_content_type);
321        let local_var_content = local_var_resp.text().await?;
322
323        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
324            match local_var_content_type {
325                ContentType::Json => {
326                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
327                }
328                ContentType::Text => {
329                    return Err(Error::from(serde_json::Error::custom(
330                        "Received `text/plain` content type response that cannot be converted to \
331                         `models::ExchangeSettlementTransactionsResponse`",
332                    )));
333                }
334                ContentType::Unsupported(local_var_unknown_type) => {
335                    return Err(Error::from(serde_json::Error::custom(format!(
336                        "Received `{local_var_unknown_type}` content type response that cannot be \
337                         converted to `models::ExchangeSettlementTransactionsResponse`"
338                    ))));
339                }
340            }
341        } else {
342            let local_var_entity: Option<GetOffExchangeSettlementTransactionsError> =
343                serde_json::from_str(&local_var_content).ok();
344            let local_var_error = ResponseContent {
345                status: local_var_status,
346                content: local_var_content,
347                entity: local_var_entity,
348            };
349            Err(Error::ResponseError(local_var_error))
350        }
351    }
352
353    /// Remove collateral and create withdraw request. </br>Endpoint Permission:
354    /// Admin, Non-Signing Admin, Signer, Approver, Editor.
355    async fn remove_off_exchange(
356        &self,
357        params: RemoveOffExchangeParams,
358    ) -> Result<models::CreateTransactionResponse, Error<RemoveOffExchangeError>> {
359        let RemoveOffExchangeParams {
360            idempotency_key,
361            remove_collateral_request_body,
362        } = params;
363
364        let local_var_configuration = &self.configuration;
365
366        let local_var_client = &local_var_configuration.client;
367
368        let local_var_uri_str =
369            format!("{}/off_exchange/remove", local_var_configuration.base_path);
370        let mut local_var_req_builder =
371            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
372
373        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
374            local_var_req_builder = local_var_req_builder
375                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
376        }
377        if let Some(local_var_param_value) = idempotency_key {
378            local_var_req_builder =
379                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
380        }
381        local_var_req_builder = local_var_req_builder.json(&remove_collateral_request_body);
382
383        let local_var_req = local_var_req_builder.build()?;
384        let local_var_resp = local_var_client.execute(local_var_req).await?;
385
386        let local_var_status = local_var_resp.status();
387        let local_var_content_type = local_var_resp
388            .headers()
389            .get("content-type")
390            .and_then(|v| v.to_str().ok())
391            .unwrap_or("application/octet-stream");
392        let local_var_content_type = super::ContentType::from(local_var_content_type);
393        let local_var_content = local_var_resp.text().await?;
394
395        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
396            match local_var_content_type {
397                ContentType::Json => {
398                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
399                }
400                ContentType::Text => {
401                    return Err(Error::from(serde_json::Error::custom(
402                        "Received `text/plain` content type response that cannot be converted to \
403                         `models::CreateTransactionResponse`",
404                    )));
405                }
406                ContentType::Unsupported(local_var_unknown_type) => {
407                    return Err(Error::from(serde_json::Error::custom(format!(
408                        "Received `{local_var_unknown_type}` content type response that cannot be \
409                         converted to `models::CreateTransactionResponse`"
410                    ))));
411                }
412            }
413        } else {
414            let local_var_entity: Option<RemoveOffExchangeError> =
415                serde_json::from_str(&local_var_content).ok();
416            let local_var_error = ResponseContent {
417                status: local_var_status,
418                content: local_var_content,
419                entity: local_var_entity,
420            };
421            Err(Error::ResponseError(local_var_error))
422        }
423    }
424
425    /// Create settlement for a trader. Learn more about Fireblocks Off Exchange in the following [guide](https://developers.fireblocks.com/docs/off-exchange). </br>Endpoint Permission: Admin, Non-Signing Admin, Signer, Approver, Editor.
426    async fn settle_off_exchange_trades(
427        &self,
428        params: SettleOffExchangeTradesParams,
429    ) -> Result<models::SettlementResponse, Error<SettleOffExchangeTradesError>> {
430        let SettleOffExchangeTradesParams {
431            idempotency_key,
432            settlement_request_body,
433        } = params;
434
435        let local_var_configuration = &self.configuration;
436
437        let local_var_client = &local_var_configuration.client;
438
439        let local_var_uri_str = format!(
440            "{}/off_exchange/settlements/trader",
441            local_var_configuration.base_path
442        );
443        let mut local_var_req_builder =
444            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
445
446        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
447            local_var_req_builder = local_var_req_builder
448                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
449        }
450        if let Some(local_var_param_value) = idempotency_key {
451            local_var_req_builder =
452                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
453        }
454        local_var_req_builder = local_var_req_builder.json(&settlement_request_body);
455
456        let local_var_req = local_var_req_builder.build()?;
457        let local_var_resp = local_var_client.execute(local_var_req).await?;
458
459        let local_var_status = local_var_resp.status();
460        let local_var_content_type = local_var_resp
461            .headers()
462            .get("content-type")
463            .and_then(|v| v.to_str().ok())
464            .unwrap_or("application/octet-stream");
465        let local_var_content_type = super::ContentType::from(local_var_content_type);
466        let local_var_content = local_var_resp.text().await?;
467
468        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
469            match local_var_content_type {
470                ContentType::Json => {
471                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
472                }
473                ContentType::Text => {
474                    return Err(Error::from(serde_json::Error::custom(
475                        "Received `text/plain` content type response that cannot be converted to \
476                         `models::SettlementResponse`",
477                    )));
478                }
479                ContentType::Unsupported(local_var_unknown_type) => {
480                    return Err(Error::from(serde_json::Error::custom(format!(
481                        "Received `{local_var_unknown_type}` content type response that cannot be \
482                         converted to `models::SettlementResponse`"
483                    ))));
484                }
485            }
486        } else {
487            let local_var_entity: Option<SettleOffExchangeTradesError> =
488                serde_json::from_str(&local_var_content).ok();
489            let local_var_error = ResponseContent {
490                status: local_var_status,
491                content: local_var_content,
492                entity: local_var_entity,
493            };
494            Err(Error::ResponseError(local_var_error))
495        }
496    }
497}
498
499/// struct for typed errors of method [`OffExchangeApi::add_off_exchange`]
500#[derive(Debug, Clone, Serialize, Deserialize)]
501#[serde(untagged)]
502pub enum AddOffExchangeError {
503    DefaultResponse(models::ErrorSchema),
504    UnknownValue(serde_json::Value),
505}
506
507/// struct for typed errors of method
508/// [`OffExchangeApi::get_off_exchange_collateral_accounts`]
509#[derive(Debug, Clone, Serialize, Deserialize)]
510#[serde(untagged)]
511pub enum GetOffExchangeCollateralAccountsError {
512    DefaultResponse(models::ErrorSchema),
513    UnknownValue(serde_json::Value),
514}
515
516/// struct for typed errors of method
517/// [`OffExchangeApi::get_off_exchange_settlement_transactions`]
518#[derive(Debug, Clone, Serialize, Deserialize)]
519#[serde(untagged)]
520pub enum GetOffExchangeSettlementTransactionsError {
521    DefaultResponse(models::ErrorSchema),
522    UnknownValue(serde_json::Value),
523}
524
525/// struct for typed errors of method [`OffExchangeApi::remove_off_exchange`]
526#[derive(Debug, Clone, Serialize, Deserialize)]
527#[serde(untagged)]
528pub enum RemoveOffExchangeError {
529    DefaultResponse(models::ErrorSchema),
530    UnknownValue(serde_json::Value),
531}
532
533/// struct for typed errors of method
534/// [`OffExchangeApi::settle_off_exchange_trades`]
535#[derive(Debug, Clone, Serialize, Deserialize)]
536#[serde(untagged)]
537pub enum SettleOffExchangeTradesError {
538    DefaultResponse(models::ErrorSchema),
539    UnknownValue(serde_json::Value),
540}