feat: 新增股票基础数据获取模块 stock_basic

- 新增 get_stock_basic 和 sync_all_stocks 函数
- 完善 Tushare 数据获取模块体系
- 测试用例重构:从 Mock 改为真实 API 调用
- 更新 API 文档,添加接口使用示例
- 更新开发规范:添加 Mock 使用规范
This commit is contained in:
2026-01-31 04:30:29 +08:00
parent e625a53162
commit 38e78a5326
10 changed files with 341 additions and 339 deletions

View File

@@ -44,4 +44,83 @@ pre_close float 昨收价【除权价】
change float 涨跌额
pct_chg float 涨跌幅 【基于除权后的昨收计算的涨跌幅:(今收-除权昨收)/除权昨收 】
vol float 成交量 (手)
amount float 成交额 (千元)
amount float 成交额 (千元)
接口用例
#取000001的前复权行情
df = ts.pro_bar(ts_code='000001.SZ', adj='qfq', start_date='20180101', end_date='20181011')
ts_code trade_date open high low close \
trade_date
20181011 000001.SZ 20181011 1085.71 1097.59 1047.90 1065.19
20181010 000001.SZ 20181010 1138.65 1151.61 1121.36 1128.92
20181009 000001.SZ 20181009 1130.00 1155.93 1122.44 1140.81
20181008 000001.SZ 20181008 1155.93 1165.65 1128.92 1128.92
20180928 000001.SZ 20180928 1164.57 1217.51 1164.57 1193.74
#取上证指数行情数据
df = ts.pro_bar(ts_code='000001.SH', asset='I', start_date='20180101', end_date='20181011')
In [10]: df.head()
Out[10]:
ts_code trade_date close open high low \
0 000001.SH 20181011 2583.4575 2643.0740 2661.2859 2560.3164
1 000001.SH 20181010 2725.8367 2723.7242 2743.5480 2703.0626
2 000001.SH 20181009 2721.0130 2713.7319 2734.3142 2711.1971
3 000001.SH 20181008 2716.5104 2768.2075 2771.9384 2710.1781
4 000001.SH 20180928 2821.3501 2794.2644 2821.7553 2791.8363
pre_close change pct_chg vol amount
0 2725.8367 -142.3792 -5.2233 197150702.0 170057762.5
1 2721.0130 4.8237 0.1773 113485736.0 111312455.3
2 2716.5104 4.5026 0.1657 116771899.0 110292457.8
3 2821.3501 -104.8397 -3.7159 149501388.0 141531551.8
4 2791.7748 29.5753 1.0594 134290456.0 125369989.4
#均线
df = ts.pro_bar(ts_code='000001.SZ', start_date='20180101', end_date='20181011', ma=[5, 20, 50])
Tushare pro_bar接口的均价和均量数据是动态计算想要获取某个时间段的均线必须要设置start_date日期大于最大均线的日期数然后自行截取想要日期段。例如想要获取20190801开始的3日均线必须设置start_date='20190729'然后剔除20190801之前的日期记录。
#换手率tor量比vr
df = ts.pro_bar(ts_code='000001.SZ', start_date='20180101', end_date='20181011', factors=['tor', 'vr'])
- 基础信息https://tushare.pro/document/2?doc_id=25
接口stock_basic可以通过数据工具调试和查看数据
描述:获取基础信息数据,包括股票代码、名称、上市日期、退市日期等
权限2000积分起。此接口是基础信息调取一次就可以拉取完建议保存倒本地存储后使用
输入参数
名称 类型 必选 描述
ts_code str N TS股票代码
name str N 名称
market str N 市场类别 (主板/创业板/科创板/CDR/北交所)
list_status str N 上市状态 L上市 D退市 P暂停上市 G过会未交易默认是L
exchange str N 交易所 SSE上交所 SZSE深交所 BSE北交所
is_hs str N 是否沪深港通标的N否 H沪股通 S深股通
输出参数
名称 类型 默认显示 描述
ts_code str Y TS代码
symbol str Y 股票代码
name str Y 股票名称
area str Y 地域
industry str Y 所属行业
fullname str N 股票全称
enname str N 英文全称
cnspell str Y 拼音缩写
market str Y 市场类型(主板/创业板/科创板/CDR
exchange str N 交易所代码
curr_type str N 交易货币
list_status str N 上市状态 L上市 D退市 G过会未交易 P暂停上市
list_date str Y 上市日期
delist_date str N 退市日期
is_hs str N 是否沪深港通标的N否 H沪股通 S深股通
act_name str Y 实控人名称
act_ent_type str Y 实控人企业性质
说明旧版上的PE/PB/股本等字段,请在行情接口“每日指标”中获取。