diff --git a/Cargo.toml b/Cargo.toml index 3dd4d17..3f08535 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,7 @@ license = "Apache-2.0" [dependencies] reqwest = "0.11" serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" \ No newline at end of file +serde_json = "1.0" +rust_decimal = "1.34" +serde_qs = "0.12" +chrono = { version = "0.4", features = ["serde"] } diff --git a/src/client/epochs.rs b/src/client/epochs.rs index d2b8909..6b60a46 100644 --- a/src/client/epochs.rs +++ b/src/client/epochs.rs @@ -12,7 +12,7 @@ impl Maestro { } pub async fn specific_epoch(&self, epoch_no: i32) -> Result> { - let url = format!("/epochs/{}/info", epoch_no); + let url = format!("/epochs/{}", epoch_no); let resp = self.get(&url).await?; let specific_epoch = serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box)?; diff --git a/src/client/markets.rs b/src/client/markets.rs new file mode 100644 index 0000000..e770433 --- /dev/null +++ b/src/client/markets.rs @@ -0,0 +1,23 @@ +use crate::models::markets::{DexPairOHLC, DexPairOHLCParameters}; + +use super::maestro::Maestro; +use std::{error::Error, fmt::Display}; + +impl Maestro { + /// Returns market activity in candlestick OHLC format for a specific DEX and token pair + pub async fn markets_dex_pair_ohlc( + &self, + dex: impl Display, + pair: impl Display, + parameters: Option, + ) -> Result, Box> { + let ps = parameters + .and_then(|p| serde_qs::to_string(&p).ok()) + .map(|x| format!("?{x}")) + .unwrap_or_default(); + let url = format!("/markets/dexs/ohlc/{dex}/{pair}{ps}"); + let resp = self.get(&url).await?; + + serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box) + } +} diff --git a/src/client/mod.rs b/src/client/mod.rs index 495fccc..fdb4af0 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -10,6 +10,7 @@ pub mod epochs; pub mod general; pub mod linear_vesting; pub mod maestro; +pub mod markets; pub mod pools; pub mod scripts; pub mod transactions; diff --git a/src/client/pools.rs b/src/client/pools.rs index b1714f0..804ee4a 100644 --- a/src/client/pools.rs +++ b/src/client/pools.rs @@ -1,8 +1,9 @@ use super::maestro::Maestro; use crate::{ models::pools::{ - PoolMintedBlocks, RegisteredPools, StakePoolDelegators, StakePoolHistory, - StakePoolInformation, StakePoolMetadata, StakePoolRelays, StakePoolUpdates, + PoolMintedBlocks, RegisteredPools, StakePoolDelegatorHistory, StakePoolDelegators, + StakePoolHistory, StakePoolInformation, StakePoolMetadata, StakePoolRelays, + StakePoolUpdates, }, utils::Parameters, }; @@ -103,4 +104,21 @@ impl Maestro { serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box)?; Ok(stake_pool_updates) } + + pub async fn stake_pool_delegator_history( + &self, + pool_id: &str, + epoch_no: i64, + params: Option, + ) -> Result> { + let formatted_params = params.map(|p| p.format()).unwrap_or_default(); + let url = format!( + "/pools/{}/delegators/{}{}", + pool_id, epoch_no, formatted_params + ); + let resp = self.get(&url).await?; + let stake_pool_delegator_history = + serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box)?; + Ok(stake_pool_delegator_history) + } } diff --git a/src/models/epochs.rs b/src/models/epochs.rs index b1e4019..65192f7 100644 --- a/src/models/epochs.rs +++ b/src/models/epochs.rs @@ -5,8 +5,8 @@ use serde::Deserialize; pub struct Epoch { pub blk_count: i32, pub epoch_no: i32, - pub fees: i32, - pub start_time: i32, + pub fees: String, + pub start_time: i64, pub tx_count: i32, } diff --git a/src/models/markets.rs b/src/models/markets.rs new file mode 100644 index 0000000..8f9981a --- /dev/null +++ b/src/models/markets.rs @@ -0,0 +1,60 @@ +use chrono::{DateTime, Utc}; +use rust_decimal::Decimal; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Deserialize)] +pub struct DexPairOHLC { + pub coin_a_change_pct: Decimal, + pub coin_a_close: Decimal, + pub coin_a_high: Decimal, + pub coin_a_low: Decimal, + pub coin_a_open: Decimal, + pub coin_a_volume: Decimal, + pub coin_b_change_pct: Decimal, + pub coin_b_close: Decimal, + pub coin_b_high: Decimal, + pub coin_b_low: Decimal, + pub coin_b_open: Decimal, + pub coin_b_volume: Decimal, + pub count: i64, + pub timestamp: DateTime, +} + +#[derive(Clone, Copy, Debug, Serialize)] +pub enum Resolution { + #[serde(rename = "1m")] + OneMinute, + #[serde(rename = "5m")] + FiveMinutes, + #[serde(rename = "15m")] + FifteenMinutes, + #[serde(rename = "30m")] + ThirtyMinutes, + #[serde(rename = "1h")] + OneHour, + #[serde(rename = "4h")] + FourHours, + #[serde(rename = "1d")] + OneDay, + #[serde(rename = "1w")] + OneWeek, + #[serde(rename = "1mo")] + OneMonth, +} + +#[derive(Clone, Copy, Debug, Serialize)] +pub enum Sort { + #[serde(rename = "asc")] + Asc, + #[serde(rename = "desc")] + Desc, +} + +#[derive(Clone, Debug, Default, Serialize)] +pub struct DexPairOHLCParameters { + pub resolution: Option, + pub from: Option, + pub to: Option, + pub limit: Option, + pub sort: Option, +} diff --git a/src/models/mod.rs b/src/models/mod.rs index 8eeb790..1daef17 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -7,6 +7,7 @@ pub mod datum; pub mod epochs; pub mod general; pub mod linear_vesting; +pub mod markets; pub mod pools; pub mod scripts; pub mod transactions; diff --git a/src/models/pools.rs b/src/models/pools.rs index d879f5b..e4e4ff9 100644 --- a/src/models/pools.rs +++ b/src/models/pools.rs @@ -56,7 +56,7 @@ pub struct StakePoolHistoryData { pub epoch_no: i64, pub epoch_ros: String, pub fixed_cost: i64, - pub margin: i64, + pub margin: serde_json::Value, pub pool_fees: i64, pub saturation_pct: serde_json::Value, } @@ -142,3 +142,16 @@ pub struct StakePoolUpdates { pub data: Vec, pub last_updated: utils::LastUpdated, } + +#[derive(Deserialize)] +pub struct StakePoolDelegatorHistoryData { + pub amount: String, + pub stake_address: String, +} + +#[derive(Deserialize)] +pub struct StakePoolDelegatorHistory { + pub data: Vec, + pub last_updated: utils::LastUpdated, + pub next_cursor: Option, +}