From 09ca670240a660b81d8dbed4c54efec96e99e811 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期二, 12 九月 2023 11:14:41 +0800
Subject: [PATCH] 下单日志优化

---
 huaxin_client/trade_client.py    |   15 +++++++--------
 trade/trade_huaxin.py            |    6 +++---
 huaxin_client/command_manager.py |   21 ++++++++++++---------
 trade/huaxin/huaxin_trade_api.py |    4 ----
 4 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/huaxin_client/command_manager.py b/huaxin_client/command_manager.py
index 5c846d9..aec509d 100644
--- a/huaxin_client/command_manager.py
+++ b/huaxin_client/command_manager.py
@@ -9,7 +9,8 @@
 
 from huaxin_client import socket_util
 from huaxin_client.client_network import SendResponseSkManager
-from log_module.log import logger_local_huaxin_trade_debug
+from log_module import async_log_util
+from log_module.log import logger_local_huaxin_trade_debug, logger_trade
 
 MSG_TYPE_HEART = "heart"
 # 鍛戒护淇℃伅
@@ -87,19 +88,21 @@
 
         try:
             data = result_json["data"]
-            print("鎺ユ敹鍐呭", result_json)
             request_id = result_json.get('request_id')
-            if not socket_util.is_client_params_sign_right(result_json):
-                print("绛惧悕閿欒")
-                # 绛惧悕鍑洪敊
-                SendResponseSkManager.send_error_response(_type, request_id, client_id,
-                                                          {"code": -1, "msg": "绛惧悕閿欒"})
-                return
+            # 鏆傛椂鍙栨秷绛惧悕
+            # if not socket_util.is_client_params_sign_right(result_json):
+            #     print("绛惧悕閿欒")
+            #     # 绛惧悕鍑洪敊
+            #     SendResponseSkManager.send_error_response(_type, request_id, client_id,
+            #                                               {"code": -1, "msg": "绛惧悕閿欒"})
+            #     return
 
             if _type == CLIENT_TYPE_TRADE:
                 # 浜ゆ槗
                 ctype = data["trade_type"]
+                async_log_util.info(logger_trade, f"浜ゆ槗寮�濮�")
                 cls.action_callback.OnTrade(client_id, request_id, sk, ctype, data)
+                async_log_util.info(logger_trade, f"浜ゆ槗缁撴潫")
             elif _type == CLIENT_TYPE_MONEY:
                 cls.action_callback.OnMoney(client_id, request_id, sk)
             elif _type == CLIENT_TYPE_DEAL_LIST:
@@ -127,7 +130,7 @@
                     val = pipe_strategy.recv()
                     if val:
                         val = json.loads(val)
-                        print("run_process_command", val)
+                        # print("run_process_command", val)
                         _type = val["type"]
                         threading.Thread(target=lambda: cls.process_command(_type, None, val), daemon=True).start()
                 except Exception as e:
diff --git a/huaxin_client/trade_client.py b/huaxin_client/trade_client.py
index 87bfb4b..f9241d9 100644
--- a/huaxin_client/trade_client.py
+++ b/huaxin_client/trade_client.py
@@ -15,7 +15,7 @@
 # 姝e紡璐﹀彿
 from huaxin_client.trade_transform_protocol import TradeRequest, TradeResponse
 from log_module import async_log_util
-from log_module.log import logger_local_huaxin_trade_debug, logger_system
+from log_module.log import logger_local_huaxin_trade_debug, logger_system, logger_trade
 
 UserID = '388000013349'
 # 鐧婚檰瀵嗙爜
@@ -89,6 +89,7 @@
             return
         if sinfo in self.__buy_sinfo_set:
             raise Exception(f'涓嬪崟璇锋眰宸茬粡鎻愪氦锛歿sinfo}')
+        async_log_util.info(logger_trade, f"{code}鍗庨懌鏈湴鐪熷疄涓嬪崟寮�濮�")
         async_log_util.info(logger_local_huaxin_trade_debug,
                             f"杩涘叆涔板叆鏂规硶锛歝ode-{code} sinfo-{sinfo}")
         self.__buy_sinfo_set.add(sinfo)
@@ -148,6 +149,7 @@
         # 缁橪2鍙戦�佹秷鎭�
         if l2pipe is not None:
             l2pipe.send(json.dumps({"type": "listen_volume", "data": {"code": code, "volume": count}}).encode('utf-8'))
+        async_log_util.info(logger_trade, f"{code}鍗庨懌鏈湴鐪熷疄涓嬪崟缁撴潫")
         return
 
     # 鎾や拱
@@ -711,7 +713,6 @@
     def OnRspQryOrder(self, pOrderField: "CTORATstpOrderField", pRspInfoField: "CTORATstpRspInfoField",
                       nRequestID: "int", bIsLast: "bool") -> "void":
         try:
-            print('鏌ヨ鎶ュ崟鍥炶皟', bIsLast)
             if nRequestID not in self.__temp_order_list_dict:
                 self.__temp_order_list_dict[nRequestID] = []
             if not bIsLast:
@@ -820,12 +821,15 @@
             price = data["price"]
             sinfo = data["sinfo"]
             local_order_id = data.get("local_order_id")
+
             if direction == 1:
+                async_log_util.info(logger_trade, f"{code}鍗庨懌鏈湴寮�濮嬩笅鍗�")
                 # 涔�
                 try:
                     req_rid_dict[sinfo] = (client_id, request_id, sk, local_order_id)
                     threading.Thread(target=lambda: self.__tradeSimpleApi.buy(code, volume, price, sinfo),
                                      daemon=True).start()
