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;
// Example Print of the Enhanced Series on GOOGL - calculating SMA 10, EMA 20, RSI 14, MACD (12, 26, 9):
Date: 2023-12-27, Open: 141.59, Close: 140.37, High: 142.08, Low: 139.89, Volume: 19628600.00, SMA 10: 137.17, EMA 20: 136.40, RSI 14: 62.03, MACD (12, 26, 9): 1.87, 1.03, 0.84, ,
Date: 2023-12-28, Open: 140.78, Close: 140.23, High: 141.14, Low: 139.75, Volume: 16045700.00, SMA 10: 137.94, EMA 20: 136.77, RSI 14: 61.58, MACD (12, 26, 9): 1.93, 1.21, 0.72, ,
Date: 2023-12-29, Open: 139.63, Close: 139.69, High: 140.36, Low: 138.78, Volume: 18727200.00, SMA 10: 138.71, EMA 20: 137.05, RSI 14: 59.79, MACD (12, 26, 9): 1.92, 1.35, 0.57, ,
Date: 2024-01-02, Open: 138.55, Close: 138.17, High: 139.45, Low: 136.48, Volume: 23711200.00, SMA 10: 139.27, EMA 20: 137.15, RSI 14: 54.93, MACD (12, 26, 9): 1.76, 1.43, 0.33, ,
Date: 2024-01-03, Open: 137.25, Close: 138.92, High: 139.63, Low: 137.08, Volume: 24212100.00, SMA 10: 139.58, EMA 20: 137.32, RSI 14: 56.79, MACD (12, 26, 9): 1.68, 1.48, 0.20, ,
Date: 2024-01-04, Open: 138.42, Close: 136.39, High: 139.16, Low: 136.35, Volume: 27137700.00, SMA 10: 139.55, EMA 20: 137.23, RSI 14: 49.37, MACD (12, 26, 9): 1.40, 1.47, -0.07, ,
Date: 2024-01-05, Open: 136.75, Close: 135.73, High: 137.16, Low: 135.15, Volume: 22506000.00, SMA 10: 139.29, EMA 20: 137.09, RSI 14: 47.62, MACD (12, 26, 9): 1.11, 1.39, -0.29, ,
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
- Simple Moving Average (SMA)
- Exponential Moving Averages (EMA)
- Relative Strength Index (RSI)
- Stochastic Oscillator
- Moving Average Convergence/Divergence (MACD)
Contribution is welcomed, if you need other indicators raise a PR or create an issue.
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: