From 5d33f8fa25c031cb52c38ff5432f7d445e74fc75 Mon Sep 17 00:00:00 2001 From: RJ Regenold Date: Tue, 12 Mar 2024 10:24:13 -0500 Subject: [PATCH 1/9] adds `stake_pool_delegator_history` endpoint. --- src/client/pools.rs | 14 ++++++++++++++ src/models/pools.rs | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/src/client/pools.rs b/src/client/pools.rs index b1714f0..fbbb99c 100644 --- a/src/client/pools.rs +++ b/src/client/pools.rs @@ -103,4 +103,18 @@ 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/pools.rs b/src/models/pools.rs index d879f5b..e06cb3d 100644 --- a/src/models/pools.rs +++ b/src/models/pools.rs @@ -142,3 +142,9 @@ pub struct StakePoolUpdates { pub data: Vec, pub last_updated: utils::LastUpdated, } + +#[derive(Deserialize)] +pub struct StakePoolDelegatorHistory { + pub amount: String, + pub stake_address: String, +} From 9cfc383f0f413496b7599c7a8633f8d2b39e6be4 Mon Sep 17 00:00:00 2001 From: RJ Regenold Date: Tue, 12 Mar 2024 10:38:26 -0500 Subject: [PATCH 2/9] fixes return type. --- src/client/pools.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/client/pools.rs b/src/client/pools.rs index fbbb99c..bfb0d37 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, }; @@ -109,9 +110,12 @@ impl Maestro { pool_id: &str, epoch_no: i64, params: Option, - ) -> Result> { + ) -> Result, Box> { let formatted_params = params.map(|p| p.format()).unwrap_or_default(); - let url = format!("/pools/{}/delegators/{}{}", pool_id, epoch_no, formatted_params); + 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)?; From b0dd2a4481e2001962773c1f4a1d7c5671f44124 Mon Sep 17 00:00:00 2001 From: RJ Regenold Date: Tue, 12 Mar 2024 10:41:11 -0500 Subject: [PATCH 3/9] _really_ fixes return types. --- src/client/pools.rs | 2 +- src/models/pools.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/client/pools.rs b/src/client/pools.rs index bfb0d37..804ee4a 100644 --- a/src/client/pools.rs +++ b/src/client/pools.rs @@ -110,7 +110,7 @@ impl Maestro { pool_id: &str, epoch_no: i64, params: Option, - ) -> Result, Box> { + ) -> Result> { let formatted_params = params.map(|p| p.format()).unwrap_or_default(); let url = format!( "/pools/{}/delegators/{}{}", diff --git a/src/models/pools.rs b/src/models/pools.rs index e06cb3d..25d62f3 100644 --- a/src/models/pools.rs +++ b/src/models/pools.rs @@ -144,7 +144,14 @@ pub struct StakePoolUpdates { } #[derive(Deserialize)] -pub struct StakePoolDelegatorHistory { +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, +} From 516d586fae6c64923006523a13934174c98f47a2 Mon Sep 17 00:00:00 2001 From: RJ Regenold Date: Tue, 12 Mar 2024 10:48:04 -0500 Subject: [PATCH 4/9] le sigh. --- src/models/pools.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/pools.rs b/src/models/pools.rs index 25d62f3..b8b801d 100644 --- a/src/models/pools.rs +++ b/src/models/pools.rs @@ -151,7 +151,7 @@ pub struct StakePoolDelegatorHistoryData { #[derive(Deserialize)] pub struct StakePoolDelegatorHistory { - pub data: Vec, + pub data: Vec, pub last_updated: utils::LastUpdated, pub next_cursor: Option, } From 3f8e2b5aa3eff93fde33c46b0dcbfb05dad3fac9 Mon Sep 17 00:00:00 2001 From: RJ Regenold Date: Tue, 12 Mar 2024 12:20:26 -0500 Subject: [PATCH 5/9] margin seems to be a float. --- src/models/pools.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/pools.rs b/src/models/pools.rs index b8b801d..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, } From 07be8052f5a9eba5ccb14b753c463af83f40bd42 Mon Sep 17 00:00:00 2001 From: RJ Regenold Date: Tue, 12 Mar 2024 16:55:59 -0500 Subject: [PATCH 6/9] updates types to match api spec. --- src/models/epochs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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, } From 93cce39f4b422e6f3bdf91fcb36602ebf8235a6f Mon Sep 17 00:00:00 2001 From: RJ Regenold Date: Mon, 18 Mar 2024 10:12:43 -0500 Subject: [PATCH 7/9] adds markets dex pair ohlc endpoint. --- Cargo.toml | 5 +++- src/client/markets.rs | 23 +++++++++++++++++ src/client/mod.rs | 1 + src/models/markets.rs | 60 +++++++++++++++++++++++++++++++++++++++++++ src/models/mod.rs | 1 + 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/client/markets.rs create mode 100644 src/models/markets.rs 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/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/models/markets.rs b/src/models/markets.rs new file mode 100644 index 0000000..0c9f588 --- /dev/null +++ b/src/models/markets.rs @@ -0,0 +1,60 @@ +use chrono::{DateTime, Utc}; +use rust_decimal::Decimal; +use serde::{Deserialize, Serialize}; + +#[derive(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(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(Serialize)] +pub enum Sort { + #[serde(rename = "asc")] + Asc, + #[serde(rename = "desc")] + Desc, +} + +#[derive(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; From 9af20094d0c4d72985374a91e889798ba09e7c34 Mon Sep 17 00:00:00 2001 From: RJ Regenold Date: Mon, 18 Mar 2024 10:19:40 -0500 Subject: [PATCH 8/9] updates req/res for ohlc. --- src/models/markets.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/models/markets.rs b/src/models/markets.rs index 0c9f588..8f9981a 100644 --- a/src/models/markets.rs +++ b/src/models/markets.rs @@ -2,7 +2,7 @@ use chrono::{DateTime, Utc}; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; -#[derive(Deserialize)] +#[derive(Clone, Debug, Deserialize)] pub struct DexPairOHLC { pub coin_a_change_pct: Decimal, pub coin_a_close: Decimal, @@ -20,7 +20,7 @@ pub struct DexPairOHLC { pub timestamp: DateTime, } -#[derive(Serialize)] +#[derive(Clone, Copy, Debug, Serialize)] pub enum Resolution { #[serde(rename = "1m")] OneMinute, @@ -42,7 +42,7 @@ pub enum Resolution { OneMonth, } -#[derive(Serialize)] +#[derive(Clone, Copy, Debug, Serialize)] pub enum Sort { #[serde(rename = "asc")] Asc, @@ -50,9 +50,9 @@ pub enum Sort { Desc, } -#[derive(Default, Serialize)] +#[derive(Clone, Debug, Default, Serialize)] pub struct DexPairOHLCParameters { - pub resolution: Option, + pub resolution: Option, pub from: Option, pub to: Option, pub limit: Option, From 25581cd45823fcda7f0ce5f683578494a6f7a436 Mon Sep 17 00:00:00 2001 From: RJ Regenold Date: Mon, 18 Mar 2024 10:56:47 -0500 Subject: [PATCH 9/9] fixes bad epoch endpoint. --- src/client/epochs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)?;