Administrator
2024-05-23 09991e316ce092d0b05a198aad9d58e78e06f69b
code_attribute/target_codes_manager.py
@@ -12,6 +12,10 @@
__valid_codes_cache = {}
# 正股到可转债代码的索引
__valid_underlying_code_map_cache = {}
# 可转债代码到正股代码的索引
__valid_cb_to_underlying_code_map_cache = {}
# 可转债昨日收盘价
__valid_pre_close_price_map_cache = {}
@@ -60,14 +64,16 @@
        __valid_codes_cache[day] = results
        __valid_underlying_code_map_cache[day] = {}
        __valid_pre_close_price_map_cache[day] = {}
        __valid_cb_to_underlying_code_map_cache[day] = {}
        for r in results:
            __valid_underlying_code_map_cache[day][r['underlying_symbol'].split('.')[1]] = r['sec_id']
            __valid_cb_to_underlying_code_map_cache[day][r['sec_id']] = r['underlying_symbol'].split('.')[1]
            __valid_pre_close_price_map_cache[day][r['sec_id']] = r['pre_close']
def get_subscript_codes():
def get_subscript_underlying_codes():
    """
    获取需要订阅的代码
    获取需要订阅的正股代码
    :return:
    """
    day = tool.get_now_date_str()
@@ -77,7 +83,19 @@
    return [x['underlying_symbol'].split('.')[1] for x in ffresults]
def get_underlying_code_map():
def get_subscript_cb_codes():
    """
    获取需要订阅的代码
    :return:
    """
    day = tool.get_now_date_str()
    if not __valid_codes_cache.get(day):
        load_valid_codes_info(tool.get_now_date_str())
    ffresults = __valid_codes_cache.get(tool.get_now_date_str())
    return [x['sec_id'] for x in ffresults]
def get_underlying_to_cb_code_map():
    """
    获取股票代码-可转债代码的map
    :param code:
@@ -90,13 +108,33 @@
    return __valid_underlying_code_map_cache.get(day)
def get_cb_to_underlying_code_map():
    """
    获取可转债代码-股票代码的map
    :param code:
    :return:
    """
    day = tool.get_now_date_str()
    if day not in __valid_cb_to_underlying_code_map_cache:
        load_valid_codes_info(day)
    return __valid_cb_to_underlying_code_map_cache.get(day)
def get_cb_code(code):
    """
    获取可转债代码
    :param code:
    :return:
    """
    map = get_underlying_code_map()
    map = get_underlying_to_cb_code_map()
    if map:
        return map.get(code)
    return None
def get_underlying_code(code):
    map = get_cb_to_underlying_code_map()
    if map:
        return map.get(code)
    return None