use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum AlternativeMeError {
#[error("HTTP error: {0}")]
Http(#[from] reqwest_middleware::Error),
#[error("Request error: {0}")]
Request(#[from] reqwest::Error),
#[error("API error: {0}")]
Api(String),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Metadata {
pub timestamp: i64,
#[serde(default)]
pub num_cryptocurrencies: Option<i32>,
#[serde(default)]
pub error: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TickerQuote {
pub price: f64,
pub volume_24h: f64,
pub market_cap: f64,
#[serde(default)]
pub percent_change_1h: Option<f64>,
#[serde(default)]
pub percent_change_24h: Option<f64>,
#[serde(default)]
pub percent_change_7d: Option<f64>,
#[serde(flatten)]
pub extra: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Ticker {
pub id: i64,
pub name: String,
pub symbol: String,
pub website_slug: String,
pub rank: i32,
pub circulating_supply: Option<f64>,
pub total_supply: Option<f64>,
pub max_supply: Option<f64>,
pub quotes: HashMap<String, TickerQuote>,
pub last_updated: i64,
}
#[derive(Debug, Clone, Default)]
pub struct GetTickerRequest {
pub limit: Option<i32>,
pub start: Option<i32>,
pub convert: Option<String>,
pub structure: Option<String>,
pub sort: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TickerArrayResponse {
pub data: Vec<Ticker>,
pub metadata: Metadata,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TickerDictResponse {
pub data: HashMap<String, Ticker>,
pub metadata: Metadata,
}
#[derive(Debug, Clone, Default)]
pub struct GetTickerByIdRequest {
pub convert: Option<String>,
pub structure: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GlobalQuote {
pub total_market_cap: f64,
pub total_volume_24h: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GlobalData {
pub active_cryptocurrencies: i32,
pub active_markets: i32,
pub bitcoin_percentage_of_market_cap: f64,
pub quotes: HashMap<String, GlobalQuote>,
pub last_updated: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GlobalResponse {
pub data: GlobalData,
pub metadata: Metadata,
}
#[derive(Debug, Clone, Default)]
pub struct GetGlobalRequest {
pub convert: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FearAndGreedData {
pub value: String,
pub value_classification: String,
pub timestamp: String,
#[serde(default)]
pub time_until_update: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FearAndGreedMetadata {
#[serde(default)]
pub error: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FearAndGreedResponse {
pub name: String,
pub data: Vec<FearAndGreedData>,
pub metadata: FearAndGreedMetadata,
}
#[derive(Debug, Clone, Default)]
pub struct GetFearAndGreedRequest {
pub limit: Option<i32>,
pub format: Option<String>,
pub date_format: Option<String>,
}