| | |
| | | |
| | | class ClientSocketManager: |
| | | # 客户端类型 |
| | | CLIENT_TYPE_COMMON = "common" |
| | | CLIENT_TYPE_TRADE = "trade" |
| | | CLIENT_TYPE_TRADE_SELL = "trade_sell" |
| | | CLIENT_TYPE_TRADE_LOW_SUCTION = "trade_low_suction" |
| | | # 可转债客户端 |
| | | CLIENT_TYPE_TRADE_CB = "trade_cb" |
| | | |
| | | socket_client_dict = {} |
| | | socket_client_lock_dict = {} |
| | |
| | | |
| | | @classmethod |
| | | def add_client(cls, _type, rid, sk): |
| | | if _type == cls.CLIENT_TYPE_TRADE: |
| | | if _type in {cls.CLIENT_TYPE_COMMON, cls.CLIENT_TYPE_TRADE, cls.CLIENT_TYPE_TRADE_SELL, |
| | | cls.CLIENT_TYPE_TRADE_CB, cls.CLIENT_TYPE_TRADE_LOW_SUCTION}: |
| | | # 交易列表 |
| | | if _type not in cls.socket_client_dict: |
| | | cls.socket_client_dict[_type] = [] |
| | |
| | | |
| | | @classmethod |
| | | def acquire_client(cls, _type): |
| | | if _type == cls.CLIENT_TYPE_TRADE: |
| | | if _type == cls.CLIENT_TYPE_COMMON or _type == cls.CLIENT_TYPE_TRADE or _type == cls.CLIENT_TYPE_TRADE_SELL or _type == cls.CLIENT_TYPE_TRADE_CB: |
| | | if _type in cls.socket_client_dict: |
| | | # 根据排序活跃时间排序 |
| | | client_list = sorted(cls.socket_client_dict[_type], key=lambda x: cls.active_client_dict.get(x[0]) if x[ |
| | |
| | | cls.del_client(k) |
| | | |
| | | @classmethod |
| | | def list_client(cls): |
| | | _type = cls.CLIENT_TYPE_TRADE |
| | | def list_client(cls, type_=None): |
| | | _type = type_ |
| | | if not _type: |
| | | _type = cls.CLIENT_TYPE_TRADE |
| | | client_list = sorted(cls.socket_client_dict[_type], |
| | | key=lambda x: cls.active_client_dict.get(x[0]) if x[0] in cls.active_client_dict else 0, |
| | | reverse=True) |
| | |
| | | active_time = 0 |
| | | active_time = tool.to_time_str(int(active_time)) |
| | | fdata.append( |
| | | (client[0], cls.socket_client_lock_dict[client[0]].locked(),active_time)) |
| | | (client[0], cls.socket_client_lock_dict[client[0]].locked(), active_time)) |
| | | return fdata |
| | | |