From 954e42723fab626b33f6dbff9246bd235981fe7a Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期五, 09 十二月 2022 19:22:38 +0800 Subject: [PATCH] 撤单策略初步修改 --- l2_data_manager_new.py | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 151 insertions(+), 10 deletions(-) diff --git a/l2_data_manager_new.py b/l2_data_manager_new.py index 7a795bd..a1df0b4 100644 --- a/l2_data_manager_new.py +++ b/l2_data_manager_new.py @@ -217,14 +217,15 @@ state = trade_manager.get_trade_state(code) start_index = len(total_datas) - len(add_datas) end_index = len(total_datas) - 1 - if state == trade_manager.TRADE_STATE_BUY_DELEGATED or state == trade_manager.TRADE_STATE_BUY_PLACE_ORDER: + if state == trade_manager.TRADE_STATE_BUY_DELEGATED or state == trade_manager.TRADE_STATE_BUY_PLACE_ORDER or state == trade_manager.TRADE_STATE_BUY_SUCCESS: # 宸叉寕鍗� cls.__process_order(code, start_index, end_index, capture_timestamp) else: # 鏈寕鍗� cls.__process_not_order(code, start_index, end_index, capture_timestamp) - logger_l2_process.info("code:{} 澶勭悊鏁版嵁鑼冨洿: {}-{} 澶勭悊鏃堕棿:{}", code, add_datas[0]["index"], - add_datas[-1]["index"], round(t.time() * 1000) - __start_time) + logger_l2_process.info("code:{} 澶勭悊鏁版嵁鑼冨洿: {}-{} 澶勭悊鏃堕棿:{} 鎴浘鏃堕棿鎴筹細{}", code, add_datas[0]["index"], + add_datas[-1]["index"], round(t.time() * 1000) - __start_time, + capture_timestamp) __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time, "l2鏁版嵁澶勭悊鏃堕棿") # 淇濆瓨鏁版嵁 l2_data_manager.save_l2_data(code, datas, add_datas) @@ -258,7 +259,7 @@ buy_single_index, buy_exec_index, buy_compute_index, num, count = cls.__get_order_begin_pos(code) # 鎾ゅ崟璁$畻,鍙湅涔�1 cancel_data, cancel_msg = L2LimitUpMoneyStatisticUtil.process_data(code, start_index, end_index, - buy_single_index) + buy_single_index, buy_exec_index) # 璁$畻m鍊煎ぇ鍗� cls.l2BigNumForMProcessor.process(code, max(buy_single_index, start_index), end_index, @@ -368,7 +369,7 @@ return False, "鍚屼竴鏉垮潡涓�佷笁,鑰佸洓,...涓嶈兘涔�" if cls.__codeActualPriceProcessor.is_under_water(code): - # 姘翠笅鎹炰笖鏉垮潡涓殑绁ㄥ皬浜�21涓嶈兘涔� + # 姘翠笅鎹炰笖鏉垮潡涓殑绁ㄥ皬浜�16涓嶈兘涔� if global_util.industry_hot_num.get(industry) is not None and global_util.industry_hot_num.get( industry) <= 16: return False, "姘翠笅鎹�,鏉垮潡涓殑绁ㄥ皬浜�2鍙�,涓簕}".format(global_util.industry_hot_num.get(industry)) @@ -518,7 +519,8 @@ l2_data_manager.TradePointManager.delete_buy_cancel_point(code) # 娑ㄥ仠灏佸崟棰濊绠� - L2LimitUpMoneyStatisticUtil.process_data(code, buy_single_index, compute_index, buy_single_index, False) + L2LimitUpMoneyStatisticUtil.process_data(code, buy_single_index, compute_index, buy_single_index, + buy_exec_index, False) _start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "璁板綍鎵ц涔板叆鏁版嵁") @@ -628,7 +630,13 @@ count = threshold_count - sub_threshold_count if count < 3: count = 3 - return round(count*buy1_factor) + count = round(count * buy1_factor) + # 鏈�楂�30绗旓紝鏈�浣�8绗� + if count > 30: + count = 30 + if count < 8: + count = 8 + return count _start_time = t.time() total_datas = local_today_datas[code] @@ -846,6 +854,17 @@ return True, "9:30娑ㄥ仠鐨勮�佸ぇ锛岃�佷簩鍙互涓嬪崟" return False, "鑰佸ぇ闈�9:30娑ㄥ仠锛岃�佷簩涓嶈兘涓嬪崟" + @classmethod + def test3(cls): + code = "002693" + load_l2_data(code, True) + start_index = 334 + end_index = 341 + buy_single_index = 152 + cls.random_key[code] = random.randint(0, 100000) + L2LimitUpMoneyStatisticUtil.process_data(code, start_index, end_index, + buy_single_index) + # 娑ㄥ仠灏佸崟棰濈粺璁� class L2LimitUpMoneyStatisticUtil: @@ -969,12 +988,13 @@ # 杩斿洖鍙栨秷鐨勬爣蹇楁暟鎹� # with_cancel 鏄惁闇�瑕佸垽鏂槸鍚︽挙閿� @classmethod - def process_data(cls, code, start_index, end_index, buy_single_begin_index, with_cancel=True): + def process_data(cls, code, start_index, end_index, buy_single_begin_index, buy_exec_index, with_cancel=True): start_time = round(t.time() * 1000) total_datas = local_today_datas[code] time_dict_num = {} # 璁板綍璁$畻鐨勫潗鏍� time_dict_num_index = {} + # 鍧愭爣-閲忕殑map num_dict = {} # 缁熻鏃堕棿鍒嗗竷 time_dict = {} @@ -1022,8 +1042,39 @@ time_list = [] # 鍒板綋鍓嶆椂闂寸疮绉殑涔�1閲� time_total_num_dict = {} + + # 澶у崟鎾ら攢绗旀暟 + cancel_big_num_count = 0 + buy_exec_time = tool.get_time_as_second(total_datas[buy_exec_index]) + # 浠庡悓鑺遍『涔�1鐭杩囧悗鐨勪綅缃紑濮嬭绠楋紝鍒癳nd_index缁撴潫 + for i in range(index + 1, end_index + 1): data = total_datas[i] + # 缁熻鎾ら攢鏁伴噺 + if big_money_num_manager.is_big_num(data["val"]): + if L2DataUtil.is_limit_up_price_buy_cancel(data["val"]): + cancel_big_num_count += int(data["re"]) + # TODO 澶ч噺閲嶅鐨勫伐浣滈渶瑕佸鐞嗭紝鍙互鏆傚瓨鍦ㄥ唴瀛樹腑锛屼粠鑰屽噺灏戣绠� + # 鑾峰彇鏄惁鍦ㄤ拱鍏ユ墽琛屼俊鍙峰懆鍥�2s + buy_index, buy_data = l2_data_util.get_buy_data_with_cancel_data(data["val"], + local_today_num_operate_map.get( + code)) + if buy_index is not None and buy_data is not None: + # 鐩稿樊1s + buy_time = buy_data["val"]["time"] + if abs(buy_exec_time - tool.get_time_as_second(buy_time)) < 2: + cancel_big_num_count += int(data["re"]) + + elif L2DataUtil.is_limit_up_price_buy(data["val"]): + cancel_big_num_count -= int(data["re"]) + + threshold_rate = 0.5 + if cancel_big_num_count >= 0: + if cancel_big_num_count < 10: + threshold_rate = threshold_rate - cancel_big_num_count * 0.01 + else: + threshold_rate = threshold_rate - 10 * 0.01 + time_ = data["val"]["time"] if time_ not in time_start_index_dict: # 璁板綍姣忎竴绉掔殑寮�濮嬩綅缃� @@ -1048,12 +1099,27 @@ # 涓�1s鐨勬�绘暟 last_second_total_volumn = time_total_num_dict.get(time_list[-1]) if last_second_total_volumn > 0 and ( - last_second_total_volumn - total_num) / last_second_total_volumn >= 0.5: + last_second_total_volumn - total_num) / last_second_total_volumn >= threshold_rate: # 鐩搁偦2s鍐呯殑鏁版嵁鍑忓皬50% cancel_index = i cancel_msg = "鐩搁偦2s({})鍐呯殑灏佸崟閲忓噺灏�50%({}->{})".format(time_, last_second_total_volumn, total_num) break + # 璁板綍涓湁涓�2涓暟鎹� + if len(time_list) >= 2: + # 鍊掓暟绗�2涓暟鎹� + last_2_second_total_volumn = time_total_num_dict.get(time_list[-2]) + if last_2_second_total_volumn > 0: + if last_2_second_total_volumn > last_second_total_volumn > total_num: + dif = last_2_second_total_volumn - total_num + if dif / last_2_second_total_volumn >= threshold_rate: + cancel_index = i + cancel_msg = "鐩搁偦3s({})鍐呯殑灏佸崟閲�(绗�3绉� 涓� 绗�1鐨� 鍑忓皬姣斾緥)鍑忓皬50%({}->{}->{})".format(time_, + last_2_second_total_volumn, + last_second_total_volumn, + total_num) + break + if not with_cancel: cancel_index = None @@ -1072,7 +1138,82 @@ return None, None +# 娑ㄥ仠鍗栫粺璁� +class L2LimitUpSellStatisticUtil: + _redisManager = redis_manager.RedisManager(0) + + @classmethod + def __get_redis(cls): + return cls._redisManager.getRedis() + + # 鏂板鍗栨暟鎹� + @classmethod + def __incre_sell_data(cls, code, num): + key = "limit_up_sell_num-{}".format(code) + cls.__get_redis().incrby(key, num) + + @classmethod + def __get_sell_data(cls, code): + key = "limit_up_sell_num-{}".format(code) + val = cls.__get_redis().get(key) + if val is None: + return 0 + return int(val) + + @classmethod + def __save_process_index(cls, code, index): + key = "limit_up_sell_index-{}".format(code) + cls.__get_redis().setex(key, tool.get_expire(), index) + + @classmethod + def __get_process_index(cls, code): + key = "limit_up_sell_index-{}".format(code) + val = cls.__get_redis().get(key) + if val is None: + return -1 + return int(val) + + # 娓呴櫎鏁版嵁 + @classmethod + def delete(cls, code): + key = "limit_up_sell_num-{}".format(code) + cls.__get_redis().delete(key) + key = "limit_up_sell_index-{}".format(code) + cls.__get_redis().delete(key) + + # 澶勭悊鏁版嵁锛岃繑鍥炴槸鍚﹂渶瑕佹挙鍗� + @classmethod + def process(cls, code, start_index, end_index, buy_exec_index): + # 鑾峰彇娑ㄥ仠鍗栫殑闃堝�� + limit_up_price = gpcode_manager.get_limit_up_price(code) + zyltgb = l2_trade_factor.L2TradeFactorUtil.get_zyltgb(code) + threshold_num = zyltgb * 0.015 // (limit_up_price * 100) + total_num = cls.__get_sell_data(code) + cancel_index = None + process_index = cls.__get_process_index(code) + for i in range(start_index, end_index + 1): + if i < buy_exec_index: + continue + if i <= process_index: + continue + total_datas = local_today_datas.get(code) + if L2DataUtil.is_limit_up_price_sell(total_datas[i]["val"]): + num = int(total_datas[i]["val"]["num"]) + cls.__incre_sell_data(code, num) + total_num += num + if total_num > threshold_num: + cancel_index = i + break + if cancel_index is not None: + process_index = cancel_index + else: + process_index = end_index + # 淇濆瓨澶勭悊鐨勪綅缃� + cls.__save_process_index(code, process_index) + return cancel_index + + if __name__ == "__main__": - L2TradeDataProcessor.test2() + L2TradeDataProcessor.test3() print("----------------------") # L2TradeDataProcessor.test() -- Gitblit v1.8.0