A股量化数据工具
Project description
Stockman
友好的A股量化数据包,支持tushare等多数据渠道(其他渠道开发中)收集,自带常用和非常用数据指标(开发中)
一、使用方式
1、生成配置文件清单
# example_generate_config_pystock.py
import stockman
stock = stockman.Stock()
stock.generate_config()
上述代码将会在项目当前目录生成 sample.yaml 配置文件, 请根据实际情况进行填写
DBCONFIG: # MYSQL数据库配置
host: 127.0.0.1 # MYSQL数据库主机地址
dbname: stock_db # MYSQL数据库名称,需要自己创建该名称数据库
username: root # MYSQL数据库用户名
password: stock_db # MYSQL数据库密码
port: 3306 # MYSQL数据库端口
charset: utf8 # MYSQL数据库默认字符集
prefix: stockman_ # MYSQL数据库表前缀
APIS: # 数据渠道配置
Tushare: # Tushare 数据渠道
Params: # Tushare 数据渠道配置
token: '' # Tushare 数据渠道TOKEN,请于Tushare个人中心获取
Permissions: # Tushare 数据功能权限配置
stock_list: true # 是否使用Tushare渠道进行股票列表数据权限获取
stock_daily: true # 是否使用Tushare渠道进行股票日线数据权限获取
stock_trade_cal: true # 是否使用Tushare渠道进行股票交易日历数据获取
2、自动安装数据表
# example_install_pystock.py
import stockman
with open("sample.yaml", "r") as f:
res = f.read()
stock = stockman.Stock(res)
stock.install()
上述代码将会根据配置文件 sample.yaml 的数据库部分配置,生成各项数据表
3、设置接口调度频率限制
本功能主要用于开源API或者未来主动采集数据时拉取数据的速度限制,如tushare的日线数据接口调用限制为 100次/60秒
# example_set_func_times_limit_pystock.py
import stockman
with open("sample.yaml", "r") as f:
res = f.read()
stock = stockman.Stock(res)
stock.set_times_limit(feature="tushare.stock_daily_sub", limit_time=(100, 60))
set_times_limit 方法接收 feature 与 limit_time 两个参数,其中 feature 参数的组成结构为 {api_name}.{func_name} , limit_time
参数为一个包含两个值的元组,依次为 次数 、 时间(单位为秒),指代的频率为 次数/时间(单位为秒)
目前feature支持调节频率的方法为
| 接口名称 | api_name | func_name | 默认值 |
|---|---|---|---|
| Tushare日线数据接口 | tushare | stock_daily_sub | 100/60 |
4、初始化数据
# example_init_data_pystock.py
import stockman
with open("sample.yaml", "r") as f:
res = f.read()
stock = stockman.Stock(res)
stock.init()
上述代码将会自动依次根据配置文件 sample.yaml 中的数据渠道部分中的权限配置去导入历史数据,目前包含有交易日历、股票列表、历史日K线数据等。
5、主动更新数据
# example_update_pystock.py
import stockman
with open("sample.yaml", "r") as f:
res = f.read()
stock = stockman.Stock(res)
# 更新日K线数据
def update_daily_k_data():
stock.update_daily_k_data()
# 更新股票列表数据
def update_stock_list_data():
stock.update_stock_list_data()
if __name__ == '__main__':
update_daily_k_data()
update_stock_list_data()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stockman-0.0.2.tar.gz.
File metadata
- Download URL: stockman-0.0.2.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3235429c66d8445e18ac2ff1e5655bbd794d1f72d745a7231d2b43e6a14657d6
|
|
| MD5 |
0ec3e19ecc6d1fde55da44741514b6c9
|
|
| BLAKE2b-256 |
74644bf6d860ad52d91522b953632e4a05f8e5555121750550f302f54cf4c58a
|
File details
Details for the file stockman-0.0.2-py3-none-any.whl.
File metadata
- Download URL: stockman-0.0.2-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48faa2e6aa4d33f717d1dc7e97fea14f21ef75ee354ca862713e693445344575
|
|
| MD5 |
cf8364cde18dff6d57df2dcba773ad3c
|
|
| BLAKE2b-256 |
03e7090517180064671b9e35cdc4f2918157b4ab564f7ea569e1a0eafd814106
|