Skip to content

A Rust lib to fetch & enhance historical time-series stock market data

License

Notifications You must be signed in to change notification settings

danrusei/market-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

market-data

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.

Features

  • Async-first: Built on tokio and reqwest.
  • 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.

Installation

Add this to your Cargo.toml:

[dependencies]
market-data = "0.5"
tokio = { version = "1.0", features = ["full"] }

Usage

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(())
}

Supported Publishers

Details on rate limits and historical data depth can be found in Publishers.md.

Supported Market Technical Indicators

For Development

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_finnhub

Contributing

Contributions are welcome! If you'd like to add a new publisher or technical indicator, please raise a PR or create an issue.

License

Apache-2.0

About

A Rust lib to fetch & enhance historical time-series stock market data

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages