diff --git a/examples/README.md b/examples/README.md index fee0038..be61c0f 100644 --- a/examples/README.md +++ b/examples/README.md @@ -12,7 +12,7 @@ cargo run --release -q --example "cex-candle" ## DEX Trade ```bash -cargo run --release -q --example "dex-trade" +cargo run --release -q --example "dex" ``` ## DEX Candle diff --git a/examples/cex-candle.rs b/examples/cex-candle.rs index 02a1d8d..f5176c5 100644 --- a/examples/cex-candle.rs +++ b/examples/cex-candle.rs @@ -30,7 +30,7 @@ fn main() { // CEX Candle Data let candle_options = datamaxi::cex::CandleOptions::new(); - let candle_response = candle.get("binance", "ETH-USDT", candle_options); + let candle_response = candle.get("binance", "BTC-USDT", "futures", candle_options); match candle_response { Ok(answer) => match serde_json::to_string(&answer) { Ok(json) => println!("{}", json), diff --git a/examples/dex.rs b/examples/dex.rs index f3466bf..af43716 100644 --- a/examples/dex.rs +++ b/examples/dex.rs @@ -33,7 +33,7 @@ fn main() { let trade_response = dex.trade( "bsc_mainnet", "pancakeswap", - "0xb24cd29e32FaCDDf9e73831d5cD1FFcd1e535423", + "0x6ee3eE9C3395BbD136B6076A70Cb6cFF241c0E24", trade_options, ); match trade_response { @@ -55,7 +55,7 @@ fn main() { let candle_response = dex.candle( "bsc_mainnet", "pancakeswap", - "0xb24cd29e32FaCDDf9e73831d5cD1FFcd1e535423", + "0x6ee3eE9C3395BbD136B6076A70Cb6cFF241c0E24", params, ); match candle_response { diff --git a/src/cex.rs b/src/cex.rs index 6c98644..7827544 100644 --- a/src/cex.rs +++ b/src/cex.rs @@ -13,28 +13,31 @@ impl Candle { /// Retrieves candle data for a specified exchange and symbol. Additional parameters can be /// provided to filter and sort the results. The response will contain an array of candle data /// objects, each representing a single candle with open, high, low, close, and volume values. - pub fn get( + pub fn get( &self, exchange: E, symbol: S, + market: M, options: CandleOptions, ) -> Result where E: Into, S: Into, + M: Into, { let mut parameters = HashMap::new(); // required parameters.insert("exchange".to_string(), exchange.into()); + parameters.insert("market".to_string(), market.into()); parameters.insert("symbol".to_string(), symbol.into()); // optional parameters.extend( [ options - .market - .map(|market| ("market".to_string(), market.to_string())), + .currency + .map(|currency| ("currency".to_string(), currency.to_string())), options .interval .map(|interval| ("interval".to_string(), interval.to_string())), diff --git a/src/dex.rs b/src/dex.rs index 84cc8af..c667aec 100644 --- a/src/dex.rs +++ b/src/dex.rs @@ -1,6 +1,6 @@ use crate::api::{Client, Config, Datamaxi, Result}; pub use crate::models::{CandleOptions, PoolsOptions, TradeOptions}; -use crate::models::{CandleResponse, PoolsResponse, TradeResponse}; +use crate::models::{DexCandleResponse, PoolsResponse, TradeResponse}; use std::collections::HashMap; /// Provides methods for retrieving DEX candle data and related information. @@ -19,7 +19,7 @@ impl Dex { exchange: E, pool: P, options: CandleOptions, - ) -> Result + ) -> Result where C: Into, E: Into, @@ -35,22 +35,19 @@ impl Dex { // optional parameters.extend( [ - options - .market - .map(|market| ("market".to_string(), market.to_string())), options .interval .map(|interval| ("interval".to_string(), interval.to_string())), + options + .from + .map(|from| ("from".to_string(), from.to_string())), + options.to.map(|to| ("to".to_string(), to.to_string())), options .page .map(|page| ("page".to_string(), page.to_string())), options .limit .map(|limit| ("limit".to_string(), limit.to_string())), - options - .from - .map(|from| ("from".to_string(), from.to_string())), - options.to.map(|to| ("to".to_string(), to.to_string())), options .sort .map(|sort| ("sort".to_string(), sort.to_string())), @@ -87,16 +84,16 @@ impl Dex { // optional parameters.extend( [ + options + .from + .map(|from| ("from".to_string(), from.to_string())), + options.to.map(|to| ("to".to_string(), to.to_string())), options .page .map(|page| ("page".to_string(), page.to_string())), options .limit .map(|limit| ("limit".to_string(), limit.to_string())), - options - .from - .map(|from| ("from".to_string(), from.to_string())), - options.to.map(|to| ("to".to_string(), to.to_string())), options .sort .map(|sort| ("sort".to_string(), sort.to_string())), diff --git a/src/models.rs b/src/models.rs index a23193a..58a3c38 100644 --- a/src/models.rs +++ b/src/models.rs @@ -6,27 +6,27 @@ use serde::Serialize; pub struct CandleDetail { /// The timestamp of the candle's open time. #[serde(rename = "d")] - pub timestamp: String, + pub timestamp: f64, /// The opening price of the asset at the beginning of the time frame. #[serde(rename = "o")] - pub open: String, + pub open: f64, /// The highest price of the asset during the time frame. #[serde(rename = "h")] - pub high: String, + pub high: f64, /// The lowest price of the asset during the time frame. #[serde(rename = "l")] - pub low: String, + pub low: f64, /// The closing price of the asset at the end of the time frame. #[serde(rename = "c")] - pub close: String, + pub close: f64, /// The total volume of trades (in the base currency) that occurred during the time frame. #[serde(rename = "v")] - pub volume: String, + pub volume: f64, } /// Response containing candle data. @@ -35,20 +35,66 @@ pub struct CandleResponse { /// A vector containing detailed information about each candle. pub data: Vec, - /// The current page number in the paginated response. - pub page: i32, + pub currency: String, - /// The maximum number of items per page in the response. - pub limit: i32, + pub interval: String, - /// The starting point of the time frame for the candle data. - pub from: String, + pub market: String, - /// The ending point of the time frame for the candle data. - pub to: String, + pub symbol: String, +} + +/// Detailed information about a dex candle. +#[derive(Serialize, Deserialize, Debug)] +pub struct DexCandleDetail { + /// The timestamp of the candle's open time. + #[serde(rename = "d")] + pub timestamp: f64, + + /// The opening price of the asset at the beginning of the time frame. + #[serde(rename = "o")] + pub open: f64, + + /// The highest price of the asset during the time frame. + #[serde(rename = "h")] + pub high: f64, + + /// The lowest price of the asset during the time frame. + #[serde(rename = "l")] + pub low: f64, + + /// The closing price of the asset at the end of the time frame. + #[serde(rename = "c")] + pub close: f64, + + /// Specifies trading volume (base token) of the candle. + #[serde(rename = "bv")] + pub basevolume: f64, + + /// Specifies trading volume (quote token) of the candle. + #[serde(rename = "qv")] + pub quotevolume: f64, +} + +/// Response containing dex candle data +#[derive(Serialize, Deserialize, Debug)] +pub struct DexCandleResponse { + /// A vector containing detailed information about each candle. + pub data: Vec, + + pub exchange: String, + + pub chain: String, + + pub pool: String, + + pub interval: String, - /// The sorting order for the candle data (e.g., "asc" or "desc"). pub sort: String, + + pub page: i32, + + pub limit: i32, } /// Detailed information about a trade. @@ -56,19 +102,15 @@ pub struct CandleResponse { pub struct TradeDetail { /// The timestamp of the trade. #[serde(rename = "d")] - pub timestamp: String, + pub timestamp: i64, /// The block number in which the trade was recorded. #[serde(rename = "b")] pub block_number: i64, - /// The trading pool where the trade occurred. - #[serde(rename = "pool")] - pub pool: String, + pub base: String, - /// The trading symbol associated with the trade (e.g., BTC-USDT). - #[serde(rename = "s")] - pub symbol: String, + pub quote: String, /// The hash of the transaction related to the trade. #[serde(rename = "tx")] @@ -84,15 +126,15 @@ pub struct TradeDetail { /// The quantity of the base asset traded, in base unit. #[serde(rename = "bq")] - pub base_quantity: String, + pub base_quantity: f64, /// The quantity of the quote asset traded, in base unit. #[serde(rename = "qq")] - pub quote_quantity: String, + pub quote_quantity: f64, /// The price of the trade in the quote asset's unit. #[serde(rename = "p")] - pub price: String, + pub price: f64, } /// Response containing trade data. @@ -107,11 +149,11 @@ pub struct TradeResponse { /// The maximum number of items per page in the response. pub limit: i32, - /// The starting point of the time frame for the trade data. - pub from: String, + pub exchange: String, + + pub chain: String, - /// The ending point of the time frame for the trade data. - pub to: String, + pub pool: String, /// The sorting order for the trade data (e.g., "asc" or "desc"). pub sort: String, @@ -139,6 +181,9 @@ pub struct CandleOptions { /// The sorting order for the candle data (e.g., "asc" or "desc"). pub sort: Option, + + /// The currency to display (e.g. USD) + pub currency: Option, } impl Default for CandleOptions { @@ -159,6 +204,7 @@ impl CandleOptions { from: None, to: None, sort: Some("desc".into()), + currency: None, } }