From 08adeb202828d464e2b61e9f2e7140a1d9380a00 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期一, 21 八月 2023 18:22:32 +0800
Subject: [PATCH] G撤

---
 huaxin_client/l2_data_manager.py |   51 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/huaxin_client/l2_data_manager.py b/huaxin_client/l2_data_manager.py
index 1c37172..aedab20 100644
--- a/huaxin_client/l2_data_manager.py
+++ b/huaxin_client/l2_data_manager.py
@@ -10,7 +10,7 @@
 from huaxin_client.client_network import SendResponseSkManager
 
 # 娲诲姩鏃堕棿
-from log_module.log import logger_local_huaxin_l2_upload, logger_local_huaxin_l2_error
+from log_module.log import logger_local_huaxin_l2_error
 
 order_detail_upload_active_time_dict = {}
 transaction_upload_active_time_dict = {}
@@ -19,6 +19,21 @@
 tmep_transaction_queue_dict = {}
 target_codes = set()
 common_queue = queue.Queue()
+trading_canceled_queue = queue.Queue()
+# 涔板叆璁㈠崟鍙风殑瀛楀吀
+buy_order_nos_dict = {}
+# 鏈�杩戠殑澶у崟鎴愪氦鍗曞彿
+latest_big_order_transaction_order_dict = {}
+
+
+# 鑾峰彇鏈�杩戠殑澶у崟鎴愪氦璁㈠崟鍙�
+def get_latest_transaction_order_no(code):
+    return latest_big_order_transaction_order_dict.get(code)
+
+
+# 姝e湪鎴愪氦鐨勮鍗曟挙鍗曚簡
+def trading_order_canceled(code_, order_no):
+    trading_canceled_queue.put((code_, order_no))
 
 
 # 娣诲姞濮旀墭璇︽儏
@@ -37,6 +52,11 @@
     #                 "OrderTime": pOrderDetail['OrderTime'], "MainSeq": pOrderDetail['MainSeq'],
     #                 "SubSeq": pOrderDetail['SubSeq'], "OrderNO": pOrderDetail['OrderNO'],
     #                 "OrderStatus": pOrderDetail['OrderStatus'].decode()}
+    if data['Side'] == "1":
+        # 璁板綍鎵�鏈変拱鍏ョ殑璁㈠崟鍙�
+        if data['SecurityID'] not in buy_order_nos_dict:
+            buy_order_nos_dict[data['SecurityID']] = set()
+        buy_order_nos_dict[data['SecurityID']].add(data['OrderNO'])
 
     tmep_order_detail_queue_dict[code].put(
         (data['SecurityID'], data['Price'], data['Volume'], data['Side'], data['OrderType'], data['OrderTime'],
@@ -48,7 +68,6 @@
     code = data["SecurityID"]
     if code not in tmep_transaction_queue_dict:
         tmep_transaction_queue_dict[code] = queue.Queue()
-
     # 鍘熸潵鐨勬牸寮�
     #  item = {"SecurityID": pTransaction['SecurityID'], "TradePrice": pTransaction['TradePrice'],
     #                     "TradeVolume": pTransaction['TradeVolume'],
@@ -56,6 +75,11 @@
     #                     "SubSeq": pTransaction['SubSeq'], "BuyNo": pTransaction['BuyNo'], "SellNo": pTransaction['SellNo'],
     #                     "ExecType": pTransaction['ExecType'].decode()}
 
+    # 鍒ゆ柇鏄惁涓哄ぇ鍗曟垚浜�
+    code = data['SecurityID']
+    if code in buy_order_nos_dict:
+        if data['BuyNo'] in buy_order_nos_dict[code]:
+            latest_big_order_transaction_order_dict[code] = data['BuyNo']
     tmep_transaction_queue_dict[code].put((data['SecurityID'], data['TradePrice'], data['TradeVolume'],
                                            data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'],
                                            data['SellNo'], data['ExecType']))
@@ -114,15 +138,16 @@
     # print("璇锋眰寮�濮�", uid, len(datas), len(fdata), f"{fdata[:20]}...{fdata[-20:]}")
     result = None
     start_time = time.time()
-    logger_local_huaxin_l2_upload.info(f"{code} 涓婁紶鏁版嵁寮�濮�-{_type}")
+    # logger_local_huaxin_l2_upload.info(f"{code} 涓婁紶鏁版嵁寮�濮�-{_type}")
     try:
         result = send_response(key, fdata.encode('utf-8'))
     except Exception as e:
         logging.exception(e)
     finally:
+        pass
         # print("璇锋眰缁撴潫", uid, result)
-        logger_local_huaxin_l2_upload.info(
-            f"{code} 涓婁紶鏁版嵁鑰楁椂-{_type}锛� {round((time.time() - start_time) * 1000, 1)} 鏁版嵁閲�:{len(datas)}")
+        # logger_local_huaxin_l2_upload.info(
+        #     f"{code} 涓婁紶鏁版嵁鑰楁椂-{_type}锛� {round((time.time() - start_time) * 1000, 1)} 鏁版嵁閲�:{len(datas)}")
     # print("涓婁紶缁撴灉", result)
 
 
@@ -183,6 +208,17 @@
             logger_local_huaxin_l2_error.error(f"涓婁紶鏅�氭暟鎹嚭閿欙細{str(e)}")
 
 
+def __run_upload_trading_canceled():
+    print("__run_upload_trading_canceled")
+    while True:
+        try:
+            temp = trading_canceled_queue.get()
+            upload_data(temp[0], "trading_order_canceled", temp[1])
+        except Exception as e:
+            logger_local_huaxin_l2_error.exception(e)
+            logger_local_huaxin_l2_error.error(f"涓婁紶鏅�氭暟鎹嚭閿欙細{str(e)}")
+
+
 # 杩愯涓婁紶浠诲姟
 def run_upload_task(code):
     # 濡傛灉浠g爜娌℃湁鍦ㄧ洰鏍囦唬鐮佷腑灏变笉闇�瑕佽繍琛�
@@ -203,6 +239,11 @@
     t.start()
 
 
+def run_upload_trading_canceled():
+    t = threading.Thread(target=lambda: __run_upload_trading_canceled(), daemon=True)
+    t.start()
+
+
 if __name__ == "__main__":
     code = "603809"
     target_codes.add(code)

--
Gitblit v1.8.0