| | |
| | | import authority |
| | | import juejin |
| | | import l2_data_manager |
| | | import l2_data_util |
| | | import tool |
| | | import trade_manager |
| | | import l2_code_operate |
| | | |
| | | from log import logger_l2_error, logger_l2_process, logger_device, logger_trade_delegate |
| | | from trade_data_manager import TradeCancelDataManager |
| | | |
| | | |
| | | class MyTCPServer(socketserver.TCPServer): |
| | |
| | | if len(data) == 0: |
| | | # print("客户端断开连接") |
| | | break; |
| | | _str = data.decode() |
| | | _str = str(data, encoding="gb2312") |
| | | if len(_str) > 0: |
| | | # print("结果:",_str) |
| | | type = data_process.parseType(_str) |
| | |
| | | |
| | | try: |
| | | __start_time = round(time.time() * 1000) |
| | | |
| | | # level2盘口数据 |
| | | day, client, channel, code, datas = l2_data_manager.parseL2Data(_str) |
| | | day, client, channel, code, capture_time, process_time, datas = l2_data_manager.parseL2Data( |
| | | _str) |
| | | # 10ms的网络传输延时 |
| | | capture_timestamp = __start_time - process_time - 10 |
| | | # 保存l2截图时间 |
| | | TradeCancelDataManager.save_l2_capture_time(client, channel, code, capture_time) |
| | | cid, pid = gpcode_manager.get_listen_code_pos(code) |
| | | # 判断目标代码位置是否与上传数据位置一致 |
| | | if cid is not None and pid is not None and client == int(cid) and channel == int(pid): |
| | |
| | | self.l2CodeOperate.set_operate_code_state(client, channel, 1) |
| | | |
| | | if gpcode_manager.is_listen(code): |
| | | l2_data_manager.process_data(code, datas) |
| | | l2_data_manager.process_data(code, datas, capture_timestamp) |
| | | except l2_data_manager.L2DataException as l: |
| | | # 单价不符 |
| | | if l.get_code() == l2_data_manager.L2DataException.CODE_PRICE_ERROR: |
| | |
| | | # todo 太敏感移除代码 |
| | | logger_l2_error.warning("code-{} l2单价错误:{}", code, l.msg) |
| | | # 单价不一致时需要移除代码重新添加 |
| | | l2_code_operate.L2CodeOperate().remove_l2_listen(code) |
| | | l2_code_operate.L2CodeOperate().remove_l2_listen(code, "l2监听单价错误") |
| | | self.l2_data_error_dict[key] = round(time.time() * 1000) |
| | | |
| | | except Exception as e: |
| | |
| | | juejin.accpt_price(item["code"], float(item["price"])) |
| | | |
| | | elif type == 30: |
| | | # 心跳信息 |
| | | data = data_process.parse(_str)["data"] |
| | | client_id = data["client"] |
| | | thsDead = data.get("thsDead") |
| | | logger_device.info("({})客户端信息:{}".format(client_id, json.dumps(data))) |
| | | data_process.saveClientActive(int(client_id), host) |
| | | data_process.saveClientActive(int(client_id), host, thsDead) |
| | | # print("心跳:", client_id) |
| | | |
| | | sk.send(return_str.encode()) |