use serde::{Deserialize, Serialize};
use crate::error::Result;
use super::super::build_client;
use super::super::models::PaginatedResponse;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Dividend {
pub ticker: Option<String>,
pub cash_amount: Option<f64>,
pub currency: Option<String>,
pub declaration_date: Option<String>,
pub dividend_type: Option<String>,
pub ex_dividend_date: Option<String>,
pub frequency: Option<u32>,
pub pay_date: Option<String>,
pub record_date: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Split {
pub ticker: Option<String>,
pub execution_date: Option<String>,
pub split_from: Option<f64>,
pub split_to: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Ipo {
pub ticker: Option<String>,
pub name: Option<String>,
pub listing_date: Option<String>,
pub ipo_price: Option<f64>,
pub currency: Option<String>,
pub primary_exchange: Option<String>,
pub lot_size: Option<u64>,
pub ipo_status: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TickerEvent {
#[serde(rename = "type")]
pub event_type: Option<String>,
pub date: Option<String>,
pub ticker_change: Option<serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TickerEventsResponse {
pub request_id: Option<String>,
pub status: Option<String>,
pub name: Option<String>,
pub events: Option<Vec<TickerEvent>>,
}
pub async fn stock_dividends(params: &[(&str, &str)]) -> Result<PaginatedResponse<Dividend>> {
let client = build_client()?;
client.get("/v3/reference/dividends", params).await
}
pub async fn stock_splits(params: &[(&str, &str)]) -> Result<PaginatedResponse<Split>> {
let client = build_client()?;
client.get("/v3/reference/splits", params).await
}
pub async fn stock_ipos(params: &[(&str, &str)]) -> Result<PaginatedResponse<Ipo>> {
let client = build_client()?;
client.get("/v1/reference/ipos", params).await
}
pub async fn stock_ticker_events(ticker: &str) -> Result<TickerEventsResponse> {
let client = build_client()?;
let path = format!("/vX/reference/tickers/{}/events", ticker);
let json = client.get_raw(&path, &[]).await?;
serde_json::from_value(json).map_err(|e| crate::error::FinanceError::ResponseStructureError {
field: "ticker_events".to_string(),
context: format!("Failed to parse ticker events: {e}"),
})
}