finance_query/adapters/polygon/stocks/
corporate_actions.rs1use serde::{Deserialize, Serialize};
4
5use crate::error::Result;
6
7use super::super::build_client;
8use super::super::models::PaginatedResponse;
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
12#[non_exhaustive]
13pub struct Dividend {
14 pub ticker: Option<String>,
16 pub cash_amount: Option<f64>,
18 pub currency: Option<String>,
20 pub declaration_date: Option<String>,
22 pub dividend_type: Option<String>,
24 pub ex_dividend_date: Option<String>,
26 pub frequency: Option<u32>,
28 pub pay_date: Option<String>,
30 pub record_date: Option<String>,
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[non_exhaustive]
37pub struct Split {
38 pub ticker: Option<String>,
40 pub execution_date: Option<String>,
42 pub split_from: Option<f64>,
44 pub split_to: Option<f64>,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50#[non_exhaustive]
51pub struct Ipo {
52 pub ticker: Option<String>,
54 pub name: Option<String>,
56 pub listing_date: Option<String>,
58 pub ipo_price: Option<f64>,
60 pub currency: Option<String>,
62 pub primary_exchange: Option<String>,
64 pub lot_size: Option<u64>,
66 pub ipo_status: Option<String>,
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize)]
72#[non_exhaustive]
73pub struct TickerEvent {
74 #[serde(rename = "type")]
76 pub event_type: Option<String>,
77 pub date: Option<String>,
79 pub ticker_change: Option<serde_json::Value>,
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize)]
85#[non_exhaustive]
86pub struct TickerEventsResponse {
87 pub request_id: Option<String>,
89 pub status: Option<String>,
91 pub name: Option<String>,
93 pub events: Option<Vec<TickerEvent>>,
95}
96
97pub async fn stock_dividends(params: &[(&str, &str)]) -> Result<PaginatedResponse<Dividend>> {
99 let client = build_client()?;
100 client.get("/v3/reference/dividends", params).await
101}
102
103pub async fn stock_splits(params: &[(&str, &str)]) -> Result<PaginatedResponse<Split>> {
105 let client = build_client()?;
106 client.get("/v3/reference/splits", params).await
107}
108
109pub async fn stock_ipos(params: &[(&str, &str)]) -> Result<PaginatedResponse<Ipo>> {
111 let client = build_client()?;
112 client.get("/v1/reference/ipos", params).await
113}
114
115pub async fn stock_ticker_events(ticker: &str) -> Result<TickerEventsResponse> {
117 let client = build_client()?;
118 let path = format!("/vX/reference/tickers/{}/events", ticker);
119 let json = client.get_raw(&path, &[]).await?;
120 serde_json::from_value(json).map_err(|e| crate::error::FinanceError::ResponseStructureError {
121 field: "ticker_events".to_string(),
122 context: format!("Failed to parse ticker events: {e}"),
123 })
124}