market-data
A Rust lib to fetch & enhance historical time-series stock market data.
The Sync version using the ureq http client is the default. An Async version using reqwest http client can be selected by enabling the "use-async" feature.
To enable async feature:
market-data = { version = "*", features = ["use-async"] }
Usage
Check the Examples folder for more examples.
// Select a Publisher from the available ones
let mut site = new;
// configure to retrieve Daily, Weekly or Intraday series, check the available methods for each publisher
// output_size is mandatory for Twelvedata - and supports values in the range from 1 to 5000 , default is 30.
// multiple requests can be added
site.weekly_series;
site.daily_series;
// create the MarketClient
let mut client = new;
// creates the query URL & download the raw data
client = client.create_endpoint?.get_data?;
// transform into MarketSeries, that can be used for further processing
let data = client.transform_data;
// prints the data
data.iter.for_each;
// the client can be reused for additional series
client
.site
.intraday_series?;
// the consuming the client pattern, the client can't be reused for configuring new series
let data2 = client.create_endpoint?.get_data?.transform_data;
// the data can be enhanced with the calculation of a number of market indicators
let enhanced_data: = data2
.into_iter
.filter_map
.map
.collect;
enhanced_data
.into_iter
.for_each;
// Prints:
// Date: 2024-02-23, Open: 410.14, Close: 410.32, High: 410.85, Low: 409.84, Volume: 1814939.00, SMA 10: 405.48, EMA 20: 405.94, EMA 6: 408.56, RSI 14: 59.19,
// Date: 2024-02-23, Open: 410.11, Close: 410.12, High: 410.78, Low: 409.53, Volume: 1998775.00, SMA 10: 406.31, EMA 20: 406.34, EMA 6: 409.00, RSI 14: 57.86,
// Date: 2024-02-23, Open: 410.77, Close: 410.11, High: 410.86, Low: 408.97, Volume: 2621471.00, SMA 10: 407.10, EMA 20: 406.70, EMA 6: 409.32, RSI 14: 64.33,
// Date: 2024-02-23, Open: 415.67, Close: 410.73, High: 415.86, Low: 410.09, Volume: 6230853.00, SMA 10: 408.32, EMA 20: 407.08, EMA 6: 409.72, RSI 14: 68.58,
Supported Publishers
Implementation is available for a number of sites that offer Free Tier. New Publishers can be added, your contribution is welcome. Additional details can be found in Publishers.md file. So far the following are supported:
- Alpha Vantage
- Twelvedata
- Iex cloud - may not work unless you use the paid subscribtions
Alternative providers, to be added:
- [] Polygon
- [] Nasdaq Data Link - WIKIP
- [] Marketstack
- [] Tradier
- [] Yahoo Finance site - maybe?
- [] Stook parse site- maybe?
Supported Market Technical Indicators
Others to be implemented:
For development
Export the API Keys, as: export Publisher_TOKEN=<your_toke_here>
Default feature in Cargo.toml is use-sync, if working on async version change the default to use-async.
Run the examples: