dfns_sdk_rust/exchanges/
mod.rs1pub mod delegated;
4pub mod types;
5
6#[allow(unused_imports)]
7use types::*;
8
9#[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 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 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 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 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 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 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 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 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 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}