| | |
| | | from records.huaxin_trade_record_manager import TradeOrderIdManager |
| | | from trade import huaxin_trade_data_update |
| | | from trade.entity import HuaxinOrderEntity |
| | | from utils import socket_util, huaxin_util, tool |
| | | from utils import socket_util, huaxin_util, tool, middle_api_protocol |
| | | |
| | | __response_thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=15) |
| | | __save_data_queue = queue.Queue() |
| | |
| | | |
| | | # 超时时间2s |
| | | TIMEOUT = 2.0 |
| | | # 交易代理 |
| | | TRADE_DELEGATED = True |
| | | |
| | | # 等待响应的request_id |
| | | __request_response_dict = {} |
| | |
| | | |
| | | def __get_request_id(type): |
| | | return f"r_{type}_{round(time.time() * 10000)}_{random.randint(0, 100000)}" |
| | | |
| | | |
| | | def __request_delegate(request_id, type, data): |
| | | fdata = middle_api_protocol.load_simulation_trade(type, data) |
| | | try: |
| | | result = middle_api_protocol.request(fdata, port=10020) |
| | | set_response(request_id, result) |
| | | except Exception as e: |
| | | pass |
| | | |
| | | |
| | | # 网络请求 |
| | |
| | | } |
| | | root_data = socket_util.encryp_client_params_sign(root_data) |
| | | start_time = time.time() |
| | | if is_trade: |
| | | queue_strategy_w_trade_r.put_nowait(root_data) |
| | | if not TRADE_DELEGATED: |
| | | if is_trade: |
| | | queue_strategy_w_trade_r.put_nowait(root_data) |
| | | else: |
| | | queue_strategy_w_trade_r_for_query.put_nowait(root_data) |
| | | else: |
| | | queue_strategy_w_trade_r_for_query.put_nowait(root_data) |
| | | threading.Thread(target=__request_delegate, args=(request_id, _type, data,), daemon=True).start() |
| | | |
| | | use_time = int((time.time() - start_time) * 1000) |
| | | if use_time > 10: |
| | |
| | | request_id = __request(ClientSocketManager.CLIENT_TYPE_MONEY, |
| | | {"type": ClientSocketManager.CLIENT_TYPE_MONEY}) |
| | | return __read_response(request_id, blocking) |
| | | |
| | | |
| | | |
| | | # 设置L2订阅数据 |