From a5e106a72ac37325231ed3236d00023eaf9417c5 Mon Sep 17 00:00:00 2001 From: Favo Yang Date: Thu, 14 Dec 2023 01:17:24 +0800 Subject: [PATCH 1/2] feat: improve get_stock_type detection and support BSE --- easyquotation/helpers.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) 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" From 5641a26b3424c69fc45d125e92ed1eaf069b7401 Mon Sep 17 00:00:00 2001 From: Favo Yang <125390+favoyang@users.noreply.github.com> Date: Sun, 15 Dec 2024 02:17:42 +0800 Subject: [PATCH 2/2] fix: BSE code prefixes --- easyquotation/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/easyquotation/helpers.py b/easyquotation/helpers.py index d9184e9..4e34c30 100644 --- a/easyquotation/helpers.py +++ b/easyquotation/helpers.py @@ -34,7 +34,7 @@ def get_stock_type(stock_code): :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") + bj_head = ("43", "83", "87", "92") sh_head = ("5", "6", "7", "9", "110", "113", "118", "132", "204") if stock_code.startswith(("sh", "sz", "zz", "bj")): return stock_code[:2]