use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct PriceData {
#[serde(flatten)]
pub prices: HashMap<String, f64>,
#[serde(flatten)]
pub extra: HashMap<String, serde_json::Value>,
}
pub type PricesResponse = HashMap<String, HashMap<String, serde_json::Value>>;
pub type TokenPricesResponse = HashMap<String, HashMap<String, serde_json::Value>>;
pub type SupportedCurrencies = Vec<String>;
#[derive(Debug, Clone, Default)]
pub struct PriceOptions {
pub include_market_cap: bool,
pub include_24hr_vol: bool,
pub include_24hr_change: bool,
pub include_last_updated_at: bool,
pub precision: Option<String>,
}
impl PriceOptions {
pub fn new() -> Self {
Self::default()
}
pub fn full() -> Self {
Self {
include_market_cap: true,
include_24hr_vol: true,
include_24hr_change: true,
include_last_updated_at: true,
precision: None,
}
}
pub fn to_query_string(&self) -> String {
let mut params = Vec::new();
if self.include_market_cap {
params.push("include_market_cap=true".to_string());
}
if self.include_24hr_vol {
params.push("include_24hr_vol=true".to_string());
}
if self.include_24hr_change {
params.push("include_24hr_change=true".to_string());
}
if self.include_last_updated_at {
params.push("include_last_updated_at=true".to_string());
}
if let Some(ref p) = self.precision {
params.push(format!("precision={}", p));
}
if params.is_empty() {
String::new()
} else {
format!("&{}", params.join("&"))
}
}
}