Skip to main content

finance_query/adapters/
mod.rs

1//! External financial data source adapters.
2//!
3//! Each adapter is behind a feature flag and follows the same pattern:
4//!
5//! 1. **Enable the feature** in `Cargo.toml`:
6//!    ```toml
7//!    [dependencies]
8//!    finance-query = { version = "2.4", features = ["polygon"] }
9//!    ```
10//!
11//! 2. **Initialize once** at startup with your API key:
12//!    ```no_run
13//!    # #[cfg(feature = "polygon")]
14//!    finance_query::adapters::polygon::init("YOUR_KEY").unwrap();
15//!    ```
16//!
17//! 3. **Call any endpoint** — all functions are async:
18//!    ```no_run
19//!    # #[cfg(feature = "polygon")]
20//!    # async fn example() -> Result<(), Box<dyn std::error::Error>> {
21//!    use finance_query::adapters::polygon::{self, Timespan};
22//!    let bars = polygon::stock_aggregates("AAPL", 1, Timespan::Day, "2024-01-01", "2024-12-31", None).await?;
23//!    # Ok(())
24//!    # }
25//!    ```
26//!
27//! # Available adapters
28//!
29//! | Feature | Provider | Free tier | Endpoints | Coverage |
30//! |---------|----------|-----------|-----------|----------|
31//! | `alphavantage` | [Alpha Vantage](https://www.alphavantage.co/) | 25 req/day | ~100 | Stocks, forex, crypto, commodities, economic indicators, 50+ technical indicators |
32//! | `polygon` | [Polygon.io](https://polygon.io/) | 5 req/sec | ~100 | Stocks, options, forex, crypto, indices, futures, economy, analyst data, WebSocket streaming |
33//! | `fmp` | [Financial Modeling Prep](https://financialmodelingprep.com/) | 250 req/day | ~100 | Fundamentals, DCF/ratings, insider trading, institutional holdings, screener, 60+ exchanges |
34//!
35//! # Quick comparison
36//!
37//! - **Alpha Vantage**: Best free option for technical indicators (50+) and economic data. Lowest rate limits.
38//! - **Polygon.io**: Tick-level trades/quotes, SEC filings, real-time WebSocket streams. Best for market microstructure.
39//! - **FMP**: Deepest fundamentals coverage (as-reported financials, DCF, ratings, analyst estimates, earnings transcripts). Best for fundamental analysis.
40//!
41//! All adapters share:
42//! - Singleton pattern with `init(api_key)` / `init_with_timeout(api_key, timeout)`
43//! - Built-in rate limiting via shared token-bucket limiter
44//! - Error mapping to [`crate::FinanceError`] variants
45//! - Full mockito test coverage (no API key needed to run tests)
46
47pub(crate) mod common;
48
49/// Alpha Vantage financial data API (requires `alphavantage` feature).
50#[cfg(feature = "alphavantage")]
51pub mod alphavantage;
52
53/// Polygon.io financial data API (requires `polygon` feature).
54#[cfg(feature = "polygon")]
55pub mod polygon;
56
57/// Financial Modeling Prep (FMP) financial data API (requires `fmp` feature).
58#[cfg(feature = "fmp")]
59pub mod fmp;