From 6e71fbcb119e7068ba35380edaa5cc66e7c71f1b Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期四, 27 十月 2022 16:21:05 +0800 Subject: [PATCH] 交易体系完善 --- l2_data_util.py | 50 ++++++++++++++++++++++++++++++++++---------------- 1 files changed, 34 insertions(+), 16 deletions(-) diff --git a/l2_data_util.py b/l2_data_util.py index 4fe0481..d7b3c8a 100644 --- a/l2_data_util.py +++ b/l2_data_util.py @@ -7,10 +7,10 @@ import datetime import json import time +from tool import async_call import l2_data_manager import tool -from trade_gui import async_call def run_time(): @@ -134,19 +134,20 @@ return True sell_datas = local_today_num_operate_map.get( "{}-{}-{}".format(sell_cancel_data["val"]["num"], "2", sell_cancel_data["val"]["price"])) - for i in range(0, len(sell_datas)): - data = sell_datas[i] - if int(data["val"]["operateType"]) != 2: - continue - if int(data["val"]["num"]) != int(sell_cancel_data["val"]["num"]): - continue - if min_space == 0 and max_space == 0: - # 鏈鍐� - if compare_time(data["val"]["time"], min_time) == 0: + if sell_datas: + for i in range(0, len(sell_datas)): + data = sell_datas[i] + if int(data["val"]["operateType"]) != 2: + continue + if int(data["val"]["num"]) != int(sell_cancel_data["val"]["num"]): + continue + if min_space == 0 and max_space == 0: + # 鏈鍐� + if compare_time(data["val"]["time"], min_time) == 0: + return data["index"] < target_data["index"] + # 鏁版嵁鍦ㄦ纭殑鍖洪棿 + elif compare_time(data["val"]["time"], min_time) > 0 and compare_time(data["val"]["time"], max_time) <= 0: return data["index"] < target_data["index"] - # 鏁版嵁鍦ㄦ纭殑鍖洪棿 - elif compare_time(data["val"]["time"], min_time) > 0 and compare_time(data["val"]["time"], max_time) <= 0: - return data["index"] < target_data["index"] return False @@ -180,6 +181,22 @@ break +# 淇濆瓨l2鏈�鏂版暟鎹殑澶у皬 +@async_call +def save_l2_latest_data_number(code, num): + redis = l2_data_manager._redisManager.getRedis() + redis.setex("l2_latest_data_num-{}".format(code), 3, num) + + +# 鑾峰彇鏈�鏂版暟鎹潯鏁� +def get_l2_latest_data_number(code): + redis = l2_data_manager._redisManager.getRedis() + num = redis.get("l2_latest_data_num-{}".format(code)) + if num is not None: + return int(num) + return None + + # l2鏁版嵁鎷兼帴宸ュ叿 class L2DataConcatUtil: @@ -190,7 +207,7 @@ self.code = code def __get_data_identity(self, data_): - data=data_["val"] + data = data_["val"] return "{}-{}-{}-{}-{}-{}".format(data.get("time"), data.get("num"), data.get("price"), data.get("operateType"), data.get("cancelTime"), data.get("cancelTimeUnit")) @@ -215,7 +232,8 @@ def get_add_datas(self): # 鏌ヨ褰撳墠鏁版嵁鏄惁鍦ㄦ渶杩戜竴娆℃暟鎹箣鍚� if self.last_datas and self.datas: - if int(self.datas[-1]["val"]["time"].replace(":", "")) - int(self.last_datas[-1]["val"]["time"].replace(":", "")) < 0: + if int(self.datas[-1]["val"]["time"].replace(":", "")) - int( + self.last_datas[-1]["val"]["time"].replace(":", "")) < 0: return [] # 鑾峰彇鎷兼帴鐐� @@ -254,7 +272,7 @@ def load_data(datas): data_list = [] for data in datas: - data_list.append({"val":{"time": data}}) + data_list.append({"val": {"time": data}}) return data_list # 涓嶅尮閰� -- Gitblit v1.8.0