证券代码代码对应的市场代码可以参考网站:
https://wiki.mbalib.com/wiki/%E8%AF%81%E5%88%B8%E4%BB%A3%E7%A0%81
因此可以使用如下函数:
def get_market(code_string):market_code_dict = {"600": "SH", # 沪市A股"601": "SH", # 沪市A股"603": "SH", # 沪市A股"605": "SH", # 沪市A股"000": "SZ", # 深市A股"001": "SZ", # 深市A股"003": "SZ", # 深市A股"688": "IB", # 科创板"300": "SZ", # 创业板(旧)"301": "SZ", # 创业板"002": "SZ", # 中小板}return market_code_dict.get(code_string[:3], None)
示例代码
def get_market(code_string):market_code_dict = {"600": "SH", # 沪市A股"601": "SH", # 沪市A股"603": "SH", # 沪市A股"605": "SH", # 沪市A股"000": "SZ", # 深市A股"001": "SZ", # 深市A股"003": "SZ", # 深市A股"688": "IB", # 科创板"300": "SZ", # 创业板(旧)"301": "SZ", # 创业板"002": "SZ", # 中小板}return market_code_dict.get(code_string[:3], None)def main():code_list = ['603601', '300992', '301002', '688590', '300037', '301040', '002959', '605133', '688328', '603833','300894', '688096', '603901', '600782', '600068', '600019', '600518', '600795', '000528', '600219','600600', '600368', '600018', '600028', '000063', '600428', '600269', '000572', '600598', '600104','000709', '600017', '600227']for _code in code_list:market_code = get_market(_code)if market_code:print(_code + ".{}".format(market_code))if __name__ == '__main__':main()