From d6b6be5eb2ae00a8ccf46bd7d53cd7d0c1e59c72 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期五, 24 十一月 2023 19:19:37 +0800 Subject: [PATCH] 初始化独立某些方法 --- huaxin_client/l1_client.py | 28 ++++++++++++++++++++++++++-- 1 files changed, 26 insertions(+), 2 deletions(-) diff --git a/huaxin_client/l1_client.py b/huaxin_client/l1_client.py index 476a6e0..d98a147 100644 --- a/huaxin_client/l1_client.py +++ b/huaxin_client/l1_client.py @@ -169,7 +169,26 @@ pass -def run(queue_l1_w_strategy_r): +__position_codes = set() + + +def __read_from_strategy(queue_l1_r_strategy_w: multiprocessing.Queue): + while True: + try: + data = queue_l1_r_strategy_w.get() + if type(data) == str: + data = json.loads(data) + if data["type"] == "set_position_codes": + codes = set(data["data"]) + global __position_codes + __position_codes = codes + except: + pass + finally: + time.sleep(1) + + +def run(queue_l1_w_strategy_r, queue_l1_r_strategy_w): logger_local_huaxin_l1.info("杩愯l1璁㈤槄鏈嶅姟") codes_sh = [] codes_sz = [] @@ -218,6 +237,7 @@ # level1_data_dict["002292"] = ( # "002292", 8.06, 9.96, 969500 * 100, time.time()) + threading.Thread(target=__read_from_strategy, args=(queue_l1_r_strategy_w,), daemon=True).start() # 绛夊緟绋嬪簭缁撴潫 while True: print("鏁伴噺", len(level1_data_dict)) @@ -229,13 +249,17 @@ # (浠g爜,鐜颁环,娑ㄥ箙,閲�,鏃堕棿) list_ = [level1_data_dict[k] for k in level1_data_dict] flist = [] + plist = [] for d in list_: if d[2] >= constant.L1_MIN_RATE: # 娑ㄥ箙灏忎簬5%鐨勯渶瑕佸垹闄� flist.append(d) + if d[0] in __position_codes: + plist.append(d) flist.sort(key=lambda x: x[2], reverse=True) datas = flist[:200] - codes = [x[0] for x in datas] + # 灏嗘寔浠撹偂鍔犲叆杩涘幓 + datas.extend(plist) print("浠g爜鏁伴噺:", len(datas)) logger_l2_codes_subscript.info("寮�濮�#鍗庨懌L1涓婁紶浠g爜锛氭暟閲�-{}", len(datas)) __upload_codes_info(queue_l1_w_strategy_r, datas) -- Gitblit v1.8.0