#data #stock #market #time-series #historical #fetch #enhance

market-data

一个用于获取并增强历史时间序列股票市场数据的Rust库

7个版本

0.3.3 2024年3月14日
0.3.2 2024年3月12日
0.2.0 2024年3月6日
0.1.1 2024年3月5日

#97 in HTTP客户端

每月34次下载

Apache-2.0

93KB
2K SLoC

market-data

一个用于获取并增强历史时间序列股票市场数据的Rust库。

默认是使用<%= ureq %> HTTP客户端的Sync版本。可以通过启用"使用异步"功能来使用<%= reqwest %> HTTP客户端的异步版本。

要启用异步功能

market-data= {版本= "*",功能= ["use-async"] }

用法

请查看示例文件夹以获取每个发布者的示例。

// Select a Publisher from the available ones
let mut site = Twelvedata::new(TOKEN.to_string());

// 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("GOOGL", 40);
site.intraday_series("MSFT", 40, Interval::Hour2)?;

// create the MarketClient
let mut client = MarketClient::new(site);

// 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(|output| match output {
    Ok(data) => println!("{}\n\n", data),
    Err(err) => println!("{}", err),
});

// the client can be reused for additional series
client.site.daily_series("GOOGL", 300);

// 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: Vec<EnhancedMarketSeries> = data2
    .into_iter()
    .filter_map(|series| series.ok())
    .map(|series| {
        series
            .enhance_data()
            .with_sma(10)
            .with_ema(20)
            .with_rsi(14)
            .with_macd(12, 26, 9)
            .calculate()
    })
    .collect();

enhanced_data
    .into_iter()
    .for_each(|enhanced_series| println!("{}", enhanced_series));

// 打印GOOGL每日增强序列的示例 - 使用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, ,

支持的发布者

实现适用于提供免费层级的付费订阅的几个网站。详细信息可以在Publishers.md文件中找到。

目前支持以下内容

可以添加新的发布者(如Nasdaq Data Link - WIKIPMarketstack等)。

欢迎贡献,如果您需要其他发布者(源网站),请提出PR或创建问题。

支持的市场技术指标

欢迎贡献,如果您需要其他指标,请提出PR或创建问题。

开发中

导出API密钥,如:export Publisher_TOKEN=<your_token_here>

Cargo.toml中的默认功能是use-sync,如果您正在开发异步版本,请将默认功能更改为use-async。

运行示例

cargo run --example example_name

// for async
cargo run --example async_example_name --features="use-async" --no-default-features

依赖项

~3–18MB
~233K SLoC