finance_query/adapters/polygon/
etf.rs1use serde::{Deserialize, Serialize};
4
5use crate::adapters::common::encode_path_segment;
6use crate::error::Result;
7
8use super::build_client;
9use super::models::PaginatedResponse;
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
13#[non_exhaustive]
14pub struct EtfAnalytics {
15 pub ticker: Option<String>,
17 pub name: Option<String>,
19 #[serde(flatten)]
21 pub data: std::collections::HashMap<String, serde_json::Value>,
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[non_exhaustive]
27pub struct EtfConstituent {
28 pub ticker: Option<String>,
30 pub name: Option<String>,
32 pub weight: Option<f64>,
34 pub market_value: Option<f64>,
36 pub shares: Option<f64>,
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[non_exhaustive]
43pub struct EtfFundFlow {
44 pub ticker: Option<String>,
46 pub date: Option<String>,
48 pub flow: Option<f64>,
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[non_exhaustive]
55pub struct EtfProfileData {
56 pub ticker: Option<String>,
58 pub name: Option<String>,
60 pub issuer: Option<String>,
62 pub expense_ratio: Option<f64>,
64 pub inception_date: Option<String>,
66 pub asset_class: Option<String>,
68 pub sector: Option<String>,
70 pub region: Option<String>,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[non_exhaustive]
77pub struct EtfTaxonomy {
78 pub category: Option<String>,
80 pub subcategory: Option<String>,
82 pub description: Option<String>,
84}
85
86pub async fn etf_analytics(params: &[(&str, &str)]) -> Result<PaginatedResponse<EtfAnalytics>> {
88 let client = build_client()?;
89 client.get("/v3/reference/etfs/analytics", params).await
90}
91
92pub async fn etf_constituents(
94 ticker: &str,
95 params: &[(&str, &str)],
96) -> Result<PaginatedResponse<EtfConstituent>> {
97 let client = build_client()?;
98 let path = format!(
99 "/v3/reference/etfs/{}/constituents",
100 encode_path_segment(ticker)
101 );
102 client.get(&path, params).await
103}
104
105pub async fn etf_fund_flows(params: &[(&str, &str)]) -> Result<PaginatedResponse<EtfFundFlow>> {
107 let client = build_client()?;
108 client.get("/v3/reference/etfs/fund-flows", params).await
109}
110
111pub async fn etf_profiles(params: &[(&str, &str)]) -> Result<PaginatedResponse<EtfProfileData>> {
113 let client = build_client()?;
114 client.get("/v3/reference/etfs/profiles", params).await
115}
116
117pub async fn etf_taxonomies(params: &[(&str, &str)]) -> Result<PaginatedResponse<EtfTaxonomy>> {
119 let client = build_client()?;
120 client.get("/v3/reference/etfs/taxonomies", params).await
121}