From 283a7c89f85b1584fde8ff429028506dc00e53d7 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期二, 08 七月 2025 14:17:47 +0800 Subject: [PATCH] bug修复/策略完善 --- server/data_server.py | 50 ++++++++++++++++++++++++++++++++++---------------- 1 files changed, 34 insertions(+), 16 deletions(-) diff --git a/server/data_server.py b/server/data_server.py index c0b1285..2417db5 100644 --- a/server/data_server.py +++ b/server/data_server.py @@ -1,10 +1,14 @@ import http import json import logging +import os import socketserver from http.server import BaseHTTPRequestHandler from log_module.log import logger_system, logger_debug, logger_request_api +from strategy import strategy_manager +from strategy.env_info import RealTimeEnvInfo +from trade import trade_record_log_util from utils import tool from log_module import async_log_util @@ -23,9 +27,11 @@ url = urlparse.urlparse(path) async_log_util.info(logger_request_api, f"寮�濮嬭姹倇tool.get_thread_id()}-{url}") response_data = "" - if url.path == "/get_kpl_data": - response_data = json.dumps({"code": 0, "data": {}}) - async_log_util.info(logger_request_api, f"缁撴潫璇锋眰{tool.get_thread_id()}-{url}") + if url.path == "/get_place_order_records": + # 鑾峰彇涓嬪崟璁板綍 + datas = trade_record_log_util.get_trade_records(trade_record_log_util.TYPE_PLACE_ORDER) + response_data = json.dumps({"code": 0, "data": datas}) + # async_log_util.info(logger_request_api, f"缁撴潫璇锋眰{tool.get_thread_id()}-{url}") self.send_response(200) # 鍙戠粰璇锋眰瀹㈡埛绔殑鍝嶅簲鏁版嵁 self.send_header('Content-type', 'application/json') @@ -36,17 +42,31 @@ path = self.path url = urlparse.urlparse(path) result_str = "" - if url.path == "/upload_big_order_datas": - # 鎺ユ敹鎴愪氦澶у崟鏁版嵁 + try: params = self.__parse_request() - logger_debug.info("upload_big_order_datas:{}", f"{params}") - elif url.path == "/upload_block_in_datas": - # 鎺ユ敹鏉垮潡娴佸叆鏁版嵁 - params = self.__parse_request() - logger_debug.info("upload_block_in_datas:{}", f"{params}") - result_str = json.dumps({"code": 0}) - else: - pass + if type(params) == str: + params = json.loads(params) + if url.path == "/upload_big_order_datas": + # 鎺ユ敹鎴愪氦澶у崟鏁版嵁 + big_order_datas = params + strategy_manager.low_suction_strtegy.add_big_orders(big_order_datas) + RealTimeEnvInfo().big_order_update_time = tool.get_now_time_str() + result_str = json.dumps({"code": 0}) + elif url.path == "/upload_block_in_datas": + # 鎺ユ敹鏉垮潡娴佸叆鏁版嵁 + block_in_datas = params + strategy_manager.low_suction_strtegy.add_block_in(block_in_datas) + RealTimeEnvInfo().block_in = (tool.get_now_time_str(), len(block_in_datas)) + result_str = json.dumps({"code": 0}) + elif url.path == "/upload_limit_up_list": + limit_up_list = params + strategy_manager.low_suction_strtegy.add_limit_up_list(limit_up_list) + RealTimeEnvInfo().kpl_current_limit_up = (tool.get_now_time_str(), len(limit_up_list)) + result_str = json.dumps({"code": 0}) + else: + pass + except Exception as e: + logger_debug.exception(e) self.__send_response(result_str) def __send_response(self, data): @@ -57,11 +77,9 @@ self.wfile.write(data.encode()) def __parse_request(self): - params = {} datas = self.rfile.read(int(self.headers['content-length'])) _str = str(datas, encoding="gbk") - params = json.loads(_str) - return params + return json.loads(_str) class ThreadedHTTPServer(socketserver.ThreadingMixIn, http.server.HTTPServer): -- Gitblit v1.8.0