use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PaginatedResponse<T> {
pub results: Option<Vec<T>>,
pub status: Option<String>,
pub request_id: Option<String>,
#[serde(rename = "resultsCount")]
pub results_count: Option<usize>,
pub count: Option<usize>,
pub next_url: Option<String>,
pub ticker: Option<String>,
pub adjusted: Option<bool>,
#[serde(rename = "queryCount")]
pub query_count: Option<usize>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Timespan {
Second,
Minute,
Hour,
Day,
Week,
Month,
Quarter,
Year,
}
impl Timespan {
pub fn as_str(&self) -> &'static str {
match self {
Self::Second => "second",
Self::Minute => "minute",
Self::Hour => "hour",
Self::Day => "day",
Self::Week => "week",
Self::Month => "month",
Self::Quarter => "quarter",
Self::Year => "year",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Sort {
Asc,
Desc,
}
impl Sort {
pub fn as_str(&self) -> &'static str {
match self {
Self::Asc => "asc",
Self::Desc => "desc",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Order {
Asc,
Desc,
}
impl Order {
pub fn as_str(&self) -> &'static str {
match self {
Self::Asc => "asc",
Self::Desc => "desc",
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AggBar {
#[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 = "vw")]
pub vwap: Option<f64>,
#[serde(rename = "t")]
pub timestamp: i64,
#[serde(rename = "n")]
pub transactions: Option<u64>,
#[serde(rename = "otc")]
pub otc: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AggregateResponse {
pub ticker: Option<String>,
pub status: Option<String>,
pub adjusted: Option<bool>,
#[serde(rename = "resultsCount")]
pub results_count: Option<usize>,
#[serde(rename = "queryCount")]
pub query_count: Option<usize>,
pub request_id: Option<String>,
pub results: Option<Vec<AggBar>>,
pub next_url: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DailyOpenClose {
pub symbol: Option<String>,
pub from: Option<String>,
pub open: Option<f64>,
pub high: Option<f64>,
pub low: Option<f64>,
pub close: Option<f64>,
pub volume: Option<f64>,
#[serde(rename = "afterHours")]
pub after_hours: Option<f64>,
#[serde(rename = "preMarket")]
pub pre_market: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Trade {
pub conditions: Option<Vec<i32>>,
pub correction: Option<i32>,
pub exchange: Option<i32>,
pub id: Option<String>,
pub participant_timestamp: Option<i64>,
pub price: Option<f64>,
pub sequence_number: Option<i64>,
pub sip_timestamp: Option<i64>,
pub size: Option<f64>,
pub tape: Option<i32>,
pub trf_id: Option<i32>,
pub trf_timestamp: Option<i64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct LastTrade {
#[serde(rename = "T")]
pub ticker: Option<String>,
pub conditions: Option<Vec<i32>>,
pub correction: Option<i32>,
pub exchange: Option<i32>,
pub id: Option<String>,
pub participant_timestamp: Option<i64>,
pub price: Option<f64>,
pub sequence_number: Option<i64>,
pub sip_timestamp: Option<i64>,
pub size: Option<f64>,
pub tape: Option<i32>,
pub trf_id: Option<i32>,
pub trf_timestamp: Option<i64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Quote {
pub ask_exchange: Option<i32>,
pub ask_price: Option<f64>,
pub ask_size: Option<f64>,
pub bid_exchange: Option<i32>,
pub bid_price: Option<f64>,
pub bid_size: Option<f64>,
pub conditions: Option<Vec<i32>>,
pub indicators: Option<Vec<i32>>,
pub participant_timestamp: Option<i64>,
pub sequence_number: Option<i64>,
pub sip_timestamp: Option<i64>,
pub tape: Option<i32>,
pub trf_timestamp: Option<i64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct LastQuoteResponse {
pub request_id: Option<String>,
pub status: Option<String>,
pub results: Option<Quote>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct LastTradeResponse {
pub request_id: Option<String>,
pub status: Option<String>,
pub results: Option<LastTrade>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct SnapshotAgg {
#[serde(rename = "o")]
pub open: Option<f64>,
#[serde(rename = "h")]
pub high: Option<f64>,
#[serde(rename = "l")]
pub low: Option<f64>,
#[serde(rename = "c")]
pub close: Option<f64>,
#[serde(rename = "v")]
pub volume: Option<f64>,
#[serde(rename = "vw")]
pub vwap: Option<f64>,
#[serde(rename = "t")]
pub timestamp: Option<i64>,
#[serde(rename = "n")]
pub transactions: Option<u64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TickerSnapshot {
pub ticker: Option<String>,
#[serde(rename = "todaysChange")]
pub todays_change: Option<f64>,
#[serde(rename = "todaysChangePerc")]
pub todays_change_perc: Option<f64>,
pub updated: Option<i64>,
pub day: Option<SnapshotAgg>,
#[serde(rename = "prevDay")]
pub prev_day: Option<SnapshotAgg>,
#[serde(rename = "lastTrade")]
pub last_trade: Option<LastTrade>,
#[serde(rename = "lastQuote")]
pub last_quote: Option<Quote>,
pub min: Option<SnapshotAgg>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct SingleSnapshotResponse {
pub request_id: Option<String>,
pub status: Option<String>,
pub ticker: Option<TickerSnapshot>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct SnapshotsResponse {
pub status: Option<String>,
pub request_id: Option<String>,
pub count: Option<usize>,
pub tickers: Option<Vec<TickerSnapshot>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct IndicatorValue {
pub timestamp: Option<i64>,
pub value: Option<f64>,
pub signal: Option<f64>,
pub histogram: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct IndicatorResponse {
pub status: Option<String>,
pub request_id: Option<String>,
pub results: Option<IndicatorResults>,
pub next_url: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct IndicatorResults {
pub underlying: Option<IndicatorUnderlying>,
pub values: Option<Vec<IndicatorValue>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct IndicatorUnderlying {
pub url: Option<String>,
pub aggregates: Option<Vec<AggBar>>,
}
#[derive(Debug, Clone, Default)]
pub struct AggregateParams {
pub adjusted: Option<bool>,
pub sort: Option<Sort>,
pub limit: Option<u32>,
}