Administrator
2023-08-21 08adeb202828d464e2b61e9f2e7140a1d9380a00
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)
# 正在成交的订单撤单了
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):
    # 如果代码没有在目标代码中就不需要运行
@@ -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)