From 6a0d3ff5832e57ee1b1374d086f24b3c1679b332 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期五, 05 九月 2025 18:22:24 +0800 Subject: [PATCH] bug修复/降低测撤单率 --- trade/l2_trade_factor.py | 231 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 169 insertions(+), 62 deletions(-) diff --git a/trade/l2_trade_factor.py b/trade/l2_trade_factor.py index 1702ab7..602d8fe 100644 --- a/trade/l2_trade_factor.py +++ b/trade/l2_trade_factor.py @@ -4,22 +4,128 @@ # l2浜ゆ槗鍥犲瓙 -import big_money_num_manager +from code_attribute import big_money_num_manager, limit_up_time_manager, global_data_loader, gpcode_manager import constant -import global_data_loader -import global_util -import limit_up_time_manager +from trade import trade_manager, deal_big_money_manager, trade_constant +from utils import global_util, tool # 涓嬪崟鍙傛暟 + + class L2PlaceOrderParamsManager: + # 鑾峰彇涔板叆绛夌骇鎻忚堪 + def get_buy_rank_desc(self): + continue_count = self.get_begin_continue_buy_count() + time_range = self.get_time_range() + m = self.get_m_val()[0] + m = m // 10000 + + desc = "" + if self.buy_rank == 0: + desc = f"涔板叆淇″彿({continue_count})" + elif self.buy_rank == 1: + desc = f"涔板叆淇″彿({continue_count})+M鍊尖墺{m}涓�" + elif self.buy_rank == 2: + desc = f"涔板叆淇″彿({continue_count})+M鍊尖墺{m}涓�+鑷冲皯鍚�1绗斿ぇ鍗�" + elif self.buy_rank == 3: + desc = f"涔板叆淇″彿({continue_count})+M鍊尖墺{m}涓�+鑷冲皯鍚�2绗斿ぇ鍗�" + else: + desc = "甯歌涔板叆" + desc += f"+鍥婃嫭鏃堕棿{time_range}s" + return desc + + # 鑾峰彇涔板叆绛夌骇 + # 0:涔板叆淇″彿 + # 1:涔板叆淇″彿+M1000涓� + # 2:涔板叆淇″彿+M1000涓�+1绗斿ぇ鍗� + # 3:涔板叆淇″彿+M1000+2绗斿ぇ鍗� + # 100:鎵ц涔嬪墠鍥烘湁鏂规 + def get_buy_rank(self): + if self.score_index == 0: + return 0 + elif self.score_index == 1: + return 1 + elif self.score_index == 2: + return 2 + else: + return 100 + # 鏆傛椂涓嶉渶瑕佹姝や腑绛栫暐 + # # 鍒ゆ柇鏈夋病鏈夌偢寮� + # if code_price_manager.Buy1PriceManager().is_can_buy(self.code): + # # 鍥炲皝 + # if self.score_index == 0: + # return 0 + # elif self.score_index == 1: + # return 1 + # elif self.score_index == 2: + # return 2 + # else: + # return 100 + # else: + # # 棣栧皝 + # if tool.trade_time_sub(self.now_time, "10:30:00") < 0 or tool.trade_time_sub(self.now_time, "14:00:00") > 0: + # if self.score_index == 0: + # return 1 + # elif self.score_index == 1: + # return 2 + # elif self.score_index == 2: + # return 3 + # else: + # return 100 + # else: + # if self.score_index == 0: + # return 2 + # elif self.score_index == 1: + # return 3 + # elif self.score_index == 2: + # return 100 + # else: + # return 100 + # 寰楀垎 - def __init__(self, code, is_first_code, volume_rate, volume_rate_index, score): + def __init__(self, code, is_first_code, volume_rate, volume_rate_index, score, now_time=tool.get_now_time_str()): self.code = code self.is_first_code = is_first_code - score_ranks = [200, 190, 180, 100] - self.score = score[0] + score_ranks = [constant.BUY_SCORE_RANK_3, constant.BUY_SCORE_RANK_2, constant.BUY_SCORE_RANK_1, + constant.BUY_SCORE_RANK_0] + # self.score = score[0][0] + # self.score_info = score + # 涓哄垎鏁拌缃瓑绾� + # score_index = -1 + # for i in range(0, len(score_ranks)): + # if self.score >= score_ranks[i]: + # score_index = i + # break + # 鍥哄畾璁剧疆涓�2 + self.score_index = 2 + # 鍙鍔犲叆鎯充拱鍗曠殑锛屽叏閮ㄦ墽琛屼富鍔ㄤ拱鍏ヤ簩鏄熸柟妗� + if gpcode_manager.WantBuyCodesManager().is_in_cache(code): + self.score_index = 1 + self.is_want_buy = True + else: + self.is_want_buy = False + # 娌℃湁鍔犲叆鎯充拱鍗曠殑锛�2鏄�/3鏄熷皢涓�1鏄� + if self.score_index == 0 or self.score_index == 1: + self.score_index = 2 + + self.volume_rate = volume_rate + self.volume_rate_index = volume_rate_index + self.now_time = now_time + self.buy_rank = self.get_buy_rank() + + # 鏄惁鏄垵娆′笅鍗� + @classmethod + def is_first_place_order(cls, code): + return trade_manager.CodesTradeStateManager().get_trade_state_cache(code) == trade_constant.TRADE_STATE_NOT_TRADE + + # 璁剧疆鍒嗘暟 + def set_score(self, score): + score_ranks = [constant.BUY_SCORE_RANK_3, constant.BUY_SCORE_RANK_2, constant.BUY_SCORE_RANK_1, + constant.BUY_SCORE_RANK_0] + self.score = score[0][0] + self.score_info = score # 涓哄垎鏁拌缃瓑绾� score_index = -1 for i in range(0, len(score_ranks)): @@ -27,11 +133,8 @@ score_index = i break self.score_index = score_index - self.volume_rate = volume_rate - self.volume_rate_index = volume_rate_index # 鑾峰彇淇″彿杩炵画涔扮瑪鏁� - def get_begin_continue_buy_count(self): counts = [3, 3, 3, 2, 2, 2, 2] volume_rate_index = self.volume_rate_index @@ -41,74 +144,73 @@ # 鑾峰彇鏃堕棿璁$畻鑼冨洿锛岃繑鍥瀞 def get_time_range(self): - ts = [pow(3, 1), pow(3, 1), pow(3, 1), pow(3, 2), pow(3, 2), pow(3, 3), pow(3, 3), pow(3, 3)] + # ts = [pow(3, 1), pow(3, 1), pow(3, 1), pow(3, 2), pow(3, 2), pow(3, 3), pow(3, 3), pow(3, 3)] + ts = [pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1), pow(2, 1)] + # 鏆傛椂鍘婚櫎鍒嗙殑褰卞搷 + # if -1 < self.score_index < 3: + # return ts[0] volume_rate_index = self.volume_rate_index if self.volume_rate_index >= len(ts): volume_rate_index = -1 + # 棣栨涓嬪崟蹇呴』鍚�1s + if self.is_first_place_order(self.code): + return 1 return ts[volume_rate_index] # 鑾峰彇闇�瑕佺殑澶у崟涓暟 def get_big_num_count(self): - if self.is_first_code: - if self.score_index == 0: - return 0 - elif self.score_index == 1: - return 0 - elif self.score_index == 2: - return 1 - elif self.score_index < 0: - return 65535 - counts = [3, 1, 1, 1, 0, 0, 0, 0] - volume_rate_index = self.volume_rate_index - if self.volume_rate_index >= len(counts): - volume_rate_index = -1 - return counts[volume_rate_index] + # counts = [1, 1, 1, 1, 0, 0, 0, 0] + # volume_rate_index = self.volume_rate_index + # if self.volume_rate_index >= len(counts): + # volume_rate_index = -1 + # return counts[volume_rate_index] + # 鏈夊ぇ鍗曟垚浜ゅ氨涓嶉渶瑕佸ぇ鍗曚簡锛屾病鏈夊ぇ鍗曟垚浜ゅ氨闇�瑕佸ぇ鍗� + deal_big_money_count = deal_big_money_manager.get_deal_big_money_count(self.code) + if deal_big_money_count > 0: + return 0 + else: + return 1 # 鑾峰彇瀹夊叏绗旀暟褰卞搷姣斾緥 def get_safe_count_rate(self): - rates = [0, -0.1, -0.2, -0.4, -0.6, -0.8, -0.8, -0.8] + rates = [0, -0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7] volume_rate_index = self.volume_rate_index if self.volume_rate_index >= len(rates): volume_rate_index = -1 return rates[volume_rate_index] def get_safe_count(self): - if self.is_first_code: - if 3 > self.score_index > -1: - return 0 - elif self.score_index < 0: - return 65535 + # if self.is_first_code: + # if self.buy_rank < 4: + # return 2 base_count, min_count, max_count = L2TradeFactorUtil.get_safe_buy_count(self.code, True) rate = self.get_safe_count_rate() count = int(round(base_count * (1 + rate))) - return count + # 鏈�灏�8绗� + return max(count, 8) # 鑾峰彇m鍊煎奖鍝嶆瘮渚� @classmethod def get_m_val_rate(cls, volume_rate_index): - rates = [0.0, 0.0, 0.0, -0.3, -0.4, -0.5, -0.6, -0.7] + rates = [0.0, -0.1, -0.15, -0.2, -0.25, -0.3, -0.35, -0.4] if volume_rate_index >= len(rates): volume_rate_index = -1 return rates[volume_rate_index] - # 鑾峰彇m鍊� - def get_m_val(self): - if self.is_first_code: - if self.score_index == 0: - return 0, "" - elif self.score_index == 1: - return 1000 * 10000, "" - elif self.score_index == 2: - return 1000 * 10000, "" - elif self.score_index < 0: - return 65535 * 10000, "" - # 鑾峰彇鍥哄畾m鍊� - zyltgb = global_util.zyltgb_map.get(self.code) + @classmethod + def get_base_m_val(cls, code): + zyltgb = global_util.zyltgb_map.get(code) if zyltgb is None: global_data_loader.load_zyltgb() - zyltgb = global_util.zyltgb_map.get(self.code) - + zyltgb = global_util.zyltgb_map.get(code) base_m = L2TradeFactorUtil.get_base_safe_val(zyltgb) + return base_m + + # 鑾峰彇m鍊� + def get_m_val(self): + base_m = self.get_base_m_val(self.code) + if self.is_first_place_order(self.code) and tool.is_sz_code(self.code): + base_m = int(base_m * 2) rate = self.get_m_val_rate(self.volume_rate_index) m = round(base_m * (1 + rate)) return m, "" @@ -127,7 +229,8 @@ # 鑾峰彇涔版椂闂磋寖鍥�(璺濈鎵ц浣�)锛岃繑鍥瀞 @staticmethod def get_buy_time_range(volume_rate_index): - seconds = [pow(2, 1), pow(2, 2), pow(2, 3), pow(2, 4), pow(2, 4), pow(2, 5), pow(2, 6), pow(2, 6)] + # rates = [0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6] + seconds = [pow(2, 1), pow(2, 2), pow(2, 3), pow(2, 4), pow(2, 5), pow(2, 5), pow(2, 4), pow(2, 4)] if volume_rate_index >= len(seconds): volume_rate_index = -1 return seconds[volume_rate_index] @@ -135,10 +238,10 @@ # 鑾峰彇鎾ら攢姣斾緥 @staticmethod def get_cancel_rate(volume_rate_index): - rates = [0.39, 0.49, 0.59, 0.69, 0.69, 0.79, 0.79, 0.79] + rates = [0.34, 0.44, 0.54, 0.64, 0.74, 0.84, 0.94, 1.04] if volume_rate_index >= len(rates): volume_rate_index = -1 - return rates[volume_rate_index] + return 0.79 # rates[volume_rate_index] # H鎾ゅ弬鏁� @@ -155,10 +258,12 @@ # 鑾峰彇鎾ら攢姣斾緥 @staticmethod def get_cancel_rate(volume_rate_index): - rates = [0.39, 0.49, 0.59, 0.69, 0.69, 0.79, 0.79, 0.79] - if volume_rate_index >= len(rates): - volume_rate_index = -1 - return rates[volume_rate_index] + # 鏆傛椂鍥哄畾姝� + # rates = [0.35, 0.45, 0.55, 0.65, 0.65, 0.75, 0.75, 0.75] + # if volume_rate_index >= len(rates): + # volume_rate_index = -1 + # return rates[volume_rate_index] + return 0.89 class L2TradeFactorUtil: @@ -170,8 +275,9 @@ yi = round(zyltgb / 100000000) if yi < 1: yi = 1 - m = 5000000 + (yi - 1) * 500000 - return round(m * (1 - 0.3)) + return int(-0.058 * yi * yi + 60.9 * yi) * 10000 + # m = 5000000 + (yi - 1) * 500000 + # return round(m * (1 - 0.3)) # 鑾峰彇琛屼笟褰卞搷姣斾緥 # total_limit_percent涓虹粺璁$殑姣斾緥涔嬪拰涔樹互100 @@ -333,11 +439,11 @@ # 棣栨娑ㄥ仠鏃堕棿 limit_up_time = global_util.limit_up_time.get(code) if limit_up_time is None: - limit_up_time = limit_up_time_manager.get_limit_up_time(code) + limit_up_time = limit_up_time_manager.LimitUpTimeManager().get_limit_up_time_cache(code) big_money_num = global_util.big_money_num.get(code) if big_money_num is None: - big_money_num = big_money_num_manager.get_num(code) + big_money_num = big_money_num_manager.get_num_cache(code) return ( zyltgb, total_industry_limit_percent, volumn_day60_max, volumn_yest, volumn_today, limit_up_time, big_money_num) @@ -387,7 +493,7 @@ MAX_VAL = 13 if not gb: # 榛樿8绗� - return MIN_VAL,MIN_VAL, MAX_VAL + return MIN_VAL, MIN_VAL, MAX_VAL count = gb // 100000000 if True: if count < 8: @@ -435,8 +541,9 @@ # print(L2TradeFactorUtil.get_safe_buy_count("003005")) # print(L2TradeFactorUtil.get_rate_factors("003004")) # print(L2TradeFactorUtil.factors_to_string("003004")) - for i in range(2, 15): - print(i, L2TradeFactorUtil.get_base_safe_val(100000000 * i)) + + # for i in range(2, 150): + print(22, L2TradeFactorUtil.get_base_safe_val(100000000 * 22)) # print(L2TradeFactorUtil.get_limit_up_time_rate("11:30:00")) # print(L2TradeFactorUtil.get_limit_up_time_rate("13:00:00")) # print(L2TradeFactorUtil.get_limit_up_time_rate("13:48:00")) -- Gitblit v1.8.0