A Rust lib to fetch & enhance historical time-series stock market data.
This library provides a stateless, async-first API to download historical stock data from various providers and enhance it with common technical indicators.
- Async-first: Built on
tokioandreqwest. - Stateless Architecture: Reusable clients and immutable request objects.
- Multiple Publishers: Supports Finnhub, Alpha Vantage, Massive (formerly Polygon.io), Twelvedata, and Yahoo Finance.
- Technical Indicators: Built-in support for SMA, EMA, RSI, MACD, and Stochastic Oscillator.
Add this to your Cargo.toml:
[dependencies]
market-data = "0.5"
tokio = { version = "1.0", features = ["full"] }Each publisher provides a set of methods to create request objects, which are then passed to the MarketClient.
use market_data::{MarketClient, Twelvedata, Interval};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// 1. Select a Publisher (e.g., Twelvedata)
let site = Twelvedata::new("YOUR_TOKEN".to_string());
// 2. Create the MarketClient
let client = MarketClient::new(site);
// 3. Create a stateless request
let request = client.site.intraday_series("MSFT", 150, Interval::Min15)?;
// 4. Fetch the data
let data = client.fetch(request).await?;
// 5. Enhance the data with technical indicators
let enhanced_data = data
.enhance_data()
.with_sma(10)
.with_ema(20)
.with_rsi(14)
.with_macd(12, 26, 9)
.calculate();
// 6. Print the results
println!("{}", enhanced_data);
Ok(())
}Details on rate limits and historical data depth can be found in Publishers.md.
- Finnhub
- Alpha Vantage
- Massive (formerly Polygon.io)
- Twelvedata
- Yahoo Finance (Unofficial, no token required)
- Simple Moving Average (SMA)
- Exponential Moving Averages (EMA)
- Relative Strength Index (RSI)
- Stochastic Oscillator
- Moving Average Convergence/Divergence (MACD)
To run the examples, export your API keys:
export Finnhub_TOKEN=<your_token>
export Twelvedata_TOKEN=<your_token>
# etc...Run an example:
cargo run --example series_finnhubContributions are welcome! If you'd like to add a new publisher or technical indicator, please raise a PR or create an issue.
Apache-2.0