+                    async_log_util.info(logger_trade, f"{code}鍗庨懌鏈湴涓嬪崟绾跨▼缁撴潫")
                 except Exception as e:
                     send_response(json.dumps({"code": 1, "msg": str(e)}), TYPE_ORDER, client_id,
                                   request_id)
@@ -880,7 +884,7 @@
     def OnDealList(self, client_id, request_id, sk):
         async_log_util.info(logger_local_huaxin_trade_debug, f"璇锋眰鎴愪氦鍒楄〃锛歝lient_id-{client_id} request_id-{request_id}")
         try:
-            print("寮�濮嬭姹傛垚浜ゅ垪琛�")
+            # print("寮�濮嬭姹傛垚浜ゅ垪琛�")
             req_id = self.__tradeSimpleApi.list_traded_orders()
             req_rid_dict[req_id] = (client_id, request_id, sk)
         except Exception as e:
@@ -1047,9 +1051,7 @@
     if type == TYPE_ORDER or type == TYPE_CANCEL_ORDER:
         key = data["sinfo"]
     try:
-        print("traderapi_callback", req_rid_dict)
         if req_rid_dict and key in req_rid_dict:
-            print("API鍥炶皟")
             temp_params = req_rid_dict.pop(key)
             client_id, request_id = temp_params[0], temp_params[1]
             # 鏈湴璁㈠崟鍙�-绯荤粺璁㈠崟鍙锋槧灏�
@@ -1068,10 +1070,8 @@
                  "request_id": request_id})
 
             async_log_util.info(logger_local_huaxin_trade_debug, "API鍥炶皟缁撴潫 req_id-{} request_id-{}", req_id, request_id)
-            print("API鍥炶皟缁撴潫")
         else:
             async_log_util.info(logger_local_huaxin_trade_debug, "闈濧PI鍥炶皟 req_id-{}", req_id)
-            print("闈濧PI鍥炶皟")
             trade_response.OnTradeCallback({"type": "trade_callback", "data": {"code": 0, "data": data, "type": type}})
             # # 闈濧PI鍥炶皟
             # send_response(
@@ -1079,7 +1079,6 @@
             #     type,
             #     None,
             #     req_id)
-            print("闈濧PI缁撴潫")
     except Exception as e:
         logging.exception(e)
 
diff --git a/trade/huaxin/huaxin_trade_api.py b/trade/huaxin/huaxin_trade_api.py
index c4a76fd..76ff691 100644
--- a/trade/huaxin/huaxin_trade_api.py
+++ b/trade/huaxin/huaxin_trade_api.py
@@ -7,7 +7,6 @@
 import threading
 import time
 
-from huaxin_client import trade_client_server
 from huaxin_client.trade_transform_protocol import TradeRequest
 from log_module import async_log_util
 from log_module.log import hx_logger_trade_debug, hx_logger_trade_loop, hx_logger_trade_callback, logger_trade
@@ -34,9 +33,7 @@
             try:
                 val = pipe_trade.recv()
                 if val:
-                    print("鏀跺埌鏉ヨ嚜浜ゆ槗鏈嶅姟鍣ㄧ殑鏁版嵁锛�", val)
                     data_json = json.loads(val)
-                    print("鏀跺埌鏉ヨ嚜浜ゆ槗瀹㈡埛绔殑鏁版嵁锛�", data_json["type"])
                     # 澶勭悊鏁版嵁
                     type_ = data_json["type"]
                     if type_ == "response":
@@ -327,7 +324,6 @@
     timestamp = round(time.time() * 1000)
     if not sinfo:
         sinfo = f"b_{code}_{timestamp}"
-    print("瀹㈡埛绔�", ClientSocketManager.socket_client_dict)
     local_order_id = f"l_{code}_{direction}_{volume}_{timestamp}_{random.randint(0, 999)}"
     request_id = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
                            {"type": ClientSocketManager.CLIENT_TYPE_TRADE, "trade_type": 1,
diff --git a/trade/trade_huaxin.py b/trade/trade_huaxin.py
index 0b3a901..1f8311e 100644
--- a/trade/trade_huaxin.py
+++ b/trade/trade_huaxin.py
@@ -34,6 +34,7 @@
 
 # 閫氳繃閲忎笅鍗�,杩斿洖(浠g爜锛岃处鍙稩D锛岃鍗曞彿)
 def order_volume(code, price, count, last_data_index):
+    async_log_util.info(logger_trade, f"{code}涓嬪崟鏂规硶寮�濮�")
     price = round(float(price), 2)
     if code.find("00") != 0 and code.find("60") != 0:
         raise Exception("鍙敮鎸�00寮�澶翠笌60寮�澶寸殑浠g爜涓嬪崟")
@@ -45,9 +46,9 @@
     result = None
     blocking = False
     try:
+        async_log_util.info(logger_trade, f"{code}涓嬪崟寮�濮�")
         result = huaxin_trade_api.order(1, code, count, price, blocking=blocking)
-        print("鍗庨懌涓嬪崟鑰楁椂", time.time() - start_time)
-        async_log_util.info(hx_logger_trade_debug, f"{code}锛氫笅鍗曡�楁椂{round(time.time() - start_time, 3)}s")
+        async_log_util.info(logger_trade, f"{code}涓嬪崟缁撴潫")
     except Exception as e:
         if str(e).find("瓒呮椂") >= 0:
             # 姝ゅ鍑虹幇瓒呮椂锛岄渶瑕侀�氳繃璇诲彇濮旀墭鍒楄〃鏉ヨ缃鍗曚俊鎭�
@@ -56,7 +57,6 @@
             raise e
 
     if result:
-        print("涓嬪崟缁撴灉", result)
         if blocking:
             if result['code'] == 0:
                 result = result["data"]

--
Gitblit v1.8.0