| | |
| | | import hashlib |
| | | import json |
| | | import logging |
| | | import random |
| | | import socket |
| | | import socketserver |
| | | import threading |
| | |
| | | import trade_manager |
| | | from db import mysql_data, redis_manager |
| | | from db.redis_manager import RedisUtils |
| | | from log import logger_request_debug |
| | | from utils import socket_util, hosting_api_util, huaxin_trade_record_manager, huaxin_util, tool, global_data_cache_util |
| | | from utils.history_k_data_util import HistoryKDatasUtils, JueJinApi |
| | | from utils.huaxin_trade_record_manager import PositionManager |
| | |
| | | # print("收到数据------", f"{data_str[:20]}......{data_str[-20:]}") |
| | | data_json = json.loads(data_str) |
| | | type_ = data_json['type'] |
| | | thread_id = random.randint(0, 1000000) |
| | | try: |
| | | logger_request_debug.info(f"middle_api_server 请求开始({thread_id}):{type_}") |
| | | if type(type_) == int: |
| | | # 处理数字型TYPE |
| | | return_str = self.process_num_type(sk, type_, data_str) |
| | |
| | | result = hosting_api_util.get_l2_listen_active_count() |
| | | return_str = json.dumps(result) |
| | | elif type_ == "trade_server_channels": |
| | | channels = socket_manager.ClientSocketManager.list_client() |
| | | return_str = json.dumps({"code": 0, "data": channels}) |
| | | trade_channels = socket_manager.ClientSocketManager.list_client( |
| | | socket_manager.ClientSocketManager.CLIENT_TYPE_TRADE) |
| | | common_channels = socket_manager.ClientSocketManager.list_client( |
| | | socket_manager.ClientSocketManager.CLIENT_TYPE_COMMON) |
| | | data = {} |
| | | available_count = 0 |
| | | active_count = 0 |
| | | now_time_str = tool.get_now_time_str() |
| | | for t in trade_channels: |
| | | if not t[1]: |
| | | available_count += 1 |
| | | if tool.trade_time_sub(now_time_str, t[2]) < 60: |
| | | active_count += 1 |
| | | data["trade"] = (len(trade_channels), available_count, active_count) |
| | | available_count = 0 |
| | | active_count = 0 |
| | | for t in common_channels: |
| | | if not t[1]: |
| | | available_count += 1 |
| | | if tool.trade_time_sub(now_time_str, t[2]) < 60: |
| | | active_count += 1 |
| | | data["common"] = (len(common_channels), available_count, active_count) |
| | | return_str = json.dumps({"code": 0, "data": data}) |
| | | elif type_ == "save_running_data": |
| | | result = hosting_api_util.save_running_data() |
| | | return_str = json.dumps(result) |
| | |
| | | params = data_json["data"] |
| | | result = hosting_api_util.common_request(params) |
| | | return_str = json.dumps(result) |
| | | |
| | | finally: |
| | | logger_request_debug.info(f"middle_api_server 请求结束({thread_id}):{type}") |
| | | break |
| | | # sk.close() |
| | | except Exception as e: |
| | |
| | | else: |
| | | return_str = json.dumps({"code": 1, "msg": "不可以取消"}) |
| | | |
| | | elif type == 421: |
| | | # 加入暂不买 |
| | | data = json.loads(_str) |
| | | codes = data["data"]["codes"] |
| | | for code in codes: |
| | | hosting_api_util.add_code_list(code, hosting_api_util.CODE_LIST_MUST_BUY) |
| | | return_str = json.dumps({"code": 0}) |
| | | |
| | | elif type == 422: |
| | | # 移除暂不买 |
| | | data = json.loads(_str) |
| | | codes = data["data"]["codes"] |
| | | for code in codes: |
| | | hosting_api_util.remove_code_list(code, hosting_api_util.CODE_LIST_MUST_BUY) |
| | | return_str = json.dumps({"code": 0}) |
| | | |
| | | elif type == 423: |
| | | # 暂不买列表 |
| | | result = hosting_api_util.get_code_list(hosting_api_util.CODE_LIST_MUST_BUY) |
| | | return_str = json.dumps(result) |
| | | |
| | | |
| | | elif type == 430: |
| | | # 查询代码属性 |
| | | data = json.loads(_str) |