From d1df4e77d2188ff3ad84b66fb2ba7f9bc738031d Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期二, 12 八月 2025 14:48:13 +0800 Subject: [PATCH] 记录L1的最大价格信息 --- code_attribute/today_max_price_manager.py | 60 ++++++++++++++++++++ trade/buy_radical/radical_buy_data_manager.py | 10 +++ l2/huaxin/huaxin_target_codes_manager.py | 17 +---- servers/huaxin_trade_server.py | 11 +++ l2/l2_data_manager_new.py | 37 ++---------- 5 files changed, 93 insertions(+), 42 deletions(-) diff --git a/code_attribute/today_max_price_manager.py b/code_attribute/today_max_price_manager.py new file mode 100644 index 0000000..49a1dfe --- /dev/null +++ b/code_attribute/today_max_price_manager.py @@ -0,0 +1,60 @@ +# 娑ㄥ仠鏃堕棿绠$悊鍣� +""" +浠婃棩鏈�楂樹环绠$悊 +""" +import json + +from db import redis_manager_delegate as redis_manager +from db.redis_manager_delegate import RedisUtils +from log_module import async_log_util +from log_module.log import logger_debug +from utils import global_util, tool + + +class MaxPriceInfoManager: + __max_price_info_cache = {} + __db = 4 + _redisManager = redis_manager.RedisManager(4) + __instance = None + + def __new__(cls, *args, **kwargs): + if not cls.__instance: + cls.__instance = super(MaxPriceInfoManager, cls).__new__(cls, *args, **kwargs) + cls.load_max_price_info() + return cls.__instance + + @classmethod + def load_max_price_info(cls): + redis = cls._redisManager.getRedis() + keys = RedisUtils.keys(redis, "max_price_info-*", auto_free=False) + for key in keys: + code = key.replace("max_price_info-", "") + val = RedisUtils.get(redis, key, auto_free=False) + if val: + val = json.loads(val) + cls.__max_price_info_cache[code] = val + + def set_price_info(self, code, price, time): + """ + 璁剧疆浠锋牸淇℃伅 + @param code: + @param price: + @param time: + @return: + """ + old_price_info = self.__max_price_info_cache.get(code) + if old_price_info and old_price_info[0] >= price: + return + price_info = (price, time) + tool.CodeDataCacheUtil.set_cache(self.__max_price_info_cache, code, price_info) + RedisUtils.setex_async( + self.__db, "max_price_info-{}".format(code), tool.get_expire(), json.dumps(price_info)) + async_log_util.info(logger_debug, f"鏈�澶х幇浠�-{price_info}") + + def get_price_info_cache(self, code): + return self.__max_price_info_cache.get(code) + + +if __name__ == "__main__": + list = [("1234578", "09:00:03", None), ("12345", "09:00:01", True), ("123456", "09:00:00", True), + ("123457", "09:00:04", False)] diff --git a/l2/huaxin/huaxin_target_codes_manager.py b/l2/huaxin/huaxin_target_codes_manager.py index 454474e..9e72116 100644 --- a/l2/huaxin/huaxin_target_codes_manager.py +++ b/l2/huaxin/huaxin_target_codes_manager.py @@ -8,6 +8,7 @@ import constant from code_attribute import global_data_loader, code_volumn_manager, first_target_code_data_processor, gpcode_manager from code_attribute.code_data_util import ZYLTGBUtil +from code_attribute.today_max_price_manager import MaxPriceInfoManager from db import redis_manager_delegate as redis_manager from log_module import async_log_util from log_module.log import logger_l2_codes_subscript, logger_debug @@ -111,16 +112,8 @@ if zylt_volume and price > 0: zylt = zylt_volume * price if not zylt: - try: - __start_time = time.time() - zylt = kpl_api.getZYLTAmount(code) - async_log_util.info(logger_l2_codes_subscript, - f"{request_id} {code}鑾峰彇鑷敱娴侀�氬競鍊艰�楁椂-{round((time.time() - __start_time) * 1000)}ms") - # 淇濆瓨鑷敱娴侀�氳偂鏈� - if zylt: - ZYLTGBUtil.save_async(code, zylt, price) - except: - pass + # 榛樿20浜� + zylt = 20 * 1e8 if zylt: limit_up_price = gpcode_manager.get_limit_up_price(code) if not limit_up_price: @@ -131,7 +124,6 @@ global_util.zyltgb_map[code] = int(zylt) # 淇濆瓨浠婃棩瀹炴椂閲� temp_volumns.append((code, d[3])) - zyltgb = 0 if code in global_util.zyltgb_map: zyltgb = global_util.zyltgb_map[code] @@ -150,7 +142,8 @@ yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() if yesterday_codes is None: yesterday_codes = set() - current_price_process_manager.accept_prices(tick_datas, request_id, in_blocks, yesterday_codes, top_out_blocks=out_blocks) + current_price_process_manager.accept_prices(tick_datas, request_id, in_blocks, yesterday_codes, + top_out_blocks=out_blocks) except Exception as e: logger_debug.exception(e) finally: diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py index 19ad570..e708b44 100644 --- a/l2/l2_data_manager_new.py +++ b/l2/l2_data_manager_new.py @@ -821,38 +821,15 @@ if order_begin_pos.buy_volume_rate is None: order_begin_pos.buy_volume_rate = 0.2 cancel_data, cancel_msg, cancel_type = None, "", None - if order_begin_pos.mode == OrderBeginPosInfo.MODE_RADICAL: - if not cancel_data: - cancel_data, cancel_msg, cancel_type = rd_cancel(order_begin_pos.buy_single_index, - order_begin_pos.buy_exec_index) + if not cancel_data: + cancel_data, cancel_msg, cancel_type = rd_cancel(order_begin_pos.buy_single_index, + order_begin_pos.buy_exec_index) - # 鎵叆涓嬪崟鍙湁L鎾� - if not cancel_data: - cancel_data, cancel_msg, cancel_type = l_cancel(order_begin_pos.buy_single_index, - order_begin_pos.buy_exec_index) - else: - if not cancel_data: - cancel_data, cancel_msg, cancel_type = rd_cancel(order_begin_pos.buy_single_index, - order_begin_pos.buy_exec_index) - if not cancel_data: - cancel_data, cancel_msg = g_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) - cancel_type = trade_constant.CANCEL_TYPE_G - # 渚濇澶勭悊 - if not cancel_data: - cancel_data, cancel_msg, cancel_type = l_cancel(order_begin_pos.buy_single_index, - order_begin_pos.buy_exec_index) - # B鎾� - if not cancel_data: - cancel_data, cancel_msg = b_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) - cancel_type = trade_constant.CANCEL_TYPE_G - if not cancel_data: - cancel_data, cancel_msg = h_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) - cancel_type = trade_constant.CANCEL_TYPE_H - # J鎾� - if not cancel_data: - cancel_data, cancel_msg = j_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) - cancel_type = trade_constant.CANCEL_TYPE_J + # 鎵叆涓嬪崟鍙湁L鎾� + if not cancel_data: + cancel_data, cancel_msg, cancel_type = l_cancel(order_begin_pos.buy_single_index, + order_begin_pos.buy_exec_index) if cancel_data and not DCancelBigNumComputer().has_auto_cancel_rules(code): try: diff --git a/servers/huaxin_trade_server.py b/servers/huaxin_trade_server.py index 8544e1d..f227183 100644 --- a/servers/huaxin_trade_server.py +++ b/servers/huaxin_trade_server.py @@ -19,6 +19,7 @@ from code_attribute.code_l1_data_manager import L1DataManager from code_attribute.gpcode_manager import CodePrePriceManager, CodesNameManager, \ WantBuyCodesManager +from code_attribute.today_max_price_manager import MaxPriceInfoManager from huaxin_client import l2_data_transform_protocol, l1_subscript_codes_manager from huaxin_client.trade_transform_protocol import TradeResponse from l2 import l2_data_manager_new, l2_log, code_price_manager, l2_data_util, transaction_progress, \ @@ -399,6 +400,16 @@ datas = data["data"] cls.__save_l1_current_price(datas) cls.__process_buy_open_limit_up_datas(datas) + + try: + # 璁板綍浠婃棩鏈�楂樹环 + # 09:25涔嬪悗鎵嶅紑濮嬭褰� + if datas and tool.get_now_time_str() > '09:25:00': + for d in datas: + MaxPriceInfoManager().set_price_info(d[0], price=d[1], time=l2_huaxin_util.convert_time(d[9])) + except Exception as e: + logger_debug.exception(e) + # 鏍规嵁楂樻爣鐨勫疄鏃舵定骞呰绠楁媺榛戞澘鍧� rate_dict = {d[0]: d[2] for d in datas} cls.__process_l1_data_thread_pool.submit( diff --git a/trade/buy_radical/radical_buy_data_manager.py b/trade/buy_radical/radical_buy_data_manager.py index 2b99117..365ab61 100644 --- a/trade/buy_radical/radical_buy_data_manager.py +++ b/trade/buy_radical/radical_buy_data_manager.py @@ -11,6 +11,7 @@ import constant import l2_data_util from code_attribute.code_volumn_manager import CodeVolumeManager +from code_attribute.today_max_price_manager import MaxPriceInfoManager from l2 import l2_data_util as l2_data_util_new, l2_log, l2_data_manager from code_attribute import code_nature_analyse, code_volumn_manager, gpcode_manager from code_attribute.code_l1_data_manager import L1DataManager @@ -2306,6 +2307,15 @@ @return: """ is_limit_up = code in LimitUpDataConstant.get_history_limit_up_codes() + # 鏄惁娑ㄥ仠 + if not is_limit_up: + # 鏍规嵁L1鍒ゆ柇鏄惁娑ㄥ仠 + max_price_info = MaxPriceInfoManager().get_price_info_cache(code) + limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) + if max_price_info and abs(max_price_info[0] - limit_up_price)<0.001 and tool.trade_time_sub(tool.get_now_time_str(), max_price_info[1])>=3: + # 鏄定鍋滀环涓旀定鍋滄椂闂磋窛绂荤幇鍦�3s浠ヤ笂 + is_limit_up = True + place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code) if place_order_count is None: place_order_count = 0 -- Gitblit v1.8.0