use serde::{Deserialize, Serialize};
use chrono::{DateTime, Utc};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Quote {
pub symbol: String,
pub last_price: f64,
pub change: f64,
pub change_percent: f64,
pub volume: u64,
pub average_volume: u64,
pub bid_price: f64,
pub bid_size: u64,
pub ask_price: f64,
pub ask_size: u64,
pub high: f64,
pub low: f64,
pub open: f64,
pub prev_close: f64,
pub fifty_two_week_high: f64,
pub fifty_two_week_low: f64,
pub market_cap: Option<f64>,
pub pe_ratio: Option<f64>,
pub timestamp: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Bar {
pub symbol: String,
pub open: f64,
pub high: f64,
pub low: f64,
pub close: f64,
pub volume: u64,
pub timestamp: DateTime<Utc>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum TimeFrame {
Minute1,
Minute5,
Minute15,
Minute30,
Hour1,
Hour4,
Day1,
Week1,
Month1,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BarQueryParams {
pub symbol: String,
pub time_frame: TimeFrame,
pub start_date: Option<DateTime<Utc>>,
pub end_date: Option<DateTime<Utc>>,
pub limit: Option<u32>,
}
impl BarQueryParams {
pub fn new(symbol: impl Into<String>, time_frame: TimeFrame) -> Self {
Self {
symbol: symbol.into(),
time_frame,
start_date: None,
end_date: None,
limit: None,
}
}
pub fn start_date(mut self, start_date: DateTime<Utc>) -> Self {
self.start_date = Some(start_date);
self
}
pub fn end_date(mut self, end_date: DateTime<Utc>) -> Self {
self.end_date = Some(end_date);
self
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptionContract {
pub symbol: String,
pub underlying_symbol: String,
pub strike_price: f64,
pub expiration_date: DateTime<Utc>,
pub option_type: OptionType,
pub last_price: f64,
pub change: f64,
pub change_percent: f64,
pub volume: u64,
pub open_interest: u64,
pub bid_price: f64,
pub bid_size: u64,
pub ask_price: f64,
pub ask_size: u64,
pub implied_volatility: f64,
pub delta: f64,
pub gamma: f64,
pub theta: f64,
pub vega: f64,
pub rho: f64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
pub enum OptionType {
Call,
Put,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptionChain {
pub underlying_symbol: String,
pub expiration_dates: Vec<DateTime<Utc>>,
pub strike_prices: Vec<f64>,
pub contracts: Vec<OptionContract>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptionChainQueryParams {
pub underlying_symbol: String,
pub expiration_date: Option<DateTime<Utc>>,
pub strike_price: Option<f64>,
pub option_type: Option<OptionType>,
}
impl OptionChainQueryParams {
pub fn new(underlying_symbol: impl Into<String>) -> Self {
Self {
underlying_symbol: underlying_symbol.into(),
expiration_date: None,
strike_price: None,
option_type: None,
}
}
pub fn expiration_date(mut self, expiration_date: DateTime<Utc>) -> Self {
self.expiration_date = Some(expiration_date);
self
}
pub fn strike_price(mut self, strike_price: f64) -> Self {
self.strike_price = Some(strike_price);
self
}
pub fn option_type(mut self, option_type: OptionType) -> Self {
self.option_type = Some(option_type);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NewsArticle {
pub id: String,
pub title: String,
pub summary: String,
pub url: String,
pub source: String,
pub publish_date: DateTime<Utc>,
pub symbols: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NewsQueryParams {
pub symbol: Option<String>,
pub start_date: Option<DateTime<Utc>>,
pub end_date: Option<DateTime<Utc>>,
pub limit: Option<u32>,
}
impl NewsQueryParams {
pub fn new() -> Self {
Self {
symbol: None,
start_date: None,
end_date: None,
limit: None,
}
}
pub fn symbol(mut self, symbol: impl Into<String>) -> Self {
self.symbol = Some(symbol.into());
self
}
pub fn start_date(mut self, start_date: DateTime<Utc>) -> Self {
self.start_date = Some(start_date);
self
}
pub fn end_date(mut self, end_date: DateTime<Utc>) -> Self {
self.end_date = Some(end_date);
self
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
}
impl Default for NewsQueryParams {
fn default() -> Self {
Self::new()
}
}