![header.png](https://cdn.wenanzhe.com/img/68747470733a2f2f7a332e617831782e636f6d2f323032312f30372f30322f5236496832382e6a7067.jfif)
# Stockman
友好的A股量化数据包,支持tushare等多数据渠道(其他渠道开发中)收集,自带常用和非常用数据指标(开发中)
----
## 一、使用方式
### 1、生成配置文件清单
```python
# example_generate_config_pystock.py
import stockman
stock = stockman.Stock()
stock.generate_config()
```
上述代码将会在项目当前目录生成 <b>sample.yaml</b> 配置文件, 请根据实际情况进行填写
```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、自动安装数据表
```python
# example_install_pystock.py
import stockman
with open("sample.yaml", "r") as f:
res = f.read()
stock = stockman.Stock(res)
stock.install()
```
上述代码将会根据配置文件 <b>sample.yaml</b> 的数据库部分配置,生成各项数据表
### 3、设置接口调度频率限制
本功能主要用于开源API或者未来主动采集数据时拉取数据的速度限制,如tushare的日线数据接口调用限制为 100次/60秒
```python
# 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`
参数为一个包含两个值的元组,依次为 <b>次数</b> 、 <b>时间(单位为秒)</b>,指代的频率为 `次数/时间(单位为秒)`
目前feature支持调节频率的方法为
| 接口名称 | api_name | func_name | 默认值 |
|---------------|----------|-----------------|--------|
| Tushare日线数据接口 | tushare | stock_daily_sub | 100/60 |
### 4、初始化数据
```python
# example_init_data_pystock.py
import stockman
with open("sample.yaml", "r") as f:
res = f.read()
stock = stockman.Stock(res)
stock.init()
```
上述代码将会自动依次根据配置文件 <b>sample.yaml</b> 中的数据渠道部分中的权限配置去导入历史数据,目前包含有交易日历、股票列表、历史日K线数据等。
### 5、主动更新数据
```python
# 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()
```
Raw data
{
"_id": null,
"home_page": "https://github.com/sml2h3/stockman",
"name": "stockman",
"maintainer": "",
"docs_url": null,
"requires_python": "<=3.11",
"maintainer_email": "",
"keywords": "",
"author": "sml2h3",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/74/64/4bf6d860ad52d91522b953632e4a05f8e5555121750550f302f54cf4c58a/stockman-0.0.2.tar.gz",
"platform": null,
"description": "![header.png](https://cdn.wenanzhe.com/img/68747470733a2f2f7a332e617831782e636f6d2f323032312f30372f30322f5236496832382e6a7067.jfif)\r\n\r\n# Stockman\r\n\r\n\u53cb\u597d\u7684A\u80a1\u91cf\u5316\u6570\u636e\u5305\uff0c\u652f\u6301tushare\u7b49\u591a\u6570\u636e\u6e20\u9053\uff08\u5176\u4ed6\u6e20\u9053\u5f00\u53d1\u4e2d\uff09\u6536\u96c6\uff0c\u81ea\u5e26\u5e38\u7528\u548c\u975e\u5e38\u7528\u6570\u636e\u6307\u6807\uff08\u5f00\u53d1\u4e2d\uff09\r\n\r\n----\r\n\r\n## \u4e00\u3001\u4f7f\u7528\u65b9\u5f0f\r\n\r\n### 1\u3001\u751f\u6210\u914d\u7f6e\u6587\u4ef6\u6e05\u5355\r\n\r\n```python\r\n# example_generate_config_pystock.py\r\n\r\nimport stockman\r\n\r\nstock = stockman.Stock()\r\nstock.generate_config()\r\n```\r\n\r\n\u4e0a\u8ff0\u4ee3\u7801\u5c06\u4f1a\u5728\u9879\u76ee\u5f53\u524d\u76ee\u5f55\u751f\u6210 <b>sample.yaml</b> \u914d\u7f6e\u6587\u4ef6\uff0c \u8bf7\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8fdb\u884c\u586b\u5199\r\n\r\n```yaml\r\nDBCONFIG: # MYSQL\u6570\u636e\u5e93\u914d\u7f6e\r\n host: 127.0.0.1 # MYSQL\u6570\u636e\u5e93\u4e3b\u673a\u5730\u5740\r\n dbname: stock_db # MYSQL\u6570\u636e\u5e93\u540d\u79f0\uff0c\u9700\u8981\u81ea\u5df1\u521b\u5efa\u8be5\u540d\u79f0\u6570\u636e\u5e93\r\n username: root # MYSQL\u6570\u636e\u5e93\u7528\u6237\u540d\r\n password: stock_db # MYSQL\u6570\u636e\u5e93\u5bc6\u7801\r\n port: 3306 # MYSQL\u6570\u636e\u5e93\u7aef\u53e3\r\n charset: utf8 # MYSQL\u6570\u636e\u5e93\u9ed8\u8ba4\u5b57\u7b26\u96c6\r\n prefix: stockman_ # MYSQL\u6570\u636e\u5e93\u8868\u524d\u7f00\r\nAPIS: # \u6570\u636e\u6e20\u9053\u914d\u7f6e\r\n Tushare: # Tushare \u6570\u636e\u6e20\u9053\r\n Params: # Tushare \u6570\u636e\u6e20\u9053\u914d\u7f6e\r\n token: '' # Tushare \u6570\u636e\u6e20\u9053TOKEN\uff0c\u8bf7\u4e8eTushare\u4e2a\u4eba\u4e2d\u5fc3\u83b7\u53d6\r\n Permissions: # Tushare \u6570\u636e\u529f\u80fd\u6743\u9650\u914d\u7f6e\r\n stock_list: true # \u662f\u5426\u4f7f\u7528Tushare\u6e20\u9053\u8fdb\u884c\u80a1\u7968\u5217\u8868\u6570\u636e\u6743\u9650\u83b7\u53d6\r\n stock_daily: true # \u662f\u5426\u4f7f\u7528Tushare\u6e20\u9053\u8fdb\u884c\u80a1\u7968\u65e5\u7ebf\u6570\u636e\u6743\u9650\u83b7\u53d6\r\n stock_trade_cal: true # \u662f\u5426\u4f7f\u7528Tushare\u6e20\u9053\u8fdb\u884c\u80a1\u7968\u4ea4\u6613\u65e5\u5386\u6570\u636e\u83b7\u53d6\r\n```\r\n\r\n### 2\u3001\u81ea\u52a8\u5b89\u88c5\u6570\u636e\u8868\r\n\r\n```python\r\n# example_install_pystock.py\r\n\r\nimport stockman\r\n\r\nwith open(\"sample.yaml\", \"r\") as f:\r\n res = f.read()\r\nstock = stockman.Stock(res)\r\nstock.install()\r\n```\r\n\r\n\u4e0a\u8ff0\u4ee3\u7801\u5c06\u4f1a\u6839\u636e\u914d\u7f6e\u6587\u4ef6 <b>sample.yaml</b> \u7684\u6570\u636e\u5e93\u90e8\u5206\u914d\u7f6e\uff0c\u751f\u6210\u5404\u9879\u6570\u636e\u8868\r\n\r\n### 3\u3001\u8bbe\u7f6e\u63a5\u53e3\u8c03\u5ea6\u9891\u7387\u9650\u5236\r\n\r\n\u672c\u529f\u80fd\u4e3b\u8981\u7528\u4e8e\u5f00\u6e90API\u6216\u8005\u672a\u6765\u4e3b\u52a8\u91c7\u96c6\u6570\u636e\u65f6\u62c9\u53d6\u6570\u636e\u7684\u901f\u5ea6\u9650\u5236\uff0c\u5982tushare\u7684\u65e5\u7ebf\u6570\u636e\u63a5\u53e3\u8c03\u7528\u9650\u5236\u4e3a 100\u6b21/60\u79d2\r\n\r\n```python\r\n# example_set_func_times_limit_pystock.py\r\n\r\nimport stockman\r\n\r\nwith open(\"sample.yaml\", \"r\") as f:\r\n res = f.read()\r\nstock = stockman.Stock(res)\r\nstock.set_times_limit(feature=\"tushare.stock_daily_sub\", limit_time=(100, 60))\r\n```\r\n\r\n`set_times_limit` \u65b9\u6cd5\u63a5\u6536 `feature` \u4e0e `limit_time` \u4e24\u4e2a\u53c2\u6570\uff0c\u5176\u4e2d `feature` \u53c2\u6570\u7684\u7ec4\u6210\u7ed3\u6784\u4e3a `{api_name}.{func_name}` , `limit_time`\r\n\u53c2\u6570\u4e3a\u4e00\u4e2a\u5305\u542b\u4e24\u4e2a\u503c\u7684\u5143\u7ec4\uff0c\u4f9d\u6b21\u4e3a <b>\u6b21\u6570</b> \u3001 <b>\u65f6\u95f4\uff08\u5355\u4f4d\u4e3a\u79d2\uff09</b>\uff0c\u6307\u4ee3\u7684\u9891\u7387\u4e3a `\u6b21\u6570/\u65f6\u95f4\uff08\u5355\u4f4d\u4e3a\u79d2\uff09`\r\n\r\n\u76ee\u524dfeature\u652f\u6301\u8c03\u8282\u9891\u7387\u7684\u65b9\u6cd5\u4e3a\r\n\r\n| \u63a5\u53e3\u540d\u79f0 | api_name | func_name | \u9ed8\u8ba4\u503c |\r\n|---------------|----------|-----------------|--------|\r\n| Tushare\u65e5\u7ebf\u6570\u636e\u63a5\u53e3 | tushare | stock_daily_sub | 100/60 |\r\n\r\n\r\n### 4\u3001\u521d\u59cb\u5316\u6570\u636e\r\n\r\n```python\r\n# example_init_data_pystock.py\r\n\r\nimport stockman\r\n\r\nwith open(\"sample.yaml\", \"r\") as f:\r\n res = f.read()\r\nstock = stockman.Stock(res)\r\nstock.init()\r\n```\r\n\r\n\u4e0a\u8ff0\u4ee3\u7801\u5c06\u4f1a\u81ea\u52a8\u4f9d\u6b21\u6839\u636e\u914d\u7f6e\u6587\u4ef6 <b>sample.yaml</b> \u4e2d\u7684\u6570\u636e\u6e20\u9053\u90e8\u5206\u4e2d\u7684\u6743\u9650\u914d\u7f6e\u53bb\u5bfc\u5165\u5386\u53f2\u6570\u636e\uff0c\u76ee\u524d\u5305\u542b\u6709\u4ea4\u6613\u65e5\u5386\u3001\u80a1\u7968\u5217\u8868\u3001\u5386\u53f2\u65e5K\u7ebf\u6570\u636e\u7b49\u3002\r\n\r\n### 5\u3001\u4e3b\u52a8\u66f4\u65b0\u6570\u636e\r\n\r\n```python\r\n# example_update_pystock.py\r\n\r\nimport stockman\r\n\r\nwith open(\"sample.yaml\", \"r\") as f:\r\n res = f.read()\r\nstock = stockman.Stock(res)\r\n\r\n\r\n# \u66f4\u65b0\u65e5K\u7ebf\u6570\u636e\r\ndef update_daily_k_data():\r\n stock.update_daily_k_data()\r\n\r\n# \u66f4\u65b0\u80a1\u7968\u5217\u8868\u6570\u636e\r\ndef update_stock_list_data():\r\n stock.update_stock_list_data()\r\n\r\n\r\nif __name__ == '__main__':\r\n update_daily_k_data()\r\n update_stock_list_data()\r\n```\r\n\r\n",
"bugtrack_url": null,
"license": "",
"summary": "A\u80a1\u91cf\u5316\u6570\u636e\u5de5\u5177",
"version": "0.0.2",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "03e7090517180064671b9e35cdc4f2918157b4ab564f7ea569e1a0eafd814106",
"md5": "cf8364cde18dff6d57df2dcba773ad3c",
"sha256": "48faa2e6aa4d33f717d1dc7e97fea14f21ef75ee354ca862713e693445344575"
},
"downloads": -1,
"filename": "stockman-0.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cf8364cde18dff6d57df2dcba773ad3c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<=3.11",
"size": 17148,
"upload_time": "2023-01-30T10:32:33",
"upload_time_iso_8601": "2023-01-30T10:32:33.994773Z",
"url": "https://files.pythonhosted.org/packages/03/e7/090517180064671b9e35cdc4f2918157b4ab564f7ea569e1a0eafd814106/stockman-0.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "74644bf6d860ad52d91522b953632e4a05f8e5555121750550f302f54cf4c58a",
"md5": "0ec3e19ecc6d1fde55da44741514b6c9",
"sha256": "3235429c66d8445e18ac2ff1e5655bbd794d1f72d745a7231d2b43e6a14657d6"
},
"downloads": -1,
"filename": "stockman-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "0ec3e19ecc6d1fde55da44741514b6c9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<=3.11",
"size": 13945,
"upload_time": "2023-01-30T10:32:36",
"upload_time_iso_8601": "2023-01-30T10:32:36.261285Z",
"url": "https://files.pythonhosted.org/packages/74/64/4bf6d860ad52d91522b953632e4a05f8e5555121750550f302f54cf4c58a/stockman-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-30 10:32:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "sml2h3",
"github_project": "stockman",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "stockman"
}