Skip to main content

dfns_sdk_rust/exchanges/
mod.rs

1// Code generated by rust-sdk-generator. DO NOT EDIT.
2
3pub mod types;
4
5#[allow(unused_imports)]
6use types::*;
7
8/// Client for exchanges operations.
9#[derive(Clone)]
10pub struct ExchangesClient {
11    client: crate::client::Client,
12}
13
14impl ExchangesClient {
15    pub fn new(client: crate::client::Client) -> Self {
16        ExchangesClient { client }
17    }
18
19    /// Retrieve the details of a specific exchange integration configuration.
20    pub async fn get_exchange(
21        &self,
22        exchange_id: String,
23    ) -> Result<GetExchangeResponse, crate::error::Error> {
24        let path = format!("/exchanges/{}", urlencoding::encode(&exchange_id));
25        self.client
26            .request::<GetExchangeResponse>(reqwest::Method::GET, &path, None, false)
27            .await
28    }
29
30    /// Delete the exchange configuration from your organization.
31    pub async fn delete_exchange(
32        &self,
33        exchange_id: String,
34    ) -> Result<DeleteExchangeResponse, crate::error::Error> {
35        let path = format!("/exchanges/{}", urlencoding::encode(&exchange_id));
36        self.client
37            .request::<DeleteExchangeResponse>(reqwest::Method::DELETE, &path, None, true)
38            .await
39    }
40
41    /// List all configured exchange integrations.
42    pub async fn list_exchanges(
43        &self,
44        query: Option<ListExchangesQuery>,
45    ) -> Result<ListExchangesResponse, crate::error::Error> {
46        let mut path = String::from("/exchanges");
47        if let Some(query) = &query {
48            let mut q: Vec<String> = Vec::new();
49            if let Some(v) = &query.limit {
50                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
51            }
52            if let Some(v) = &query.pagination_token {
53                q.push(format!(
54                    "paginationToken={}",
55                    urlencoding::encode(&v.to_string())
56                ));
57            }
58            if !q.is_empty() {
59                path.push('?');
60                path.push_str(&q.join("&"));
61            }
62        }
63        self.client
64            .request::<ListExchangesResponse>(reqwest::Method::GET, &path, None, false)
65            .await
66    }
67
68    /// Link your organization with a cryptocurrency exchange.
69    pub async fn create_exchange(
70        &self,
71        body: CreateExchangeRequest,
72    ) -> Result<CreateExchangeResponse, crate::error::Error> {
73        let path = String::from("/exchanges");
74        let body = serde_json::to_value(&body)?;
75        self.client
76            .request::<CreateExchangeResponse>(reqwest::Method::POST, &path, Some(&body), true)
77            .await
78    }
79
80    /// Get a list of accounts for a specific exchange.
81    pub async fn list_accounts(
82        &self,
83        exchange_id: String,
84        query: Option<ListAccountsQuery>,
85    ) -> Result<ListAccountsResponse, crate::error::Error> {
86        let mut path = format!("/exchanges/{}/accounts", urlencoding::encode(&exchange_id));
87        if let Some(query) = &query {
88            let mut q: Vec<String> = Vec::new();
89            if let Some(v) = &query.limit {
90                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
91            }
92            if let Some(v) = &query.pagination_token {
93                q.push(format!(
94                    "paginationToken={}",
95                    urlencoding::encode(&v.to_string())
96                ));
97            }
98            if !q.is_empty() {
99                path.push('?');
100                path.push_str(&q.join("&"));
101            }
102        }
103        self.client
104            .request::<ListAccountsResponse>(reqwest::Method::GET, &path, None, false)
105            .await
106    }
107
108    /// Retrieve the list of assets for a specific account on a specific exchange.
109    pub async fn list_account_assets(
110        &self,
111        exchange_id: String,
112        account_id: String,
113        query: Option<ListAccountAssetsQuery>,
114    ) -> Result<ListAccountAssetsResponse, crate::error::Error> {
115        let mut path = format!(
116            "/exchanges/{}/accounts/{}/assets",
117            urlencoding::encode(&exchange_id),
118            urlencoding::encode(&account_id)
119        );
120        if let Some(query) = &query {
121            let mut q: Vec<String> = Vec::new();
122            if let Some(v) = &query.limit {
123                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
124            }
125            if let Some(v) = &query.pagination_token {
126                q.push(format!(
127                    "paginationToken={}",
128                    urlencoding::encode(&v.to_string())
129                ));
130            }
131            if !q.is_empty() {
132                path.push('?');
133                path.push_str(&q.join("&"));
134            }
135        }
136        self.client
137            .request::<ListAccountAssetsResponse>(reqwest::Method::GET, &path, None, false)
138            .await
139    }
140
141    /// Lists the networks to which the given asset can be withdrawn from an exchange account.
142    pub async fn list_asset_withdrawal_networks(
143        &self,
144        exchange_id: String,
145        account_id: String,
146        asset: String,
147    ) -> Result<serde_json::Value, crate::error::Error> {
148        let path = format!(
149            "/exchanges/{}/accounts/{}/assets/{}/withdrawal-networks",
150            urlencoding::encode(&exchange_id),
151            urlencoding::encode(&account_id),
152            urlencoding::encode(&asset)
153        );
154        self.client
155            .request::<serde_json::Value>(reqwest::Method::GET, &path, None, false)
156            .await
157    }
158
159    /// Creates a new exchange deposit transaction.
160    pub async fn create_exchange_deposit(
161        &self,
162        exchange_id: String,
163        account_id: String,
164        body: CreateExchangeDepositRequest,
165    ) -> Result<CreateExchangeDepositResponse, crate::error::Error> {
166        let path = format!(
167            "/exchanges/{}/accounts/{}/deposits",
168            urlencoding::encode(&exchange_id),
169            urlencoding::encode(&account_id)
170        );
171        let body = serde_json::to_value(&body)?;
172        self.client
173            .request::<CreateExchangeDepositResponse>(
174                reqwest::Method::POST,
175                &path,
176                Some(&body),
177                true,
178            )
179            .await
180    }
181
182    /// Creates a new exchange withdrawal transaction.
183    pub async fn create_exchange_withdrawal(
184        &self,
185        exchange_id: String,
186        account_id: String,
187        body: CreateExchangeWithdrawalRequest,
188    ) -> Result<CreateExchangeWithdrawalResponse, crate::error::Error> {
189        let path = format!(
190            "/exchanges/{}/accounts/{}/withdrawals",
191            urlencoding::encode(&exchange_id),
192            urlencoding::encode(&account_id)
193        );
194        let body = serde_json::to_value(&body)?;
195        self.client
196            .request::<CreateExchangeWithdrawalResponse>(
197                reqwest::Method::POST,
198                &path,
199                Some(&body),
200                true,
201            )
202            .await
203    }
204}