From e355406604ed8a2c9576322b68546e5721e1c141 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 19 五月 2025 17:14:05 +0800 Subject: [PATCH] L2成交大单提取 --- huaxin_client/l2_client_test.py | 23 +++++++++++++---------- 1 files changed, 13 insertions(+), 10 deletions(-) diff --git a/huaxin_client/l2_client_test.py b/huaxin_client/l2_client_test.py index 92fece3..447bff5 100644 --- a/huaxin_client/l2_client_test.py +++ b/huaxin_client/l2_client_test.py @@ -67,9 +67,10 @@ def get_big_sell_orders(self): return self.__big_sell_orders - def add_transaction_data_for_accurate(self, item): + def add_transaction_data_for_accurate(self, item, big_order_money_threshold=299e4): """ 鑾峰彇绮剧‘鐨勪拱鍗曚俊鎭� + @param big_order_money_threshold: 澶у崟闃堝�� @param data: @return: """ @@ -77,13 +78,14 @@ def format_timestamp(timestamp): time_str = str(timestamp) return int(time_str[:5] if time_str[0] == '9' else time_str[:6]) + money = round(item[2] * item[3]) volume = item[3] price = item[2] order_time = item[4] if item[0] not in self.__big_accurate_buy_order_dict: - # (涔板崟鍙�, 閲�, 閲戦, 鏃堕棿, 鏈�鏂版垚浜や环鏍�) - self.__big_accurate_buy_order_dict[item[0]] = [item[0], 0, 0, order_time, price] + # (涔板崟鍙�, 閲�, 閲戦, 鏃堕棿, 鏈�鏂版垚浜や环鏍�, 寮�濮嬫垚浜ゆ椂闂�, 寮�濮嬫垚浜や环鏍�) + self.__big_accurate_buy_order_dict[item[0]] = [item[0], 0, 0, order_time, price, order_time, price] buy_order_info = self.__big_accurate_buy_order_dict[item[0]] buy_order_info[1] += volume buy_order_info[2] += money @@ -94,7 +96,7 @@ # 鏈夊彲鑳芥槸澶у崟鎴愪氦瀹屾垚锛� 鍒ゆ柇涓婁釜璁㈠崟鏄惁鏄ぇ鍗� last_buy_order = self.__big_accurate_buy_order_dict.get(self.__latest_buy_order[0]) - if last_buy_order[2] > 299e4: + if last_buy_order[2] > big_order_money_threshold: self.big_accurate_buy_order_queue.put_nowait(last_buy_order) # 濡傛灉鏁版嵁杩囧闇�瑕佺Щ闄よ繃闀挎椂闂寸殑灏忛噾棰濇暟鎹� @@ -115,8 +117,8 @@ # 缁熻鍗栧崟 if item[1] not in self.__big_accurate_sell_order_dict: - # (鍗栧崟鍙�, 閲�, 閲戦, 鏃堕棿, 鏈�鏂版垚浜や环鏍�) - self.__big_accurate_sell_order_dict[item[1]] = [item[1], 0, 0, order_time, price] + # (鍗栧崟鍙�, 閲�, 閲戦, 鏃堕棿, 鏈�鏂版垚浜や环鏍�, 寮�濮嬫垚浜ゆ椂闂�, 寮�濮嬫垚浜や环鏍�) + self.__big_accurate_sell_order_dict[item[1]] = [item[1], 0, 0, order_time, price, order_time, price] sell_order_info = self.__big_accurate_sell_order_dict[item[1]] sell_order_info[1] += volume sell_order_info[2] += money @@ -125,14 +127,15 @@ if self.__latest_sell_order and self.__latest_sell_order[0] != item[1]: # 鏈夊彲鑳芥槸澶у崟鎴愪氦瀹屾垚锛� 鍒ゆ柇涓婁釜璁㈠崟鏄惁鏄ぇ鍗� last_sell_order = self.__big_accurate_sell_order_dict.get(self.__latest_sell_order[0]) - if last_sell_order[2] > 299e4: + if last_sell_order[2] > big_order_money_threshold: self.big_accurate_sell_order_queue.put_nowait(last_sell_order) # 濡傛灉鏁版嵁杩囧闇�瑕佺Щ闄よ繃闀挎椂闂寸殑灏忛噾棰濇暟鎹� accurate_sell_count = len(self.__big_accurate_sell_order_dict.keys()) if accurate_sell_count > 10000 and accurate_sell_count - self.__last_accurate_sell_count > 2000: # 瓒呰繃1w鏉℃暟鎹笖鏂板2000鏉℃暟鎹� # 瓒呰繃1w鏉℃暟鎹氨瑕佺Щ闄�30鍒嗛挓涔嬪墠鐨勬暟鎹� - now_time_int = int(tool.trade_time_add_second(l2_huaxin_util.convert_time(order_time), -3600).replace(":", "")) + now_time_int = int( + tool.trade_time_add_second(l2_huaxin_util.convert_time(order_time), -3600).replace(":", "")) try: remove_order_nos = [x for x in self.__big_accurate_sell_order_dict if now_time_int > format_timestamp( @@ -143,7 +146,7 @@ finally: self.__last_accurate_sell_count = len(self.__big_accurate_sell_order_dict.keys()) - def add_transaction_data(self, data): + def add_transaction_data(self, data, big_order_money_threshold=299e4): item = (data["BuyNo"], data["SellNo"], data["TradePrice"], data["TradeVolume"], data["OrderTime"]) # item = {"SecurityID": pTransaction['SecurityID'], "TradePrice": pTransaction['TradePrice'], # "TradeVolume": pTransaction['TradeVolume'], @@ -157,7 +160,7 @@ order_time = item[4] if self.accurate_buy: - self.add_transaction_data_for_accurate(item) + self.add_transaction_data_for_accurate(item, big_order_money_threshold=big_order_money_threshold) if not self.__latest_buy_order: # (涔板崟鍙�, 閲�, 閲戦, 鏃堕棿, 鏈�鏂版垚浜や环鏍�) -- Gitblit v1.8.0