use serde::{Deserialize, Serialize};
use crate::adapters::common::encode_path_segment;
use crate::error::Result;
use super::build_client;
use super::models::PaginatedResponse;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EtfAnalytics {
pub ticker: Option<String>,
pub name: Option<String>,
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EtfConstituent {
pub ticker: Option<String>,
pub name: Option<String>,
pub weight: Option<f64>,
pub market_value: Option<f64>,
pub shares: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EtfFundFlow {
pub ticker: Option<String>,
pub date: Option<String>,
pub flow: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EtfProfileData {
pub ticker: Option<String>,
pub name: Option<String>,
pub issuer: Option<String>,
pub expense_ratio: Option<f64>,
pub inception_date: Option<String>,
pub asset_class: Option<String>,
pub sector: Option<String>,
pub region: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EtfTaxonomy {
pub category: Option<String>,
pub subcategory: Option<String>,
pub description: Option<String>,
}
pub async fn etf_analytics(params: &[(&str, &str)]) -> Result<PaginatedResponse<EtfAnalytics>> {
let client = build_client()?;
client.get("/v3/reference/etfs/analytics", params).await
}
pub async fn etf_constituents(
ticker: &str,
params: &[(&str, &str)],
) -> Result<PaginatedResponse<EtfConstituent>> {
let client = build_client()?;
let path = format!(
"/v3/reference/etfs/{}/constituents",
encode_path_segment(ticker)
);
client.get(&path, params).await
}
pub async fn etf_fund_flows(params: &[(&str, &str)]) -> Result<PaginatedResponse<EtfFundFlow>> {
let client = build_client()?;
client.get("/v3/reference/etfs/fund-flows", params).await
}
pub async fn etf_profiles(params: &[(&str, &str)]) -> Result<PaginatedResponse<EtfProfileData>> {
let client = build_client()?;
client.get("/v3/reference/etfs/profiles", params).await
}
pub async fn etf_taxonomies(params: &[(&str, &str)]) -> Result<PaginatedResponse<EtfTaxonomy>> {
let client = build_client()?;
client.get("/v3/reference/etfs/taxonomies", params).await
}