diff --git a/easyquotation/helpers.py b/easyquotation/helpers.py index 11ba7cc..d9184e9 100644 --- a/easyquotation/helpers.py +++ b/easyquotation/helpers.py @@ -2,6 +2,7 @@ import json import os import re + import requests STOCK_CODE_PATH = os.path.join(os.path.dirname(__file__), "stock_codes.conf") @@ -27,15 +28,18 @@ def get_stock_codes(realtime=False): def get_stock_type(stock_code): """判断股票ID对应的证券市场 匹配规则 - ['50', '51', '60', '90', '110'] 为 sh - ['00', '13', '18', '15', '16', '18', '20', '30', '39', '115'] 为 sz - ['5', '6', '9'] 开头的为 sh, 其余为 sz - :param stock_code:股票ID, 若以 'sz', 'sh' 开头直接返回对应类型,否则使用内置规则判断 - :return 'sh' or 'sz'""" - assert type(stock_code) is str, "stock code need str type" - sh_head = ("50", "51", "60", "90", "110", "113", "118", - "132", "204", "5", "6", "9", "7") - if stock_code.startswith(("sh", "sz", "zz")): + ['4', '8'] 为 bj + ['5', '6', '7', '9', '110', '113', '118', '132', '204'] 为 sh + 其余为 sz + :param stock_code:股票ID, 若以 'sz', 'sh', 'bj' 开头直接返回对应类型,否则使用内置规则判断 + :return 'bj', 'sh' or 'sz'""" + assert isinstance(stock_code, str), "stock code need str type" + bj_head = ("4", "8") + sh_head = ("5", "6", "7", "9", "110", "113", "118", "132", "204") + if stock_code.startswith(("sh", "sz", "zz", "bj")): return stock_code[:2] - else: - return "sh" if stock_code.startswith(sh_head) else "sz" + elif stock_code.startswith(bj_head): + return "bj" + elif stock_code.startswith(sh_head): + return "sh" + return "sz"