Administrator
2023-07-10 ad69cf29b884f99b1e22f383644cd706f392753d
trade/huaxin/trade_server.py
@@ -7,19 +7,15 @@
import socketserver
import threading
import time
import l2
import constant
from code_attribute import gpcode_manager
from l2 import l2_data_manager_new, l2_data_log
from l2.huaxin import l2_huaxin_util, huaxin_target_codes_manager
from l2.l2_data_util import local_today_datas
from log_module.log import logger_l2_error
from trade.huaxin.huaxin_log import logger_l2_orderdetail, logger_l2_transaction, logger_l2_upload, \
    logger_contact_debug, logger_trade_callback, logger_trade_debug
from l2 import l2_data_manager_new
from l2.huaxin import  huaxin_target_codes_manager
from log_module.log import hx_logger_l2_upload, hx_logger_contact_debug, hx_logger_trade_callback, \
    hx_logger_l2_orderdetail, hx_logger_l2_transaction, hx_logger_trade_debug
from trade.huaxin import huaxin_trade_api as trade_api, huaxin_trade_api, huaxin_trade_record_manager
from utils import socket_util, tool
from utils import socket_util
trade_data_request_queue = queue.Queue()
@@ -77,7 +73,7 @@
            else:
                data = skk.recv(1024 * 1024)
                data = buf + data.decode('utf-8')
            logger_l2_upload.info(f"读取数据耗时:{round((time.time() - start_time) * 1000, 1)}")
            hx_logger_l2_upload.info(f"读取数据耗时:{round((time.time() - start_time) * 1000, 1)}")
        return data, header_str
    def handle(self):
@@ -118,7 +114,7 @@
                                        # 记录活跃客户端
                                        trade_api.ClientSocketManager.heart(resultJSON['client_id'])
                                    else:
                                        logger_contact_debug.warning(f"接收到非心跳信息:{result}")
                                        hx_logger_contact_debug.warning(f"接收到非心跳信息:{result}")
                                except json.decoder.JSONDecodeError as e:
                                    if not result:
                                        sk.close()
@@ -140,7 +136,7 @@
                        data_json = data_json["data"]
                        type_ = data_json["type"]
                        # 记录交易反馈日志
                        logger_trade_callback.info(data_json)
                        hx_logger_trade_callback.info(data_json)
                        sk.sendall(json.dumps({"code": 0}).encode(encoding='utf-8'))
                        # 重新请求委托列表与资金
                        trade_data_request_queue.put_nowait({"type": "delegate_list"})
@@ -152,7 +148,7 @@
                        data = data_json["data"]
                        code = data["code"]
                        datas = data["data"]
                        logger_l2_orderdetail.info(f"{code}#{datas}")
                        hx_logger_l2_orderdetail.info(f"{code}#{datas}")
                        l2_data_manager_new.L2TradeDataProcessor.process_huaxin(code, datas)
                        sk.sendall(json.dumps({"code": 0}).encode(encoding='utf-8'))
@@ -160,7 +156,7 @@
                        data = data_json["data"]
                        code = data["code"]
                        datas = data["data"]
                        logger_l2_transaction.info(f"{code}#{datas}")
                        hx_logger_l2_transaction.info(f"{code}#{datas}")
                        sk.sendall(json.dumps({"code": 0}).encode(encoding='utf-8'))
                    # ------客户端请求接口-------
                    elif data_json["type"] == 'buy':
@@ -291,7 +287,7 @@
            data = trade_data_request_queue.get()
            if data:
                type_ = data["type"]
                logger_trade_debug.info(f"获取交易数据开始:{type_}")
                hx_logger_trade_debug.info(f"获取交易数据开始:{type_}")
                if type_ == "delegate_list":
                    data = huaxin_trade_api.get_delegate_list(False)
@@ -312,9 +308,9 @@
                        data = dataJSON["data"]["data"]
                        huaxin_trade_record_manager.DealRecordManager.add(data)
                logger_trade_debug.info(f"获取交易数据成功:{type_}")
                hx_logger_trade_debug.info(f"获取交易数据成功:{type_}")
        except Exception as e:
            logger_trade_debug.exception(e)
            hx_logger_trade_debug.exception(e)
        finally:
            # 有1s的间隔
            time.sleep(1)