From 8e8a2a2767e2784a6548cd07a2bf7dd6558e3f43 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期二, 19 三月 2024 18:50:14 +0800 Subject: [PATCH] S撤实现 --- l2/l2_transaction_data_manager.py | 95 +++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 91 insertions(+), 4 deletions(-) diff --git a/l2/l2_transaction_data_manager.py b/l2/l2_transaction_data_manager.py index 02a5ea8..e1214e8 100644 --- a/l2/l2_transaction_data_manager.py +++ b/l2/l2_transaction_data_manager.py @@ -5,18 +5,20 @@ from db import redis_manager from db.redis_manager_delegate import RedisUtils +from l2 import l2_log +from l2.huaxin import l2_huaxin_util from log_module import async_log_util -from log_module.log import hx_logger_l2_transaction_desc +from log_module.log import hx_logger_l2_transaction_desc, hx_logger_l2_transaction_sell_order from utils import tool -class HuaXinTransactionDataManager: +# 鎴愪氦鏁版嵁缁熻 +class HuaXinBuyOrderManager: __db = 0 __instance = None __redis_manager = redis_manager.RedisManager(0) - # 姝e湪鎴愪氦鐨勮鍗� __dealing_order_info_dict = {} @@ -25,7 +27,7 @@ def __new__(cls, *args, **kwargs): if not cls.__instance: - cls.__instance = super(HuaXinTransactionDataManager, cls).__new__(cls, *args, **kwargs) + cls.__instance = super(HuaXinBuyOrderManager, cls).__new__(cls, *args, **kwargs) cls.__load_datas() return cls.__instance @@ -82,3 +84,88 @@ return None +# 鍗栧崟缁熻鏁版嵁 +class HuaXinSellOrderStatisticManager: + # 鏈�杩戠殑澶у崠鍗曟垚浜わ紝鏍煎紡:{code:[鍗栧崟淇℃伅,...]} + __latest_sell_order_info_list_dict = {} + + # 澶у崟鍗栧崟鍙风殑闆嗗悎锛屾牸寮忥細{code:{鍗栧崟鍙穧} + __big_sell_order_ids_dict = {} + + # 澶у崠鍗曠殑鍗栧崟鍙�->鍗栧崟淇℃伅鏄犲皠 + __big_sell_order_info_dict = {} + + # 鏈�杩戠殑鍗栧崟, 鏍煎紡{code:[鍗栧崟鍙�,鎬绘墜鏁�,浠锋牸,锛�'寮�濮嬫椂闂�',涔板崟鍙凤級,锛�'缁撴潫鏃堕棿',涔板崟鍙凤級]} + __latest_sell_order_dict = {} + + @classmethod + def add_transaction_datas(cls, code, datas): + # q.append((data['SecurityID'], data['TradePrice'], data['TradeVolume'], + # data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'], + # data['SellNo'], data['ExecType'])) + if code not in cls.__latest_sell_order_info_list_dict: + cls.__latest_sell_order_info_list_dict[code] = [] + if code not in cls.__big_sell_order_ids_dict: + cls.__big_sell_order_ids_dict[code] = set() + if code not in cls.__big_sell_order_info_dict: + cls.__big_sell_order_info_dict[code] = {} + for d in datas: + cls.__latest_sell_order_info_list_dict[code].append(d) + if code not in cls.__latest_sell_order_dict: + cls.__latest_sell_order_dict[code] = [d[7], d[2], d[1], (d[3], d[6]), (d[3], d[6])] + else: + if cls.__latest_sell_order_dict[code][0] == d[7]: + cls.__latest_sell_order_dict[code][1] += d[2] + cls.__latest_sell_order_dict[code][2] = d[1] + cls.__latest_sell_order_dict[code][4] = (d[3], d[6]) + else: + # 灏佸瓨鏁版嵁锛岃绠楁柊璧风偣 + l2_log.info(code, hx_logger_l2_transaction_sell_order, f"{cls.__latest_sell_order_dict[code]}") + # 澶т簬50w鍔犲叆鍗栧崟 + info = cls.__latest_sell_order_dict[code] + if info[1] * info[2] >= 500000: + cls.__big_sell_order_ids_dict[code].add(info[0]) + cls.__big_sell_order_info_dict[code][info[0]] = info + + cls.__latest_sell_order_dict[code] = [d[7], d[2], d[1], (d[3], d[6]), (d[3], d[6])] + latest_time = l2_huaxin_util.convert_time(datas[-1][3], with_ms=True) + min_time = tool.trade_time_add_millionsecond(latest_time, -1000) + min_time_int = int(min_time.replace(":", "").replace(".", "")) + # 璁$畻鏈�杩�1s鐨勫ぇ鍗曟垚浜� + total_datas = cls.__latest_sell_order_info_list_dict.get(code) + start_index = 0 + + total_sell_info = [0, None] # 鎬昏祫閲�,寮�濮嬫垚浜や俊鎭�,缁撴潫鎴愪氦淇℃伅 + latest_sell_order_info = cls.__latest_sell_order_dict[code] + big_sell_order_ids = cls.__big_sell_order_ids_dict[code] + # print("澶у崠鍗�", big_sell_order_ids) + big_sell_orders = [] + temp_sell_order_ids = set() + for i in range(len(datas) - 1, -1, -1): + d = datas[i] + if d[7] != latest_sell_order_info[0]: + # 涓嶆槸鏈�杩戠殑鎴愪氦涓斾笉鏄ぇ鍗曠洿鎺ヨ繃婊� + if d[7] not in big_sell_order_ids: + continue + else: + if d[7] not in temp_sell_order_ids: + big_sell_orders.append(cls.__big_sell_order_info_dict[code].get(d[7])) + temp_sell_order_ids.add(d[7]) + else: + # 鏄渶杩戠殑浣嗕笉鏄ぇ鍗曢渶瑕佽繃婊� + if latest_sell_order_info[1] * latest_sell_order_info[2] < 500000: + continue + else: + if latest_sell_order_info[0] not in temp_sell_order_ids: + big_sell_orders.append(latest_sell_order_info) + temp_sell_order_ids.add(latest_sell_order_info[0]) + + if min_time_int > int(l2_huaxin_util.convert_time(d[3], with_ms=True).replace(":", "").replace(".", "")): + start_index = i + break + # 缁熻鏈�杩�1s鐨勫ぇ鍗栧崟鏁版嵁 + total_sell_info[0] += int(d[1] * d[2]) + big_sell_orders.reverse() + total_sell_info[1] = big_sell_orders + cls.__latest_sell_order_info_list_dict[code] = cls.__latest_sell_order_info_list_dict[code][start_index:] + return total_sell_info -- Gitblit v1.8.0