#![allow(dead_code)]
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 TimeSeriesEntryDTO {
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 AdjustedTimeSeriesEntryDTO {
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 TimeSeriesDTO {
pub symbol: String,
pub last_refreshed: String,
pub entries: Vec<TimeSeriesEntryDTO>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AdjustedTimeSeriesDTO {
pub symbol: String,
pub last_refreshed: String,
pub entries: Vec<AdjustedTimeSeriesEntryDTO>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GlobalQuoteDTO {
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 BulkQuoteDTO {
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 SymbolMatchDTO {
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 MarketStatusDTO {
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 OptionContractDTO {
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 OptionsChainDTO {
pub symbol: String,
pub contracts: Vec<OptionContractDTO>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct NewsArticleDTO {
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<TickerSentimentDTO>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TickerSentimentDTO {
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 EarningsCallTranscriptDTO {
pub symbol: String,
pub quarter: String,
pub transcript: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TopMoverTickerDTO {
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 TopMoversDTO {
pub last_updated: String,
pub top_gainers: Vec<TopMoverTickerDTO>,
pub top_losers: Vec<TopMoverTickerDTO>,
pub most_actively_traded: Vec<TopMoverTickerDTO>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CompanyOverviewDTO {
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 EtfProfileDTO {
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<EtfHoldingDTO>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EtfHoldingDTO {
pub symbol: Option<String>,
pub description: Option<String>,
pub weight: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct FinancialReportDTO {
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 FinancialStatementsDTO {
pub symbol: String,
pub annual_reports: Vec<FinancialReportDTO>,
pub quarterly_reports: Vec<FinancialReportDTO>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DividendEventDTO {
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 SplitEventDTO {
pub effective_date: Option<String>,
pub split_ratio: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EarningsDataDTO {
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 EarningsHistoryDTO {
pub symbol: String,
pub annual_earnings: Vec<EarningsDataDTO>,
pub quarterly_earnings: Vec<EarningsDataDTO>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EarningsCalendarEntryDTO {
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 IpoCalendarEntryDTO {
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 ListingEntryDTO {
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 ExchangeRateDTO {
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 ForexEntryDTO {
pub timestamp: String,
pub open: f64,
pub high: f64,
pub low: f64,
pub close: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ForexTimeSeriesDTO {
pub from_symbol: String,
pub to_symbol: String,
pub last_refreshed: String,
pub entries: Vec<ForexEntryDTO>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CryptoEntryDTO {
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 CryptoTimeSeriesDTO {
pub symbol: String,
pub market: String,
pub last_refreshed: String,
pub entries: Vec<CryptoEntryDTO>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CommodityDataPointDTO {
pub date: String,
pub value: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CommoditySeriesDTO {
pub name: String,
pub interval: String,
pub unit: String,
pub data: Vec<CommodityDataPointDTO>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EconomicDataPointDTO {
pub date: String,
pub value: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EconomicSeriesDTO {
pub name: String,
pub interval: String,
pub unit: String,
pub data: Vec<EconomicDataPointDTO>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct IndicatorDataPointDTO {
pub timestamp: String,
pub values: std::collections::HashMap<String, f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TechnicalIndicatorDTO {
pub indicator: String,
pub symbol: String,
pub last_refreshed: String,
pub interval: String,
pub data: Vec<IndicatorDataPointDTO>,
}