Skip to main content

finance_query/adapters/polygon/
alternative.rs

1//! Alternative data: consumer spending (Fable Data merchant aggregates and hierarchy).
2
3use serde::{Deserialize, Serialize};
4
5use crate::error::Result;
6
7use super::build_client;
8use super::models::PaginatedResponse;
9
10/// Merchant aggregate data (European consumer spending).
11#[derive(Debug, Clone, Serialize, Deserialize)]
12#[non_exhaustive]
13pub struct MerchantAggregate {
14    /// Merchant name.
15    pub merchant: Option<String>,
16    /// Parent company.
17    pub parent: Option<String>,
18    /// Date.
19    pub date: Option<String>,
20    /// Transaction count.
21    pub transaction_count: Option<f64>,
22    /// Average transaction value.
23    pub avg_transaction_value: Option<f64>,
24    /// Total spend.
25    pub total_spend: Option<f64>,
26}
27
28/// Merchant hierarchy entry (merchant-to-parent mapping).
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[non_exhaustive]
31pub struct MerchantHierarchy {
32    /// Merchant name.
33    pub merchant: Option<String>,
34    /// Parent company name.
35    pub parent: Option<String>,
36    /// Ticker symbol (if public).
37    pub ticker: Option<String>,
38    /// Category.
39    pub category: Option<String>,
40}
41
42/// Fetch merchant aggregate spending data.
43pub async fn merchant_aggregates(
44    params: &[(&str, &str)],
45) -> Result<PaginatedResponse<MerchantAggregate>> {
46    let client = build_client()?;
47    client
48        .get("/v1/alternative/merchant-aggregates", params)
49        .await
50}
51
52/// Fetch merchant hierarchy (merchant-to-parent mappings).
53pub async fn merchant_hierarchy(
54    params: &[(&str, &str)],
55) -> Result<PaginatedResponse<MerchantHierarchy>> {
56    let client = build_client()?;
57    client
58        .get("/v1/alternative/merchant-hierarchy", params)
59        .await
60}