| | |
| | | import time |
| | | |
| | | # 心跳信息 |
| | | from huaxin_api import socket_util |
| | | from huaxin_api.client_network import SendResponseSkManager |
| | | from huaxin_client import socket_util |
| | | from huaxin_client.client_network import SendResponseSkManager |
| | | from log_module.log import logger_debug |
| | | from utils import middle_api_protocol |
| | | |
| | | MSG_TYPE_HEART = "heart" |
| | |
| | | API_TYPE_CODE_ATRRIBUTE = "code_attribute" # 代码属性 |
| | | API_TYPE_CODE_TRADE_STATE = "code_trade_state" # 代码交易状态 |
| | | API_TYPE_GET_ENV = "get_env" # 获取环境信息 |
| | | API_TYPE_SYNC_L1_TARGET_CODES = "sync_l1_subscript_codes" # 同步L1需要订阅的代码 |
| | | |
| | | |
| | | class ActionCallback(object): |
| | |
| | | def OnGetEnvInfo(self, client_id, request_id, data): |
| | | pass |
| | | |
| | | def OnSyncL2SubscriptCodes(self, client_id, request_id): |
| | | pass |
| | | |
| | | |
| | | # 交易指令管理 |
| | | # 交易指令管理 |
| | |
| | | @classmethod |
| | | def __create_client(cls, client_type, rid): |
| | | client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 生成socket,连接server |
| | | client.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, True) |
| | | # client.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, True) |
| | | # client.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 60 * 1000, 30 * 1000)) |
| | | client.connect(cls.ip_port) |
| | | client.send(SendResponseSkManager.format_response( |
| | |
| | | cls.action_callback.OnGetCodeTradeState(client_id, request_id, data) |
| | | elif content_type == API_TYPE_GET_ENV: |
| | | cls.action_callback.OnGetEnvInfo(client_id, request_id, data) |
| | | elif content_type == API_TYPE_GET_ENV: |
| | | cls.action_callback.OnSyncL2SubscriptCodes(client_id, request_id) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | pass |
| | |
| | | def __heart_beats(cls, _type, client_id, sk): |
| | | while True: |
| | | try: |
| | | sk.send(SendResponseSkManager.format_response( |
| | | json.dumps({"type": "heart", "client_id": client_id}).encode('utf-8'))) |
| | | sk.send(socket_util.load_header(json.dumps({"type": "heart", "client_id": client_id}).encode('utf-8'))) |
| | | # print("心跳信息发送成功", client_id) |
| | | except Exception as e: |
| | | logging.error("错误") |
| | | print("心跳信息发送失败", _type, client_id) |
| | | logging.exception(e) |
| | | if _type == CLIENT_TYPE_TRADE: |