use serde::{Deserialize, Deserializer, Serialize};
#[allow(dead_code)]
pub(crate) fn deserialize_optional_f64<'de, D>(
deserializer: D,
) -> std::result::Result<Option<f64>, D::Error>
where
D: Deserializer<'de>,
{
let s: Option<String> = Option::deserialize(deserializer)?;
match s.as_deref() {
Some("None") | Some(".") | Some("-") | Some("") | None => Ok(None),
Some(v) => v.parse::<f64>().ok().map_or(Ok(None), |n| Ok(Some(n))),
}
}
#[allow(dead_code)]
pub(crate) fn deserialize_f64_from_str<'de, D>(
deserializer: D,
) -> std::result::Result<f64, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(s.parse::<f64>().unwrap_or(0.0))
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AvInterval {
OneMin,
FiveMin,
FifteenMin,
ThirtyMin,
SixtyMin,
Daily,
Weekly,
Monthly,
}
impl AvInterval {
pub fn as_str(&self) -> &'static str {
match self {
Self::OneMin => "1min",
Self::FiveMin => "5min",
Self::FifteenMin => "15min",
Self::ThirtyMin => "30min",
Self::SixtyMin => "60min",
Self::Daily => "daily",
Self::Weekly => "weekly",
Self::Monthly => "monthly",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SeriesType {
Close,
Open,
High,
Low,
}
impl SeriesType {
pub fn as_str(&self) -> &'static str {
match self {
Self::Close => "close",
Self::Open => "open",
Self::High => "high",
Self::Low => "low",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OutputSize {
Compact,
Full,
}
impl OutputSize {
pub fn as_str(&self) -> &'static str {
match self {
Self::Compact => "compact",
Self::Full => "full",
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TimeSeriesEntry {
pub timestamp: String,
pub open: f64,
pub high: f64,
pub low: f64,
pub close: f64,
pub volume: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AdjustedTimeSeriesEntry {
pub timestamp: String,
pub open: f64,
pub high: f64,
pub low: f64,
pub close: f64,
pub adjusted_close: f64,
pub volume: f64,
pub dividend_amount: f64,
pub split_coefficient: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TimeSeries {
pub symbol: String,
pub last_refreshed: String,
pub entries: Vec<TimeSeriesEntry>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AdjustedTimeSeries {
pub symbol: String,
pub last_refreshed: String,
pub entries: Vec<AdjustedTimeSeriesEntry>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GlobalQuote {
pub symbol: String,
pub open: f64,
pub high: f64,
pub low: f64,
pub price: f64,
pub volume: f64,
pub latest_trading_day: String,
pub previous_close: f64,
pub change: f64,
pub change_percent: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BulkQuote {
pub symbol: String,
pub open: Option<f64>,
pub high: Option<f64>,
pub low: Option<f64>,
pub price: Option<f64>,
pub volume: Option<f64>,
pub latest_trading_day: Option<String>,
pub previous_close: Option<f64>,
pub change: Option<f64>,
pub change_percent: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct SymbolMatch {
pub symbol: String,
pub name: String,
pub asset_type: String,
pub region: String,
pub market_open: String,
pub market_close: String,
pub timezone: String,
pub currency: String,
pub match_score: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MarketStatus {
pub market_type: String,
pub region: String,
pub primary_exchanges: String,
pub local_open: String,
pub local_close: String,
pub current_status: String,
pub notes: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct OptionContract {
pub contractid: String,
pub symbol: String,
pub expiration: String,
pub strike: f64,
pub option_type: String,
pub last: Option<f64>,
pub mark: Option<f64>,
pub bid: Option<f64>,
pub bid_size: Option<f64>,
pub ask: Option<f64>,
pub ask_size: Option<f64>,
pub volume: Option<f64>,
pub open_interest: Option<f64>,
pub implied_volatility: Option<f64>,
pub delta: Option<f64>,
pub gamma: Option<f64>,
pub theta: Option<f64>,
pub vega: Option<f64>,
pub rho: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct OptionsChain {
pub symbol: String,
pub contracts: Vec<OptionContract>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct NewsArticle {
pub title: String,
pub url: String,
pub time_published: String,
pub source: String,
pub summary: String,
pub overall_sentiment_score: Option<f64>,
pub overall_sentiment_label: Option<String>,
pub ticker_sentiment: Vec<TickerSentiment>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TickerSentiment {
pub ticker: String,
pub relevance_score: Option<f64>,
pub ticker_sentiment_score: Option<f64>,
pub ticker_sentiment_label: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EarningsCallTranscript {
pub symbol: String,
pub quarter: String,
pub transcript: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TopMoverTicker {
pub ticker: String,
pub price: String,
pub change_amount: String,
pub change_percentage: String,
pub volume: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TopMovers {
pub last_updated: String,
pub top_gainers: Vec<TopMoverTicker>,
pub top_losers: Vec<TopMoverTicker>,
pub most_actively_traded: Vec<TopMoverTicker>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CompanyOverview {
pub symbol: String,
pub asset_type: Option<String>,
pub name: Option<String>,
pub description: Option<String>,
pub exchange: Option<String>,
pub currency: Option<String>,
pub country: Option<String>,
pub sector: Option<String>,
pub industry: Option<String>,
pub market_capitalization: Option<f64>,
pub pe_ratio: Option<f64>,
pub peg_ratio: Option<f64>,
pub book_value: Option<f64>,
pub dividend_per_share: Option<f64>,
pub dividend_yield: Option<f64>,
pub eps: Option<f64>,
pub revenue_per_share_ttm: Option<f64>,
pub profit_margin: Option<f64>,
pub operating_margin_ttm: Option<f64>,
pub return_on_assets_ttm: Option<f64>,
pub return_on_equity_ttm: Option<f64>,
pub revenue_ttm: Option<f64>,
pub gross_profit_ttm: Option<f64>,
pub ebitda: Option<f64>,
pub week_52_high: Option<f64>,
pub week_52_low: Option<f64>,
pub moving_average_50day: Option<f64>,
pub moving_average_200day: Option<f64>,
pub shares_outstanding: Option<f64>,
pub beta: Option<f64>,
pub forward_pe: Option<f64>,
pub price_to_sales_ratio_ttm: Option<f64>,
pub price_to_book_ratio: Option<f64>,
pub analyst_target_price: Option<f64>,
pub analyst_rating_strong_buy: Option<u32>,
pub analyst_rating_buy: Option<u32>,
pub analyst_rating_hold: Option<u32>,
pub analyst_rating_sell: Option<u32>,
pub analyst_rating_strong_sell: Option<u32>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EtfProfile {
pub symbol: String,
pub name: Option<String>,
pub asset_type: Option<String>,
pub net_assets: Option<f64>,
pub net_expense_ratio: Option<f64>,
pub portfolio_turnover: Option<f64>,
pub dividend_yield: Option<f64>,
pub inception_date: Option<String>,
pub holdings: Vec<EtfHolding>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EtfHolding {
pub symbol: Option<String>,
pub description: Option<String>,
pub weight: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct FinancialReport {
pub fiscal_date_ending: String,
pub reported_currency: String,
#[serde(flatten)]
pub fields: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct FinancialStatements {
pub symbol: String,
pub annual_reports: Vec<FinancialReport>,
pub quarterly_reports: Vec<FinancialReport>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DividendEvent {
pub ex_dividend_date: Option<String>,
pub declaration_date: Option<String>,
pub record_date: Option<String>,
pub payment_date: Option<String>,
pub amount: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct SplitEvent {
pub effective_date: Option<String>,
pub split_ratio: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EarningsData {
pub fiscal_date_ending: Option<String>,
pub reported_date: Option<String>,
pub reported_eps: Option<f64>,
pub estimated_eps: Option<f64>,
pub surprise: Option<f64>,
pub surprise_percentage: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EarningsHistory {
pub symbol: String,
pub annual_earnings: Vec<EarningsData>,
pub quarterly_earnings: Vec<EarningsData>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EarningsCalendarEntry {
pub symbol: String,
pub name: Option<String>,
pub report_date: Option<String>,
pub fiscal_date_ending: Option<String>,
pub estimate: Option<f64>,
pub currency: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct IpoCalendarEntry {
pub symbol: Option<String>,
pub name: Option<String>,
pub ipo_date: Option<String>,
pub price_range: Option<String>,
pub exchange: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ListingEntry {
pub symbol: String,
pub name: Option<String>,
pub exchange: Option<String>,
pub asset_type: Option<String>,
pub ipo_date: Option<String>,
pub delisting_date: Option<String>,
pub status: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ExchangeRate {
pub from_currency_code: String,
pub from_currency_name: String,
pub to_currency_code: String,
pub to_currency_name: String,
pub exchange_rate: f64,
pub last_refreshed: String,
pub bid_price: f64,
pub ask_price: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ForexEntry {
pub timestamp: String,
pub open: f64,
pub high: f64,
pub low: f64,
pub close: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ForexTimeSeries {
pub from_symbol: String,
pub to_symbol: String,
pub last_refreshed: String,
pub entries: Vec<ForexEntry>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CryptoEntry {
pub timestamp: String,
pub open: f64,
pub high: f64,
pub low: f64,
pub close: f64,
pub volume: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CryptoTimeSeries {
pub symbol: String,
pub market: String,
pub last_refreshed: String,
pub entries: Vec<CryptoEntry>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CommodityDataPoint {
pub date: String,
pub value: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CommoditySeries {
pub name: String,
pub interval: String,
pub unit: String,
pub data: Vec<CommodityDataPoint>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EconomicDataPoint {
pub date: String,
pub value: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EconomicSeries {
pub name: String,
pub interval: String,
pub unit: String,
pub data: Vec<EconomicDataPoint>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct IndicatorDataPoint {
pub timestamp: String,
pub values: std::collections::HashMap<String, f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TechnicalIndicator {
pub indicator: String,
pub symbol: String,
pub last_refreshed: String,
pub interval: String,
pub data: Vec<IndicatorDataPoint>,
}