Administrator
2023-08-15 cc6fcdf8e3792d17ccf436fb2f03fcda57b0f06a
++++++++++++++++
bug修复-
3个文件已修改
86 ■■■■■ 已修改文件
log_module/log.py 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.py 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/trade_api_server.py 64 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
log_module/log.py
@@ -1,6 +1,7 @@
"""
日志
"""
import logging
import os
import sys
from loguru import logger
@@ -293,5 +294,7 @@
def close_print():
    os.close(1)
    os.open('/dev/null', os.O_WRONLY)
    logging.basicConfig(level=logging.ERROR)
    if not constant.is_windows():
        os.close(1)
        os.open('/dev/null', os.O_WRONLY)
main.py
@@ -59,6 +59,19 @@
if __name__ == '__main__':
    st1 = "#"
    for i in range(1000):
        st1 += "#"
    st2 = "#"
    for i in range(10000):
        st2 += "#"
    start_time = time.time()
    print(st1)
    print("耗时1:", time.time() - start_time)
    start_time = time.time()
    print(st2)
    print("耗时2:", time.time() - start_time)
    log.close_print()
    # 策略与server间的通信
    pss_server, pss_strategy = multiprocessing.Pipe()
@@ -85,7 +98,7 @@
    l2Process = multiprocessing.Process(target=huaxin_api.l2_client.run, args=(ptl2_l2, psl2_l2,))
    l2Process.start()
    #
    tradeProcess = multiprocessing.Process(target=huaxin_api.trade_client.run,args=(ptl2_trade, pst_trade,))
    tradeProcess = multiprocessing.Process(target=huaxin_api.trade_client.run, args=(ptl2_trade, pst_trade,))
    tradeProcess.start()
    # L1订阅数据
    huaxin_api.l1_client.run_async(pl1t_l1)
trade/huaxin/trade_api_server.py
@@ -420,58 +420,30 @@
        super().finish()
test_data = [('600829', 60024, 8.33), ('603610', 40000, 12.5), ('002945', 28474, 17.56), ('600689', 47438, 10.54),
             ('002907', 26288, 19.02), ('002999', 60680, 8.24), ('601136', 18939, 26.4), ('603190', 16062, 31.13),
             ('001231', 21844, 22.89), ('605138', 50454, 9.91), ('603963', 37850, 13.21), ('603029', 21608, 23.14),
             ('001222', 29833, 16.76), ('002898', 34868, 14.34), ('603106', 58754, 8.51), ('600361', 80775, 6.19),
             ('600280', 92251, 5.42), ('002370', 100402, 4.98), ('002640', 124378, 4.02), ('002758', 37821, 13.22),
             ('000953', 82237, 6.08), ('002747', 20602, 24.27), ('002146', 191571, 2.61), ('601696', 39620, 12.62),
             ('000411', 31566, 15.84), ('603220', 26810, 18.65), ('000739', 26137, 19.13), ('600575', 174825, 2.86),
             ('600257', 72464, 6.9), ('003042', 22686, 22.04), ('601059', 24522, 20.39), ('603667', 33400, 14.97)]
def __set_target_codes(pipe_l2):
    while True:
        try:
            datas = test_data
            root_data = {"data": {"type": ClientSocketManager.CLIENT_TYPE_CMD_L2,
                                  "data": datas},
                         "request_id": f"{ClientSocketManager.CLIENT_TYPE_CMD_L2}_{round(time.time() * 1000)}"}
            root_data = socket_util.encryp_client_params_sign(root_data)
            pipe_l2.send(json.dumps(root_data))
            print("向L2发送数据")
            _datas = huaxin_target_codes_manager.HuaXinL2SubscriptCodesManager.pop()
            if _datas:
                timestamp = _datas[0]
                datas = _datas[1]
                print("时间戳:", timestamp)
                print("内容:", datas)
                # 只处理20s内的数据
                if time.time() - timestamp < 20 and datas:
                    codes = [d[0] for d in datas]
                    for code in codes:
                        block_info.init_code(code)
                    root_data = {"data": {"type": ClientSocketManager.CLIENT_TYPE_CMD_L2,
                                          "data": datas},
                                 "request_id": f"{ClientSocketManager.CLIENT_TYPE_CMD_L2}_{round(time.time() * 1000)}"}
                    root_data = socket_util.encryp_client_params_sign(root_data)
                    pipe_l2.send(json.dumps(root_data))
                    print("设置L2代码结束")
        except Exception as e:
            logging.exception(e)
        finally:
            time.sleep(2)
#
# def __set_target_codes(pipe_l2):
#     while True:
#         try:
#             _datas = huaxin_target_codes_manager.HuaXinL2SubscriptCodesManager.pop()
#             if _datas:
#                 timestamp = _datas[0]
#                 datas = _datas[1]
#                 print("时间戳:", timestamp)
#                 print("内容:", datas)
#                 # 只处理20s内的数据
#                 if time.time() - timestamp < 20 and datas:
#                     codes = [d[0] for d in datas]
#                     for code in codes:
#                         block_info.init_code(code)
#                     root_data = {"type": ClientSocketManager.CLIENT_TYPE_CMD_L2,
#                                  "data": datas,
#                                  "request_id": f"{ClientSocketManager.CLIENT_TYPE_CMD_L2}_{round(time.time() * 1000)}"}
#                     root_data = socket_util.encryp_client_params_sign(root_data)
#                     pipe_l2.send(json.dumps(root_data))
#                     print("设置L2代码结束")
#         except Exception as e:
#             logging.exception(e)
#         finally:
#             time.sleep(1)
            time.sleep(1)
def __read_sync_task(pipe):