| | |
| | | if val: |
| | | val = json.loads(val) |
| | | _type = val["type"] |
| | | logger_local_huaxin_trade_debug.debug(f"获取到策略端信息:{val}") |
| | | cls.process_command_thread_pool.submit(lambda: cls.process_command(_type, None, val)) |
| | | |
| | | except Exception as e: |
| | |
| | | __start_time = round(t.time() * 1000) |
| | | # 获取阈值 |
| | | threshold_money, msg = cls.__get_threshmoney(code) |
| | | # if round(t.time() * 1000) - __start_time > 10: |
| | | # __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time, |
| | | # "获取m值数据耗时") |
| | | if True: # end_index - start_index < 10: |
| | | cls.__start_compute_buy(code, start_index, end_index, threshold_money, capture_time, is_first_code) |
| | | else: |
| | | # pass |
| | | lp = LineProfiler() |
| | | lp.enable() |
| | | lp_wrap = lp(cls.__start_compute_buy) |
| | | lp_wrap(code, start_index, end_index, threshold_money, capture_time, is_first_code) |
| | | output = io.StringIO() |
| | | lp.print_stats(stream=output) |
| | | lp.disable() |
| | | logger_profile.info(output.getvalue()) |
| | | cls.__start_compute_buy(code, start_index, end_index, threshold_money, capture_time, is_first_code) |
| | | |
| | | # 测试专用 |
| | | @classmethod |
| | |
| | | |
| | | |
| | | # 网络请求 |
| | | def __request(_type, data, request_id=None, blocking=False, is_pipe=True): |
| | | def __request(_type, data, request_id=None, blocking=False, is_pipe=True, log_enable=True): |
| | | if not request_id: |
| | | request_id = __get_request_id(_type) |
| | | try: |
| | | async_log_util.info(hx_logger_trade_loop, "请求发送开始:client_id-{} request_id-{} is_pipe-{}", 0, request_id, |
| | | is_pipe) |
| | | if log_enable: |
| | | async_log_util.info(hx_logger_trade_loop, "请求发送开始:client_id-{} request_id-{} is_pipe-{}", 0, request_id, |
| | | is_pipe) |
| | | root_data = {"type": _type, |
| | | "data": data, |
| | | "request_id": request_id} |
| | |
| | | trade_cmd_callback(TradeRequest(_type, root_data, request_id)) |
| | | else: |
| | | pipe_trade.send(json.dumps(root_data).encode("utf-8")) |
| | | async_log_util.info(hx_logger_trade_loop, "请求发送成功:request_id-{}", request_id) |
| | | if log_enable: |
| | | async_log_util.info(hx_logger_trade_loop, "请求发送成功:request_id-{}", request_id) |
| | | except BrokenPipeError as e: |
| | | hx_logger_trade_loop.info("请求发送异常:request_id-{} error-{}", request_id, str(e)) |
| | | raise e |
| | |
| | | return request_id |
| | | |
| | | |
| | | def __read_response(request_id, blocking, timeout=TIMEOUT): |
| | | def __read_response(request_id, blocking, timeout=TIMEOUT, log_enable=True): |
| | | if blocking: |
| | | start_time = time.time() |
| | | try: |
| | |
| | | if request_id in __request_response_dict: |
| | | # 获取到了响应内容 |
| | | result = __request_response_dict.pop(request_id) |
| | | hx_logger_trade_loop.info("请求读取成功: request_id-{}", request_id) |
| | | if log_enable: |
| | | hx_logger_trade_loop.info("请求读取成功: request_id-{}", request_id) |
| | | return result |
| | | if time.time() - start_time > timeout: |
| | | hx_logger_trade_loop.info("请求读取超时: request_id-{}", request_id) |
| | | if log_enable: |
| | | hx_logger_trade_loop.info("请求读取超时: request_id-{}", request_id) |
| | | # 读取内容超时才会释放 |
| | | raise Exception(f"读取内容超时: request_id={request_id}") |
| | | finally: |
| | |
| | | # 设置L2订阅数据 |
| | | def __test_trade_channel(sid): |
| | | request_id = __request("test", |
| | | {"type": "test", "data": {"sid": sid}}, blocking=True) |
| | | return __read_response(request_id, True) |
| | | {"type": "test", "data": {"sid": sid}}, blocking=True, log_enable=False) |
| | | return __read_response(request_id, True, log_enable=False) |
| | | |
| | | |
| | | def parseResponse(data_str): |