From 0785e8c3e834185d058ef5ad89e727241040c027 Mon Sep 17 00:00:00 2001 From: gmoratorio Date: Thu, 14 Nov 2024 09:43:45 -0700 Subject: [PATCH 1/2] add custom deserializer for Decimal --- src/models/markets.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/models/markets.rs b/src/models/markets.rs index 116b5de..d3f866b 100644 --- a/src/models/markets.rs +++ b/src/models/markets.rs @@ -1,20 +1,42 @@ use chrono::{DateTime, Utc}; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; +use serde::de::{self, Deserializer}; +use rust_decimal::prelude::FromPrimitive; + +fn deserialize_decimal_from_f64<'de, D>(deserializer: D) -> Result +where + D: Deserializer<'de>, +{ + let float = f64::deserialize(deserializer)?; + Decimal::from_f64(float).ok_or_else(|| de::Error::custom("Failed to convert float to Decimal")) +} #[derive(Clone, Debug, Deserialize)] pub struct DexPairOHLC { + #[serde(deserialize_with = "deserialize_decimal_from_f64")] pub coin_a_change_pct: Decimal, + #[serde(deserialize_with = "deserialize_decimal_from_f64")] pub coin_a_close: Decimal, + #[serde(deserialize_with = "deserialize_decimal_from_f64")] pub coin_a_high: Decimal, + #[serde(deserialize_with = "deserialize_decimal_from_f64")] pub coin_a_low: Decimal, + #[serde(deserialize_with = "deserialize_decimal_from_f64")] pub coin_a_open: Decimal, + #[serde(deserialize_with = "deserialize_decimal_from_f64")] pub coin_a_volume: Decimal, + #[serde(deserialize_with = "deserialize_decimal_from_f64")] pub coin_b_change_pct: Decimal, + #[serde(deserialize_with = "deserialize_decimal_from_f64")] pub coin_b_close: Decimal, + #[serde(deserialize_with = "deserialize_decimal_from_f64")] pub coin_b_high: Decimal, + #[serde(deserialize_with = "deserialize_decimal_from_f64")] pub coin_b_low: Decimal, + #[serde(deserialize_with = "deserialize_decimal_from_f64")] pub coin_b_open: Decimal, + #[serde(deserialize_with = "deserialize_decimal_from_f64")] pub coin_b_volume: Decimal, pub count: i64, pub timestamp: DateTime, From 61e0d24045f7d0812dc7d3d7e7ecad6ed0ec5a81 Mon Sep 17 00:00:00 2001 From: gmoratorio Date: Thu, 14 Nov 2024 09:43:58 -0700 Subject: [PATCH 2/2] bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2fde00f..e00787b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "maestro-rust-sdk" -version = "1.2.4" +version = "1.2.5" description = "Rust SDK for the Maestro Dapp Platform" repository = "https://github.com/maestro-org/rust-sdk" documentation = "https://docs.gomaestro.org/"