use chrono::{DateTime, NaiveDate, Utc};
use serde::{Deserialize, Serialize};
pub type Timestamp = DateTime<Utc>;
pub type Date = NaiveDate;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PaginatedResponse<T> {
pub data: Vec<T>,
#[serde(skip_serializing_if = "Option::is_none")]
pub total: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub count: Option<i64>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum MarketStatus {
Open,
Closed,
#[serde(rename = "pre-market")]
PreMarket,
#[serde(rename = "after-hours")]
AfterHours,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Resolution {
#[serde(rename = "1")]
OneMinute,
#[serde(rename = "5")]
FiveMinutes,
#[serde(rename = "15")]
FifteenMinutes,
#[serde(rename = "30")]
ThirtyMinutes,
#[serde(rename = "60")]
SixtyMinutes,
#[serde(rename = "D")]
Daily,
#[serde(rename = "W")]
Weekly,
#[serde(rename = "M")]
Monthly,
}
impl Resolution {
pub fn as_str(&self) -> &'static str {
match self {
Self::OneMinute => "1",
Self::FiveMinutes => "5",
Self::FifteenMinutes => "15",
Self::ThirtyMinutes => "30",
Self::SixtyMinutes => "60",
Self::Daily => "D",
Self::Weekly => "W",
Self::Monthly => "M",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Exchange(pub String);
impl Exchange {
pub const US: &'static str = "US";
pub const NYSE: &'static str = "NYSE";
pub const NASDAQ: &'static str = "NASDAQ";
pub const LSE: &'static str = "LSE";
pub const TSE: &'static str = "TSE";
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Currency(pub String);
impl Currency {
pub const USD: &'static str = "USD";
pub const EUR: &'static str = "EUR";
pub const GBP: &'static str = "GBP";
pub const JPY: &'static str = "JPY";
pub const CAD: &'static str = "CAD";
pub const AUD: &'static str = "AUD";
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Candle {
#[serde(rename = "o")]
pub open: f64,
#[serde(rename = "h")]
pub high: f64,
#[serde(rename = "l")]
pub low: f64,
#[serde(rename = "c")]
pub close: f64,
#[serde(rename = "v")]
pub volume: f64,
#[serde(rename = "t")]
pub timestamp: i64,
#[serde(rename = "s", skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Metric {
pub key: String,
pub value: serde_json::Value,
}