Skip to main content

dfns_sdk_rust/exchanges/
mod.rs

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