From 9d39b293bde97f31f522010373aad1dd3f654c07 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 25 七月 2024 17:23:07 +0800
Subject: [PATCH] 策略修改

---
 code_attribute/target_codes_manager.py |   47 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/code_attribute/target_codes_manager.py b/code_attribute/target_codes_manager.py
index 0964f40..d4d0e92 100644
--- a/code_attribute/target_codes_manager.py
+++ b/code_attribute/target_codes_manager.py
@@ -12,6 +12,10 @@
 __valid_codes_cache = {}
 # 姝h偂鍒板彲杞�轰唬鐮佺殑绱㈠紩
 __valid_underlying_code_map_cache = {}
+
+# 鍙浆鍊轰唬鐮佸埌姝h偂浠g爜鐨勭储寮�
+__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():
     """
-    鑾峰彇闇�瑕佽闃呯殑浠g爜
+    鑾峰彇闇�瑕佽闃呯殑姝h偂浠g爜
     :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():
+    """
+    鑾峰彇闇�瑕佽闃呯殑浠g爜
+    :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():
     """
     鑾峰彇鑲$エ浠g爜-鍙浆鍊轰唬鐮佺殑map
     :param code:
@@ -90,13 +108,33 @@
     return __valid_underlying_code_map_cache.get(day)
 
 
+def get_cb_to_underlying_code_map():
+    """
+    鑾峰彇鍙浆鍊轰唬鐮�-鑲$エ浠g爜鐨刴ap
+    :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
@@ -134,6 +172,7 @@
     return str(tool.to_price(price_close * decimal.Decimal("0.8"), "0.000"))
 
 
+
 if __name__ == '__main__':
     load_valid_codes_info()
     print(get_limit_up_price("110060"), get_limit_down_price("110060"))

--
Gitblit v1.8.0