Administrator
2023-07-20 a21a08292fad35745037f979f3855b80e1fd53b0
bug修复
2个文件已修改
37 ■■■■ 已修改文件
trade/huaxin/huaxin_trade_api.py 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/trade_api_server.py 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_api.py
@@ -47,6 +47,13 @@
            cls.socket_client_dict[_type] = (rid, sk)
            cls.socket_client_lock_dict[rid] = threading.Lock()
    # 是否已经被锁住
    @classmethod
    def is_client_locked(cls, rid):
        if rid in cls.socket_client_lock_dict:
            return cls.socket_client_lock_dict[rid].locked()
        return None
    @classmethod
    def acquire_client(cls, _type):
        if _type == cls.CLIENT_TYPE_TRADE:
@@ -164,6 +171,7 @@
def __read_response(client, request_id, blocking, timeout=TIMEOUT):
    if blocking:
        start_time = time.time()
        try:
        while True:
            time.sleep(0.01)
            if request_id in __request_response_dict:
@@ -171,8 +179,9 @@
                result = __request_response_dict.pop(request_id)
                return result
            if time.time() - start_time > timeout:
                ClientSocketManager.release_client(client[0])
                raise Exception(f"读取内容超时: request_id={request_id}")
        finally:
            ClientSocketManager.release_client(client[0])
    return None
trade/huaxin/trade_api_server.py
@@ -289,8 +289,20 @@
                                 huaxin_trade_api.ClientSocketManager.CLIENT_TYPE_POSITION_LIST]
                        fdata = {}
                        for t in types:
                            trade_list = huaxin_trade_api.ClientSocketManager.list_client(t)
                            fdata[t] = len(trade_list)
                            client_list = huaxin_trade_api.ClientSocketManager.list_client(t)
                            client_state_list = []
                            for t in client_list:
                                # 判断是否已经上锁
                                lock_state = huaxin_trade_api.ClientSocketManager.is_client_locked(t[0])
                                lock_state_desc = ""
                                if lock_state is None:
                                    lock_state_desc = "未知"
                                elif lock_state:
                                    lock_state_desc = "已锁"
                                else:
                                    lock_state_desc = "未锁"
                                client_state_list.append((t[0],lock_state_desc))
                            fdata[t] = client_state_list
                        return_str = json.dumps(
                            {"code": 0, "data": fdata, "msg": ""})
                    elif type_ == 'juejin_is_valid':
@@ -355,7 +367,7 @@
            if data:
                type_ = data["type"]
                hx_logger_trade_debug.info(f"获取交易数据开始:{type_}")
                try:
                if type_ == "delegate_list":
                    dataJSON = huaxin_trade_api.get_delegate_list(can_cancel=False, timeout=5)
                    print("获取委托列表", dataJSON)
@@ -390,7 +402,8 @@
                        datas = dataJSON["data"]
                        huaxin_trade_record_manager.DealRecordManager.add(datas)
                        if datas:
                            tempList = [{"time": d["tradeTime"], "type": int(d['direction']), "code": d['securityID']}
                                tempList = [
                                    {"time": d["tradeTime"], "type": int(d['direction']), "code": d['securityID']}
                                        for d in datas]
                            try:
                                trade_manager.process_trade_success_data(tempList)
@@ -404,6 +417,11 @@
                        huaxin_trade_record_manager.PositionManager.add(data)
                hx_logger_trade_debug.info(f"获取交易数据成功:{type_}")
                except Exception as e1:
                    if str(e1).find("超时") >= 0:
                        # 读取结果超时需要重新请求
                        trade_data_request_queue.put_nowait({"type": type_})
                    raise e1
        except Exception as e:
            hx_logger_trade_debug.exception(e)
        finally: