Skip to main content

header.png

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

Metadata

Release files for stockman 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stockman 0.0.2
File Size Uploaded
stockman-0.0.2.tar.gz 13.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stockman 0.0.2
File Interpreter ABI Platform
stockman-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 31.1 kB

Release files / stockman-0.0.2.tar.gz

Download URL stockman-0.0.2.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3235429c66d8445e18ac2ff1e5655bbd794d1f72d745a7231d2b43e6a14657d6
BLAKE2b-256 checksum
How to use checksums
74644bf6d860ad52d91522b953632e4a05f8e5555121750550f302f54cf4c58a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / stockman-0.0.2-py3-none-any.whl

Download URL stockman-0.0.2-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
48faa2e6aa4d33f717d1dc7e97fea14f21ef75ee354ca862713e693445344575
BLAKE2b-256 checksum
How to use checksums
03e7090517180064671b9e35cdc4f2918157b4ab564f7ea569e1a0eafd814106
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page