Skip to content

Commit 8395fd0

Browse files
committed
wip
1 parent c543f29 commit 8395fd0

File tree

6 files changed

+146
-184
lines changed

6 files changed

+146
-184
lines changed

examples/cex-candle.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() {
3030

3131
// CEX Candle Data
3232
let candle_options = datamaxi::cex::CandleOptions::new();
33-
let candle_response = candle.get("binance", "ETH-USDT", candle_options);
33+
let candle_response = candle.get("binance", "spot", "ETH-USDT", candle_options);
3434
match candle_response {
3535
Ok(answer) => match serde_json::to_string(&answer) {
3636
Ok(json) => println!("{}", json),

examples/dex-candle.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ fn main() {
66
let candle: datamaxi::dex::Candle = datamaxi::api::Datamaxi::new(api_key);
77

88
// DEX Candle Intervals
9-
match candle.intervals() {
10-
Ok(answer) => println!("{:?}", answer),
11-
Err(e) => println!("Error: {}", e),
12-
}
9+
// match candle.intervals() {
10+
// Ok(answer) => println!("{:?}", answer),
11+
// Err(e) => println!("Error: {}", e),
12+
// }
1313

14-
// DEX Candle Exchanges
15-
match candle.exchanges() {
16-
Ok(answer) => println!("{:?}", answer),
17-
Err(e) => println!("Error: {}", e),
18-
}
14+
// // DEX Candle Exchanges
15+
// match candle.exchanges() {
16+
// Ok(answer) => println!("{:?}", answer),
17+
// Err(e) => println!("Error: {}", e),
18+
// }
1919

20-
// DEX Candle Chains
21-
match candle.chains() {
22-
Ok(answer) => println!("{:?}", answer),
23-
Err(e) => println!("Error: {}", e),
24-
}
20+
// // DEX Candle Chains
21+
// match candle.chains() {
22+
// Ok(answer) => println!("{:?}", answer),
23+
// Err(e) => println!("Error: {}", e),
24+
// }
2525

2626
// DEX Candle Pools
27-
let pools_options = datamaxi::dex::PoolsOptions::new();
28-
let pools_response = candle.pools(pools_options);
29-
match pools_response {
30-
Ok(answer) => match serde_json::to_string(&answer) {
31-
Ok(json) => println!("{}", json),
32-
Err(e) => println!("Error: {}", e),
33-
},
34-
Err(e) => println!("Error: {}", e),
35-
}
27+
// let pools_options = datamaxi::dex::PoolsOptions::new();
28+
// let pools_response = candle.pools(pools_options);
29+
// match pools_response {
30+
// Ok(answer) => match serde_json::to_string(&answer) {
31+
// Ok(json) => println!("{}", json),
32+
// Err(e) => println!("Error: {}", e),
33+
// },
34+
// Err(e) => println!("Error: {}", e),
35+
// }
3636

3737
// DEX Candle Data
3838
let params = datamaxi::dex::CandleOptions::new();

examples/dex-trade.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ fn main() {
66
let trade: datamaxi::dex::Trade = datamaxi::api::Datamaxi::new(api_key);
77

88
// DEX Trade Exchanges
9-
match trade.exchanges() {
10-
Ok(answer) => println!("{:?}", answer),
11-
Err(e) => println!("Error: {}", e),
12-
}
9+
// match trade.exchanges() {
10+
// Ok(answer) => println!("{:?}", answer),
11+
// Err(e) => println!("Error: {}", e),
12+
// }
1313

14-
// DEX Trade Chains
15-
match trade.chains() {
16-
Ok(answer) => println!("{:?}", answer),
17-
Err(e) => println!("Error: {}", e),
18-
}
14+
// // DEX Trade Chains
15+
// match trade.chains() {
16+
// Ok(answer) => println!("{:?}", answer),
17+
// Err(e) => println!("Error: {}", e),
18+
// }
1919

2020
// DEX Trade Pools
21-
let pools_options = datamaxi::dex::PoolsOptions::new();
22-
let pools_response = trade.pools(pools_options);
23-
match pools_response {
24-
Ok(answer) => match serde_json::to_string(&answer) {
25-
Ok(json) => println!("{}", json),
26-
Err(e) => println!("Error: {}", e),
27-
},
28-
Err(e) => println!("Error: {}", e),
29-
}
21+
// let pools_options = datamaxi::dex::PoolsOptions::new();
22+
// let pools_response = trade.pools(pools_options);
23+
// match pools_response {
24+
// Ok(answer) => match serde_json::to_string(&answer) {
25+
// Ok(json) => println!("{}", json),
26+
// Err(e) => println!("Error: {}", e),
27+
// },
28+
// Err(e) => println!("Error: {}", e),
29+
// }
3030

3131
// DEX Trade Data
3232
let trade_options = datamaxi::dex::TradeOptions::new().limit(5);

src/cex.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,35 @@ impl Candle {
1313
/// Retrieves candle data for a specified exchange and symbol. Additional parameters can be
1414
/// provided to filter and sort the results. The response will contain an array of candle data
1515
/// objects, each representing a single candle with open, high, low, close, and volume values.
16-
pub fn get<E, S>(
16+
pub fn get<E, M, S>(
1717
&self,
1818
exchange: E,
19+
market: M,
1920
symbol: S,
2021
options: CandleOptions,
2122
) -> Result<CandleResponse>
2223
where
2324
E: Into<String>,
25+
M: Into<String>,
2426
S: Into<String>,
2527
{
2628
let mut parameters = HashMap::new();
2729

2830
// required
2931
parameters.insert("exchange".to_string(), exchange.into());
32+
parameters.insert("market".to_string(), market.into());
3033
parameters.insert("symbol".to_string(), symbol.into());
3134

3235
// optional
3336
parameters.extend(
3437
[
35-
options
36-
.market
37-
.map(|market| ("market".to_string(), market.to_string())),
3838
options
3939
.interval
4040
.map(|interval| ("interval".to_string(), interval.to_string())),
41-
options
42-
.page
43-
.map(|page| ("page".to_string(), page.to_string())),
44-
options
45-
.limit
46-
.map(|limit| ("limit".to_string(), limit.to_string())),
4741
options
4842
.from
4943
.map(|from| ("from".to_string(), from.to_string())),
5044
options.to.map(|to| ("to".to_string(), to.to_string())),
51-
options
52-
.sort
53-
.map(|sort| ("sort".to_string(), sort.to_string())),
5445
]
5546
.into_iter()
5647
.flatten(),

src/dex.rs

+80-78
Original file line numberDiff line numberDiff line change
@@ -35,70 +35,20 @@ impl Candle {
3535
// optional
3636
parameters.extend(
3737
[
38-
options
39-
.market
40-
.map(|market| ("market".to_string(), market.to_string())),
4138
options
4239
.interval
4340
.map(|interval| ("interval".to_string(), interval.to_string())),
44-
options
45-
.page
46-
.map(|page| ("page".to_string(), page.to_string())),
47-
options
48-
.limit
49-
.map(|limit| ("limit".to_string(), limit.to_string())),
5041
options
5142
.from
5243
.map(|from| ("from".to_string(), from.to_string())),
5344
options.to.map(|to| ("to".to_string(), to.to_string())),
54-
options
55-
.sort
56-
.map(|sort| ("sort".to_string(), sort.to_string())),
5745
]
5846
.into_iter()
5947
.flatten(),
6048
);
6149

6250
self.client.get("/dex/candle", Some(parameters))
6351
}
64-
65-
/// Retrieves information about available pools, including details about the chain, exchange,
66-
/// base and quote symbols, and pool address. Optional parameters can be provided to filter the
67-
/// results by chain and exchange.
68-
pub fn pools(&self, options: PoolsOptions) -> Result<Vec<PoolsResponse>> {
69-
let mut parameters = HashMap::new();
70-
71-
// optional
72-
parameters.extend(
73-
[
74-
options
75-
.exchange
76-
.map(|exchange| ("exchange".to_string(), exchange.to_string())),
77-
options
78-
.chain
79-
.map(|chain| ("chain".to_string(), chain.to_string())),
80-
]
81-
.into_iter()
82-
.flatten(),
83-
);
84-
85-
self.client.get("/dex/candle/pools", Some(parameters))
86-
}
87-
88-
/// Retrieves a list of available chains for candle data.
89-
pub fn chains(&self) -> Result<Vec<String>> {
90-
self.client.get("/dex/candle/chains", None)
91-
}
92-
93-
/// Retrieves a list of available exchanges for candle data.
94-
pub fn exchanges(&self) -> Result<Vec<String>> {
95-
self.client.get("/dex/candle/exchanges", None)
96-
}
97-
98-
/// Retrieves a list of available intervals for candle data.
99-
pub fn intervals(&self) -> Result<Vec<String>> {
100-
self.client.get("/dex/candle/intervals", None)
101-
}
10252
}
10353

10454
/// Implements the `Datamaxi` trait for `Candle`, providing methods
@@ -204,87 +154,139 @@ impl Trade {
204154

205155
self.client.get("/dex/trade", Some(parameters))
206156
}
157+
}
158+
159+
/// Implements the `Datamaxi` trait for `Trade`, providing methods
160+
/// to create new instances of `Trade` with or without a custom base URL.
161+
impl Datamaxi for Trade {
162+
/// Creates a new `Trade` instance with the default base URL.
163+
///
164+
/// # Parameters
165+
/// - `api_key`: A `String` containing the API key to authenticate requests.
166+
///
167+
/// # Returns
168+
/// A new `Trade` instance configured with the default base URL and the provided `api_key`.
169+
///
170+
/// # Example
171+
/// ```rust
172+
/// use crate::datamaxi::api::Datamaxi;
173+
/// let trade = datamaxi::dex::Trade::new("my_api_key".to_string());
174+
/// ```
175+
fn new(api_key: String) -> Trade {
176+
let config = Config {
177+
base_url: None, // Use the default base URL
178+
api_key, // Provided API key
179+
};
180+
Trade {
181+
client: Client::new(config), // Create a new client with the given config
182+
}
183+
}
184+
185+
/// Creates a new `Trade` instance with a custom base URL.
186+
///
187+
/// # Parameters
188+
/// - `api_key`: A `String` containing the API key to authenticate requests.
189+
/// - `base_url`: A `String` specifying the custom base URL for API requests.
190+
///
191+
/// # Returns
192+
/// A new `Trade` instance configured with the provided `base_url` and `api_key`.
193+
///
194+
/// # Example
195+
/// ```rust
196+
/// use crate::datamaxi::api::Datamaxi;
197+
/// let trade = datamaxi::dex::Trade::new_with_base_url("my_api_key".to_string(), "https://custom-api.example.com".to_string());
198+
/// ```
199+
fn new_with_base_url(api_key: String, base_url: String) -> Trade {
200+
let config = Config {
201+
base_url: Some(base_url), // Use the provided custom base URL
202+
api_key, // Provided API key
203+
};
204+
Trade {
205+
client: Client::new(config), // Create a new client with the given config
206+
}
207+
}
208+
}
207209

210+
#[derive(Clone)]
211+
pub struct Pool {
212+
pub client: Client,
213+
}
214+
215+
impl Pool {
208216
/// Retrieves information about available pools, including details about the chain, exchange,
209217
/// base and quote symbols, and pool address. Optional parameters can be provided to filter the
210218
/// results by chain and exchange.
211-
pub fn pools(&self, options: PoolsOptions) -> Result<Vec<PoolsResponse>> {
219+
pub fn get(
220+
&self,
221+
options: PoolsOptions,
222+
) -> Result<PoolsResponse>
223+
{
212224
let mut parameters = HashMap::new();
213225

214226
// optional
215227
parameters.extend(
216228
[
217-
options
218-
.chain
219-
.map(|chain| ("chain".to_string(), chain.to_string())),
220229
options
221230
.exchange
222231
.map(|exchange| ("exchange".to_string(), exchange.to_string())),
232+
options
233+
.chain
234+
.map(|chain| ("chain".to_string(), chain.to_string())),
223235
]
224236
.into_iter()
225237
.flatten(),
226238
);
227239

228-
self.client.get("/dex/trade/pools", Some(parameters))
229-
}
230-
231-
/// Retrieves a list of available intervals for trade data.
232-
pub fn chains(&self) -> Result<Vec<String>> {
233-
self.client.get("/dex/trade/chains", None)
234-
}
235-
236-
/// Retrieves a list of available exchanges for trade data.
237-
pub fn exchanges(&self) -> Result<Vec<String>> {
238-
self.client.get("/dex/trade/exchanges", None)
240+
self.client.get("/dex/pools", Some(parameters))
239241
}
240242
}
241243

242-
/// Implements the `Datamaxi` trait for `Trade`, providing methods
243-
/// to create new instances of `Trade` with or without a custom base URL.
244-
impl Datamaxi for Trade {
245-
/// Creates a new `Trade` instance with the default base URL.
244+
/// Implements the `Datamaxi` trait for `Pool`, providing methods
245+
/// to create new instances of `Pool` with or without a custom base URL.
246+
impl Datamaxi for Pool {
247+
/// Creates a new `Pool` instance with the default base URL.
246248
///
247249
/// # Parameters
248250
/// - `api_key`: A `String` containing the API key to authenticate requests.
249251
///
250252
/// # Returns
251-
/// A new `Trade` instance configured with the default base URL and the provided `api_key`.
253+
/// A new `Pool` instance configured with the default base URL and the provided `api_key`.
252254
///
253255
/// # Example
254256
/// ```rust
255257
/// use crate::datamaxi::api::Datamaxi;
256-
/// let trade = datamaxi::dex::Trade::new("my_api_key".to_string());
258+
/// let pool = datamaxi::dex::Pool::new("my_api_key".to_string());
257259
/// ```
258-
fn new(api_key: String) -> Trade {
260+
fn new(api_key: String) -> Pool {
259261
let config = Config {
260262
base_url: None, // Use the default base URL
261263
api_key, // Provided API key
262264
};
263-
Trade {
265+
Pool {
264266
client: Client::new(config), // Create a new client with the given config
265267
}
266268
}
267269

268-
/// Creates a new `Trade` instance with a custom base URL.
270+
/// Creates a new `Pool` instance with a custom base URL.
269271
///
270272
/// # Parameters
271273
/// - `api_key`: A `String` containing the API key to authenticate requests.
272274
/// - `base_url`: A `String` specifying the custom base URL for API requests.
273275
///
274276
/// # Returns
275-
/// A new `Trade` instance configured with the provided `base_url` and `api_key`.
277+
/// A new `Pool` instance configured with the provided `base_url` and `api_key`.
276278
///
277279
/// # Example
278280
/// ```rust
279281
/// use crate::datamaxi::api::Datamaxi;
280-
/// let trade = datamaxi::dex::Trade::new_with_base_url("my_api_key".to_string(), "https://custom-api.example.com".to_string());
282+
/// let pool = datamaxi::dex::Pool::new_with_base_url("my_api_key".to_string(), "https://custom-api.example.com".to_string());
281283
/// ```
282-
fn new_with_base_url(api_key: String, base_url: String) -> Trade {
284+
fn new_with_base_url(api_key: String, base_url: String) -> Pool {
283285
let config = Config {
284286
base_url: Some(base_url), // Use the provided custom base URL
285287
api_key, // Provided API key
286288
};
287-
Trade {
289+
Pool {
288290
client: Client::new(config), // Create a new client with the given config
289291
}
290292
}

0 commit comments

Comments
 (0)