From 2c0cd33754ca012a24438b0b1d01229242079aca Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 09 六月 2025 16:03:18 +0800 Subject: [PATCH] 功能完善 --- strategy/time_series_backtest.py | 6 +- strategy/strategy_variable_factory.py | 4 main.py | 9 ++ strategy/strategy_params_settings.py | 8 +- api/outside_api_command_manager.py | 57 ------------------- api/outside_api_callback.py | 60 ++++++++++++++++++++ 6 files changed, 77 insertions(+), 67 deletions(-) diff --git a/api/outside_api_callback.py b/api/outside_api_callback.py new file mode 100644 index 0000000..fb743cf --- /dev/null +++ b/api/outside_api_callback.py @@ -0,0 +1,60 @@ +import json +import logging + +from api.outside_api_command_manager import ActionCallback +from huaxin_client.client_network import SendResponseSkManager +from strategy import strategy_params_settings +from utils import socket_util, middle_api_protocol + + +class MyAPICallback(ActionCallback): + + @classmethod + def __send_response(cls, data_bytes): + sk = SendResponseSkManager.create_send_response_sk(addr=middle_api_protocol.SERVER_HOST, + port=middle_api_protocol.SERVER_PORT) + try: + data_bytes = socket_util.load_header(data_bytes) + sk.sendall(data_bytes) + result, header_str = socket_util.recv_data(sk) + result = json.loads(result) + if result["code"] != 0: + raise Exception(result['msg']) + finally: + sk.close() + + def send_response(self, data, _client_id, _request_id): + data_bytes = json.dumps({"type": "response", "data": data, "client_id": _client_id, + "request_id": _request_id}).encode('utf-8') + for i in range(3): + try: + self.__send_response(data_bytes) + # print("鍙戦�佹暟鎹垚鍔�") + break + except Exception as e1: + logging.exception(e1) + + def __on_get_settings(self): + """ + 鑾峰彇浜ゆ槗鍙傛暟 + @return: + """ + result = strategy_params_settings.settings.to_json_str() + return json.dumps({"code": 0, "data": result}) + + def __on_get_env(self): + """ + 鑾峰彇鐜淇℃伅 + @return: + """ + return json.dumps({"code": 0, "data": {}, "msg": "娴嬭瘯缁撴灉"}) + + def OnCommonRequest(self, client_id, request_id, data): + ctype = data["ctype"] + result_str = '' + if ctype == "get_settings": + result_str = self.__on_get_settings() + elif ctype == 'get_env': + result_str = self.__on_get_env() + + self.send_response(result_str, client_id, request_id) diff --git a/api/outside_api_command_manager.py b/api/outside_api_command_manager.py index ba16e7a..ed40f0c 100644 --- a/api/outside_api_command_manager.py +++ b/api/outside_api_command_manager.py @@ -66,63 +66,6 @@ class ActionCallback(object): - # 浜ゆ槗 - def OnTrade(self, client_id, request_id, data): - pass - - # 浜ゆ槗鐘舵�� - def OnTradeState(self, client_id, request_id, data): - pass - - # 浜ゆ槗妯″紡 - def OnTradeMode(self, client_id, request_id, data): - pass - - # 鍗栧嚭瑙勫垯 - def OnSellRule(self, client_id, request_id, data): - pass - - # 浠g爜鍚嶅崟 - def OnCodeList(self, client_id, request_id, data): - pass - - def OnExportL2(self, client_id, request_id, data): - pass - - def OnEveryDayInit(self, client_id, request_id, data): - pass - - def OnRefreshTradeData(self, client_id, request_id, data): - pass - - def OnGetCodeAttribute(self, client_id, request_id, data): - pass - - def OnGetCodeTradeState(self, client_id, request_id, data): - pass - - def OnGetEnvInfo(self, client_id, request_id, data): - pass - - def OnSyncL2SubscriptCodes(self, client_id, request_id): - pass - - def OnGetFromDataServer(self, client_id, request_id, data): - pass - - # 浠g爜鐨勪氦鏄撲俊鎭� - def OnGetCodeTradeInfo(self, client_id, request_id, data): - pass - - def OnGetActiveListenCount(self, client_id, request_id): - pass - - def OnSaveRunningData(self, client_id, request_id): - pass - - def OnGetCodePositionInfo(self, client_id, request_id, data): - pass - def OnCommonRequest(self, client_id, request_id, data): pass diff --git a/main.py b/main.py index 7958fd8..3688b87 100644 --- a/main.py +++ b/main.py @@ -5,13 +5,15 @@ import requests +from api import outside_api_callback +from api.outside_api_command_manager import ApiCommandManager from huaxin_client import l2_market_client, trade_client from log_module.log import logger_debug from server import data_server from strategy.env_info import RealTimeEnvInfo from third_data import hx_qc_value_util from trade.huaxin import huaxin_trade_api -from utils import tool +from utils import tool, middle_api_protocol def __run_l2_market_subscript(): @@ -47,6 +49,11 @@ if __name__ == "__main__": # -----鍚姩data_server----- threading.Thread(target=lambda: data_server.run("127.0.0.1", 9008), daemon=True).start() + + # --------鍚姩鏈湴API鎺ュ彛---------- + manager = ApiCommandManager(middle_api_protocol.SERVER_HOST, middle_api_protocol.SERVER_PORT, outside_api_callback.MyAPICallback()) + manager.run(blocking=False) + # -------鍚姩鍗庨懌澧炲�兼湇鍔pi------ threading.Thread(target=hx_qc_value_util.run, daemon=True).start() # --------鍚姩浜ゆ槗---------- diff --git a/strategy/strategy_params_settings.py b/strategy/strategy_params_settings.py index 05ccf87..c7048dd 100644 --- a/strategy/strategy_params_settings.py +++ b/strategy/strategy_params_settings.py @@ -3,7 +3,6 @@ """ import json - class StrategyParamsSettings: # 绂佹涔板叆 STATE_FORBIDDEN_BUY = 0 @@ -18,9 +17,9 @@ # 浠锋牸鍖洪棿 self.price_range = (3, 60) # 鑰侀鏉愭定鍋滄暟 - self.limit_up_count_of_old_plate = 4 + self.limit_up_count_of_old_plate = 3 # 鏂伴鏉愭定鍋滄暟 - self.limit_up_count_of_new_plate = 4 + self.limit_up_count_of_new_plate = 3 # 鏄ㄦ棩涓嶈兘娑ㄥ仠 self.cant_yesterday_limit_up = True # 鏄ㄦ棩涓嶈兘璺屽仠 @@ -50,7 +49,7 @@ # 鏄惁鍙拱浠婃棩娑ㄥ仠杩囩殑绁� self.can_buy_limited_up = False # 鏈�浣庡紑鐩樻定骞� - self.min_open_rate = -0.03 + self.min_open_rate = -0.02 # 鍙拱鐨勬定骞呮瘮渚� self.avaiable_rates = (-0.03, 0.07) # 浠婃棩娑ㄥ仠浠烽渶绐佺牬XX鏃ユ渶楂樹环,None琛ㄧず姝ゆ潯鏁版嵁涓嶇敓鏁� @@ -73,3 +72,4 @@ return obj +settings: StrategyParamsSettings = StrategyParamsSettings() \ No newline at end of file diff --git a/strategy/strategy_variable_factory.py b/strategy/strategy_variable_factory.py index a8a0643..3f674ae 100644 --- a/strategy/strategy_variable_factory.py +++ b/strategy/strategy_variable_factory.py @@ -628,7 +628,7 @@ if __name__ == "__main__": - __DataLoader = DataLoader("2025-06-05") + __DataLoader = DataLoader("2025-06-09") # __test_jx_blocks(__DataLoader) # instance = StockVariables() @@ -644,7 +644,7 @@ # print(result_dict["301279"]) results = __DataLoader.load_target_plate_and_codes() - plates = ["鏈夎壊閲戝睘"] + plates = ["鍖昏嵂"] print("==========鏂伴鏉�=======") for p in plates: print(p, results.get(p)) diff --git a/strategy/time_series_backtest.py b/strategy/time_series_backtest.py index b69de53..9701205 100644 --- a/strategy/time_series_backtest.py +++ b/strategy/time_series_backtest.py @@ -766,7 +766,7 @@ stock_variables.鏉垮潡鎴愪氦浠g爜 = self.deal_block_codes -# DEBUG_CODES = ['002194', '002583', '603083', '002130', '002436'] +# DEBUG_CODES = ['002365', '000953', '002907', '002688', '003020', '002900', '002082', '000566', '300204', '002317'] DEBUG_CODES = [] VOLUME_LOG_ENABLE = False @@ -782,8 +782,8 @@ # days = ["2025-05-06", "2025-05-07", "2025-05-08", "2025-05-09", "2025-05-12", "2025-05-13", "2025-05-14", # "2025-05-15", "2025-05-16"] days = ["2025-05-12", "2025-05-13", "2025-05-14", "2025-05-15", "2025-05-16", "2025-05-19", "2025-05-20", - "2025-05-21", "2025-05-22","2025-05-23", "2025-05-26", "2025-05-27", "2025-05-28", "2025-05-29", - "2025-05-30", "2025-06-03", "2025-06-04", "2025-06-05", "2025-06-06"] + "2025-05-21", "2025-05-22", "2025-05-23", "2025-05-26", "2025-05-27", "2025-05-28", "2025-05-29", + "2025-05-30", "2025-06-03", "2025-06-04", "2025-06-05", "2025-06-06", "2025-06-09"] days.reverse() for day in days: if day not in back_test_dict: -- Gitblit v1.8.0