fix: 完善市场代码判断逻辑,增加北交所支持
市场代码规则: - 6开头 → SH(上海) - 0、3开头 → SZ(深圳) - 4、8开头 → BJ(北京)
This commit is contained in:
@@ -67,14 +67,28 @@ def load_stock_list():
|
||||
|
||||
|
||||
def get_stock_codes_with_suffix(df):
|
||||
"""将股票代码转换为tushare格式(添加后缀)"""
|
||||
"""将股票代码转换为tushare格式(添加后缀)
|
||||
|
||||
市场代码规则:
|
||||
- 6开头 → SH(上海)
|
||||
- 0、3开头 → SZ(深圳)
|
||||
- 4、8开头 → BJ(北京)
|
||||
"""
|
||||
codes = []
|
||||
for code in df['code']:
|
||||
code = str(code).zfill(6) # 补零到6位
|
||||
if code.startswith('6'):
|
||||
first_digit = code[0]
|
||||
|
||||
if first_digit == '6':
|
||||
ts_code = f"{code}.SH"
|
||||
else:
|
||||
elif first_digit in ('0', '3'):
|
||||
ts_code = f"{code}.SZ"
|
||||
elif first_digit in ('4', '8'):
|
||||
ts_code = f"{code}.BJ"
|
||||
else:
|
||||
# 未知市场,默认深圳
|
||||
ts_code = f"{code}.SZ"
|
||||
|
||||
codes.append(ts_code)
|
||||
return codes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user