From 48dcb788e821d40be37fa05c9789b751a6e2a69b Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期五, 13 一月 2023 16:38:45 +0800 Subject: [PATCH] H撤大单修改 --- l2_data_manager_new.py | 265 ++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 183 insertions(+), 82 deletions(-) diff --git a/l2_data_manager_new.py b/l2_data_manager_new.py index acf94b3..279b9c5 100644 --- a/l2_data_manager_new.py +++ b/l2_data_manager_new.py @@ -301,7 +301,8 @@ if end_index < start_index: return # 鑾峰彇涔板叆淇″彿璧峰鐐� - buy_single_index, buy_exec_index, buy_compute_index, num, count = cls.__get_order_begin_pos(code) + buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos( + code) # 鎾ゅ崟璁$畻,鍙湅涔�1 cancel_data, cancel_msg = L2LimitUpMoneyStatisticUtil.process_data(code, start_index, end_index, @@ -389,7 +390,8 @@ trade_data_manager.placeordercountmanager.place_order(code) # 鑾峰彇涔板叆浣嶇疆淇℃伅 try: - buy_single_index, buy_exec_index, buy_compute_index, num, count = cls.__get_order_begin_pos(code) + buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos( + code) SecondAverageBigNumComputer.place_order_success(code, buy_single_index, buy_exec_index) AverageBigNumComputer.place_order_success(code, buy_single_index, buy_exec_index) LongAverageBigNumComputer.place_order_success(code, buy_single_index, buy_exec_index) @@ -454,7 +456,8 @@ if sell1_time is not None and sell1_volumn > 0: # 鑾峰彇鎵ц浣嶄俊鎭� total_datas = local_today_datas[code] - buy_single_index, buy_exec_index, buy_compute_index, num, count = cls.__get_order_begin_pos(code) + buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos( + code) buy_nums = num for i in range(buy_exec_index + 1, total_datas[-1]["index"] + 1): _val = total_datas[i]["val"] @@ -558,7 +561,8 @@ # 鏄惁鏄氦鏄撻槦鍒楄Е鍙� if source == "trade_queue": # 浜ゆ槗闃熷垪瑙﹀彂鐨勯渶瑕佷笅鍗曞悗5s - buy_single_index, buy_exec_index, buy_compute_index, num, count = cls.__get_order_begin_pos(code) + buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos( + code) total_datas = local_today_datas[code] if buy_exec_index is not None and buy_exec_index > 0: now_time_str = datetime.datetime.now().strftime("%H:%M:%S") @@ -603,7 +607,8 @@ _start_time = round(t.time() * 1000) total_datas = local_today_datas[code] # 鑾峰彇涔板叆淇″彿璁$畻璧峰浣嶇疆 - buy_single_index, buy_exec_index, buy_compute_index, num, count = cls.__get_order_begin_pos(code) + buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_index = cls.__get_order_begin_pos( + code) # 鏄惁涓烘柊鑾峰彇鍒扮殑浣嶇疆 if buy_single_index is None: @@ -619,7 +624,8 @@ if has_single: num = 0 count = 0 - cls.debug(code, "鑾峰彇鍒颁拱鍏ヤ俊鍙疯捣濮嬬偣锛歿} 鏁版嵁锛歿}", buy_single_index, total_datas[buy_single_index]) + cls.debug(code, "鑾峰彇鍒颁拱鍏ヤ俊鍙疯捣濮嬬偣锛歿} ,璁$畻鑼冨洿锛歿}-{} 锛屾暟鎹細{}", buy_single_index, compute_start_index, + compute_end_index, total_datas[buy_single_index]) # 濡傛灉鏄粖澶╃涓�娆℃湁涓嬪崟寮�濮嬩俊鍙凤紝闇�瑕佽缃ぇ鍗曡捣濮嬬偣 cls.l2BigNumForMProcessor.set_begin_pos(code, buy_single_index) @@ -637,12 +643,16 @@ threshold_money, msg = cls.__get_threshmoney(code) # 涔板叆绾拱棰濈粺璁� - compute_index, buy_nums, buy_count, rebegin_buy_pos = cls.__sum_buy_num_for_order_3(code, max(buy_single_index, - compute_start_index), - compute_end_index, num, - count, threshold_money, - buy_single_index, - capture_time) + compute_index, buy_nums, buy_count, rebegin_buy_pos, max_num_index_new = cls.__sum_buy_num_for_order_3(code, + max( + buy_single_index, + compute_start_index), + compute_end_index, + num, + count, + threshold_money, + buy_single_index, + max_num_index) _start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "绾拱棰濈粺璁℃椂闂�") cls.debug(code, "m鍊�-{} m鍊煎洜瀛�-{}", threshold_money, msg) @@ -658,7 +668,8 @@ buy_count, total_datas[compute_index]) # 璁板綍涔板叆淇″彿浣嶇疆 - cls.__save_order_begin_data(code, buy_single_index, compute_index, compute_index, buy_nums, buy_count) + cls.__save_order_begin_data(code, buy_single_index, compute_index, compute_index, buy_nums, buy_count, + max_num_index_new) # 濡傛灉鏄粖澶╃涓�娆℃湁涓嬪崟鎵ц淇″彿锛屾定鍋滄椂闂达紙涔板叆鎵ц浣嶆椂闂达級 limit_up_time_manager.save_limit_up_time(code, total_datas[compute_index]["val"]["time"]) # 铏氭嫙涓嬪崟 @@ -702,7 +713,8 @@ else: # 鏈揪鍒颁笅鍗曟潯浠讹紝淇濆瓨绾拱棰濓紝璁剧疆绾拱棰� # 璁板綍涔板叆淇″彿浣嶇疆 - cls.__save_order_begin_data(code, buy_single_index, -1, compute_end_index, buy_nums, buy_count) + cls.__save_order_begin_data(code, buy_single_index, -1, compute_end_index, buy_nums, buy_count, + max_num_index_new) print("淇濆瓨澶у崟鏃堕棿", round((t.time() - _start_time) * 1000)) _start_time = t.time() pass @@ -710,14 +722,15 @@ # 鑾峰彇涓嬪崟璧峰淇″彿 @classmethod def __get_order_begin_pos(cls, code): - buy_single_index, buy_exec_index, compute_index, num, count = l2_data_manager.TradePointManager.get_buy_compute_start_data( + buy_single_index, buy_exec_index, compute_index, num, count, max_num_index = l2_data_manager.TradePointManager.get_buy_compute_start_data( code) - return buy_single_index, buy_exec_index, compute_index, num, count + return buy_single_index, buy_exec_index, compute_index, num, count, max_num_index # 淇濆瓨涓嬪崟璧峰淇″彿 @classmethod - def __save_order_begin_data(self, code, buy_single_index, buy_exec_index, compute_index, num, count): - TradePointManager.set_buy_compute_start_data(code, buy_single_index, buy_exec_index, compute_index, num, count) + def __save_order_begin_data(self, code, buy_single_index, buy_exec_index, compute_index, num, count, max_num_index): + TradePointManager.set_buy_compute_start_data(code, buy_single_index, buy_exec_index, compute_index, num, count, + max_num_index) # 璁$畻涓嬪崟璧峰淇″彿 # compute_data_count 鐢ㄤ簬璁$畻鐨刲2鏁版嵁鏁伴噺 @@ -770,9 +783,9 @@ # 鏄惁涓轰竾鎵嬪摜 @classmethod def __is_big_money(cls, limit_up_price, val): - if int(val["num"]) >= 7888: + if int(val["num"]) >= constant.BIG_MONEY_NUM: return True - if int(val["num"]) * limit_up_price >= 29900: + if int(val["num"]) * limit_up_price >= constant.BIG_MONEY_AMOUNT: return True return False @@ -790,7 +803,7 @@ # 缁熻涔板叆鍑�涔伴噺锛屼笉璁$畻鍦ㄤ拱鍏ヤ俊鍙蜂箣鍓嶇殑涔版挙鍗� @classmethod def __sum_buy_num_for_order_3(cls, code, compute_start_index, compute_end_index, origin_num, origin_count, - threshold_money, buy_single_index, capture_time): + threshold_money, buy_single_index, max_num_index): def get_threshold_count(): count = threshold_count - sub_threshold_count if count < 3: @@ -837,10 +850,15 @@ # 鍙互瑙﹀彂涔帮紝褰撴湁娑ㄥ仠涔颁俊鍙锋椂鎵嶄細瑙﹀彂涔� trigger_buy = True place_order_count = trade_data_manager.placeordercountmanager.get_place_order_count(code) - if place_order_count>3: + if place_order_count > 3: place_order_count = 3 # 闂撮殧鏈�澶ф椂闂翠緷娆′负锛�3,9,27,81 - max_space_time = pow(3,place_order_count + 1) - 1 + max_space_time = pow(3, place_order_count + 1) - 1 + # 鏈�澶т拱閲� + max_buy_num = 0 + max_buy_num_index = max_num_index + if max_num_index > -1: + max_buy_num = int(total_datas[max_num_index]["val"]["num"]) for i in range(compute_start_index, compute_end_index + 1): data = total_datas[i] _val = total_datas[i]["val"] @@ -850,17 +868,20 @@ TradePointManager.delete_buy_point(code) if i == compute_end_index: # 鏁版嵁澶勭悊瀹屾瘯 - return None, buy_nums, buy_count, None + return None, buy_nums, buy_count, None, max_buy_num_index else: # 璁$畻涔板叆淇″彿锛屼笉鑳藉悓涓�鏃堕棿寮�濮嬭绠� for ii in range(buy_single_index + 1, compute_end_index + 1): if total_datas[buy_single_index]["val"]["time"] != total_datas[ii]["val"]["time"]: - return None, buy_nums, buy_count, ii + return None, buy_nums, buy_count, ii, max_buy_num_index # 娑ㄥ仠涔� if L2DataUtil.is_limit_up_price_buy(_val): if cls.__is_big_money(limit_up_price, _val): sub_threshold_count += int(total_datas[i]["re"]) if round(int(_val["num"]) * float(_val["price"])) >= 5900: + if int(_val["num"]) > max_buy_num: + max_buy_num = int(_val["num"]) + max_buy_num_index = i trigger_buy = True # 鍙粺璁�59涓囦互涓婄殑閲戦 buy_nums += int(_val["num"]) * int(total_datas[i]["re"]) @@ -901,15 +922,16 @@ cls.buy_debug(code, "浣嶇疆-{}锛屾�绘墜鏁帮細{}锛岀洰鏍囨墜鏁帮細{}", i, buy_nums, threshold_num) # 鏈夋挙鍗曚俊鍙凤紝涓斿皬浜庨槇鍊� - if buy_nums >= threshold_num and buy_count >= get_threshold_count() and trigger_buy: - return i, buy_nums, buy_count, None + if buy_nums >= threshold_num and buy_count >= get_threshold_count() and trigger_buy and max_buy_num_index > -1 and cls.__is_big_money( + limit_up_price, total_datas[max_buy_num_index]["val"]): + return i, buy_nums, buy_count, None, max_buy_num_index cls.buy_debug(code, "灏氭湭鑾峰彇鍒颁拱鍏ユ墽琛岀偣锛岃捣濮嬭绠椾綅缃細{} 缁熻绾拱鎵嬫暟锛歿} 鐩爣绾拱鎵嬫暟锛歿} 缁熻绾拱鍗曟暟锛歿} 鐩爣绾拱鍗曟暟锛歿} 澶у崟鏁伴噺锛歿}", compute_start_index, buy_nums, threshold_num, buy_count, get_threshold_count(), sub_threshold_count) - return None, buy_nums, buy_count, None + return None, buy_nums, buy_count, None, max_buy_num_index @classmethod def test(cls): @@ -1063,6 +1085,7 @@ # 娑ㄥ仠灏佸崟棰濈粺璁� class L2LimitUpMoneyStatisticUtil: _redisManager = redis_manager.RedisManager(1) + _thsBuy1VolumnManager = trade_queue_manager.THSBuy1VolumnManager() @classmethod def __get_redis(cls): @@ -1243,6 +1266,10 @@ # 澶у崟鎾ら攢绗旀暟 cancel_big_num_count = 0 buy_exec_time = tool.get_time_as_second(total_datas[buy_exec_index]["val"]["time"]) + + # 鑾峰彇鏈�澶у皝鍗曢 + max_buy1_volume = cls._thsBuy1VolumnManager.get_max_buy1_volume(code) + # 浠庡悓鑺遍『涔�1鐭杩囧悗鐨勪綅缃紑濮嬭绠楋紝鍒癳nd_index缁撴潫 for i in range(index + 1, end_index + 1): @@ -1294,6 +1321,12 @@ if start_index <= i <= end_index: # 濡傛灉鏄噺灏忛」 if val < 0: + # 褰撳墠閲忓皬浜庢渶澶ч噺鐨�24%鍒欓渶瑕佸彇娑� + if exec_time_offset >= 30: + if total_num <= min_volumn_big and max_buy1_volume * 0.24 > total_num: + cancel_index = i + cancel_msg = "灏佹澘棰濆皬浜庢渶楂樺皝鏉块鐨�24% {}/{}".format(total_num, max_buy1_volume) + break # 绱灏佸崟閲戦灏忎簬1000涓� if total_num < min_volumn: # 涓庢墽琛屼綅鐩搁殧>=5s鏃惰鍒欑敓鏁� @@ -1331,7 +1364,7 @@ break # ------澶у崟鎾ゅ鐞�------- # if total_num < min_volumn_big: - if exec_time_offset < 1800: + if exec_time_offset < 31: pass # try: # b_need_cancel, b_cancel_index = AverageBigNumComputer.need_cancel(code, i, i) @@ -1341,14 +1374,14 @@ # break # except Exception as e: # logging.exception(e) - # 30鍒嗛挓澶栨墠鎵ц - elif 1800 <= exec_time_offset <= 5400: + # 30s澶栨墠鎵ц + elif 31 <= exec_time_offset: try: b_need_cancel, b_cancel_index = LongAverageBigNumComputer.need_cancel(code, buy_exec_index, i, i) if b_need_cancel: cancel_index = b_cancel_index - cancel_msg = "60s-1h鍐呭ぇ鍗曟挙閿�姣斾緥瑙﹀彂闃堝��" + cancel_msg = "30s鍚庡唴澶у崟鎾ら攢姣斾緥瑙﹀彂闃堝��" break except Exception as e: logging.exception(e) @@ -1520,41 +1553,65 @@ val = cls.__getRedis().get(key) return val + # 淇濆瓨缁撴潫浣嶇疆 + @classmethod + def __save_end_index(cls, code, end_index): + key = "s_average_big_num_end_index_set-{}".format(code) + cls.__getRedis().sadd(key, end_index) + + @classmethod + def __list_end_indexs(cls, code): + key = "s_average_big_num_end_index_set-{}".format(code) + vals = cls.__getRedis().smembers(key) + if vals is None: + return None + results = [] + for val in vals: + results.append(int(val)) + results.sort() + return results + @classmethod def __clear_data(cls, code): - key = "s_average_big_num_comput_info-{}".format(code) - cls.__getRedis().delete(key) - key = "s_average_big_num-{}".format(code) - cls.__getRedis().delete(key) + ks = ["s_average_big_num_comput_info-{}".format(code), "s_average_big_num-{}".format(code), + "s_average_big_num_end_index_set-{}".format(code)] + for key in ks: + cls.__getRedis().delete(key) @classmethod def clear_data(cls): - key = "s_average_big_num_comput_info-*" - keys = cls.__getRedis().keys(key) - for k in keys: - cls.__getRedis().delete(k) - key = "s_average_big_num-*" - keys = cls.__getRedis().keys(key) - for k in keys: - cls.__getRedis().delete(k) + ks = ["s_average_big_num_comput_info-*", "s_average_big_num-*", "s_average_big_num_end_index_set-*"] + for key in ks: + keys = cls.__getRedis().keys(key) + for k in keys: + cls.__getRedis().delete(k) # 璁$畻骞冲潎鎵嬫暟 # 璁$畻鑼冨洿锛氫拱鍏ヤ俊鍙疯捣濮嬬偣鍒颁拱鍏ユ墽琛屼綅鐨勪笅涓�寮犲浘缁撴潫鐐规暟鎹负姝� @classmethod def compute_average_big_num(cls, code, buy_single_index, start_index, end_index): + cls.__save_end_index(code, end_index) + # 淇濆瓨缁撴潫浣嶇疆 + end_indexs = cls.__list_end_indexs(code) print("compute_average_big_num", code, buy_single_index, start_index, end_index) L2TradeDataProcessor.cancel_debug(code, "寮�濮嬭绠楃煭澶у崟浣嶇疆") total_data = local_today_datas[code] num = 0 count = 0 - apply_time_second = int(cls.get_apply_time(code).replace(":", "")) + apply_time = cls.get_apply_time(code) + apply_time_second = int(apply_time.replace(":", "")) + for ei in end_indexs: + if int(total_data[ei]["val"]["time"].replace(":", "")) >= apply_time_second: + end_index = ei + break + for i in range(start_index, end_index + 1): data = total_data[i] val = data["val"] - if int(val["time"].replace(":", "")) > apply_time_second: - # 閲嶆柊璁剧疆璁$畻缁撴潫浣嶇疆 - end_index = i - 1 - break + # if int(val["time"].replace(":", "")) > apply_time_second: + # # 閲嶆柊璁剧疆璁$畻缁撴潫浣嶇疆 + # end_index = i - 1 + # break if L2DataUtil.is_limit_up_price_buy(val): # and float(val["price"]) * int(val["num"]) > 7500: # 75涓囦互涓婄殑鎵嶅弬涓庤绠楀钩鍧囧ぇ鍗� @@ -1573,7 +1630,8 @@ num += int(val["num"]) average_num = num // count - average_num = round(5900 / gpcode_manager.get_limit_up_price(code)) + average_num = min(constant.BIG_MONEY_NUM, + round(constant.BIG_MONEY_AMOUNT / gpcode_manager.get_limit_up_price(code))) average_up_count = 0 for i in range(start_index, end_index + 1): data = total_data[i] @@ -1591,10 +1649,16 @@ @classmethod def need_cancel(cls, code, buy_single_index, buy_exec_index, start_index, end_index, need_cancel=True): average_num, average_up_count, a_start_index, a_end_index = cls.__get_average_data(code) - L2TradeDataProcessor.cancel_debug(code,"s绾ф槸鍚﹂渶瑕佹挙鍗曪紝鏁版嵁鑼冨洿锛歿}-{} 骞冲潎澶у崟淇℃伅-({},{},{},{})",start_index,end_index,average_num, average_up_count, a_start_index, a_end_index) + L2TradeDataProcessor.cancel_debug(code, "s绾ф槸鍚﹂渶瑕佹挙鍗曪紝鏁版嵁鑼冨洿锛歿}-{} 骞冲潎澶у崟淇℃伅-({},{},{},{})", start_index, end_index, + average_num, average_up_count, a_start_index, a_end_index) if average_num is None: return False, None total_data = local_today_datas[code] + + # 鍙畧鎶�30s + if tool.trade_time_sub(total_data[start_index]["val"]["time"], total_data[buy_exec_index]["val"]["time"]) > 30: + return False, None + # 濡傛灉start_index涓巄uy_single_index鐩稿悓锛屽嵆鏄笅鍗曞悗鐨勭涓�娆¤绠� # 闇�瑕佹煡璇拱鍏ヤ俊鍙蜂箣鍓嶇殑鍚�1s鏄惁鏈夋定鍋滄挙鐨勬暟鎹� if buy_single_index == start_index: @@ -1625,6 +1689,17 @@ code)) if buy_index is not None and a_start_index <= buy_index <= a_end_index: cls.__save_cancel_data(code, i) + else: + # 鏈夐儴鍒嗘挙閿�浠庤�屽鑷寸殑鏃犳硶婧簮锛岃繖鏃跺氨闇�瑕佸垽鏂浼颁拱鍏ユ椂闂存槸鍚﹀湪a_start_index鍒癮_end_index鐨勬椂闂村尯闂� + min_space, max_space = l2_data_util.compute_time_space_as_second(val["cancelTime"], + val["cancelTimeUnit"]) + # 鍙垽鏂璖绾ф挙閿�,鍙湁s绾ф挙閿�鎵嶆湁鍙兘鐩哥瓑 + if max_space - min_space <= 1: + buy_time = tool.trade_time_add_second(val["time"], 0 - min_space) + if int(total_data[a_start_index]["val"]["time"].replace(":", "")) <= int( + buy_time.replace(":", "")) <= int( + total_data[a_end_index]["val"]["time"].replace(":", "")): + cls.__save_cancel_data(code, i) if need_cancel: # 璁$畻涔版挙澶у崟鏆傛瘮 cancel_datas = cls.__get_cancel_datas(code) @@ -1635,9 +1710,9 @@ if place_order_count <= 1: cancel_rate_threshold = 0.49 elif place_order_count <= 2: - cancel_rate_threshold = 0.549 - else: cancel_rate_threshold = 0.59 + else: + cancel_rate_threshold = 0.69 cancel_indexs = [] for index in cancel_datas: cancel_indexs.append(int(index)) @@ -1717,9 +1792,16 @@ @classmethod def test(cls): - cls.__test(("000909", 607, 646, 646, 694)) + # cls.__test(("000909", 607, 646, 646, 694)) # 浠g爜 涔板叆淇″彿璧峰鐐� 涔板叆淇℃伅鎵ц浣嶇疆 璁$畻鏈綅 鏈�杩滆绠椾綅缃� # cls.__test(("002793", 292, 308, 314, 410)) + cls.__save_end_index("000333", 200) + cls.__save_end_index("000333", 101) + cls.__save_end_index("000333", 99) + cls.__save_end_index("000333", 120) + cls.__save_end_index("000333", 126) + cls.__save_end_index("000333", 126) + print(cls.__list_end_indexs("000333")) # 鎵ц鏄惁闇�瑕佹挙閿� @@ -1810,7 +1892,8 @@ average_num = num // count # average_num = 0 - average_num = round(5900 / gpcode_manager.get_limit_up_price(code)) + average_num = min(constant.BIG_MONEY_NUM, + round(constant.BIG_MONEY_AMOUNT / gpcode_manager.get_limit_up_price(code))) average_up_count = 0 for i in range(start_index, end_index + 1): data = total_data[i] @@ -1825,6 +1908,8 @@ # 鏄惁闇�瑕佹挙鍗� @classmethod def need_cancel(cls, code, buy_single_index, buy_exec_index, start_index, end_index, need_cancel=True): + # 鏆傛椂鍙栨秷姝ゆ挙鍗曟潯浠� + return False, None average_num, average_up_count, a_start_index, a_end_index = cls.__get_average_data(code) if average_num is None: return False, None @@ -1946,27 +2031,29 @@ return cls.__redis_manager.getRedis() @classmethod - def __save_average_data(cls, code, average_num, average_up_count, start_index, end_index): - L2TradeDataProcessor.cancel_debug(code, "鑾峰彇鍒伴暱澶у崟浣嶇疆淇℃伅锛氬钩鍧囨墜鏁�-{} 澶у崟鏁伴噺-{} 璁$畻寮�濮嬭寖鍥�-{}:{}".format(average_num, - average_up_count, - start_index, - end_index)) + def __save_average_data(cls, code, average_num, average_up_count, total_count, start_index, end_index): + L2TradeDataProcessor.cancel_debug(code, "鑾峰彇鍒伴暱澶у崟浣嶇疆淇℃伅锛氬钩鍧囨墜鏁�-{} 澶у崟鏁伴噺-{} 鏍锋湰鏁伴噺-{} 璁$畻寮�濮嬭寖鍥�-{}:{}".format(average_num, + average_up_count, + total_count, + start_index, + end_index)) key = "l_average_big_num-{}".format(code) - cls.__getRedis().setex(key, 3600, json.dumps((average_num, average_up_count, start_index, end_index))) + cls.__getRedis().setex(key, tool.get_expire(), + json.dumps((average_num, average_up_count, total_count, start_index, end_index))) @classmethod def __get_average_data(cls, code): key = "l_average_big_num-{}".format(code) val = cls.__getRedis().get(key) if val is None: - return None, None, None, None + return None, None, None, None, None val = json.loads(val) - return val[0], val[1], val[2], val[3] + return val[0], val[1], val[2], val[3], val[4] @classmethod def __save_compute_info(cls, code, cancel_count, process_index): key = "l_average_big_num_comput_info-{}".format(code) - cls.__getRedis().setex(key, 3600, json.dumps((cancel_count, process_index))) + cls.__getRedis().setex(key, tool.get_expire(), json.dumps((cancel_count, process_index))) @classmethod def __get_compute_info(cls, code): @@ -1989,14 +2076,14 @@ @classmethod def compute_average_big_num(cls, code, buy_single_index, buy_exec_index): total_data = local_today_datas[code] + latest_index = total_data[-1]["index"] end_index = total_data[-1]["index"] - start_index = buy_single_index + start_index = buy_exec_index if tool.trade_time_sub(total_data[end_index]["val"]["time"], total_data[buy_exec_index]["val"]["time"]) < 3: return - exec_time = total_data[buy_exec_index]["val"]["time"] - o_average_num, o_average_up_count, o_start_index, o_start_index = cls.__get_average_data(code) - if o_average_num is not None: + o_average_num, o_average_up_count, o_count, o_start_index, o_start_index = cls.__get_average_data(code) + if o_average_num is not None and o_count >= constant.H_CANCEL_BUY_COUNT: return # 鑾峰彇涔板叆鎵ц浣嶅悗2s鐨勬暟鎹湯浣� for i in range(end_index, buy_exec_index, - 1): @@ -2009,32 +2096,46 @@ for i in range(start_index, end_index + 1): data = total_data[i] val = data["val"] - if L2DataUtil.is_limit_up_price_buy(val): + if L2DataUtil.is_limit_up_price_buy(val) and int(val["num"]) * float(val["price"]) >= 5900: count += data["re"] - num += int(val["num"]) - average_num = num / count - average_num = round(average_num) + num += int(val["num"]) * data["re"] + # 濡傛灉灏忎簬30绗旓紝闇�瑕佸啀寰�鍚庤绠� + if count < constant.H_CANCEL_BUY_COUNT: + for i in range(end_index + 1, latest_index + 1, 1): + data = total_data[i] + val = data["val"] + if L2DataUtil.is_limit_up_price_buy(val) and int(val["num"]) * float(val["price"]) >= 5900: + count += data["re"] + num += int(val["num"]) * data["re"] + if count >= constant.H_CANCEL_BUY_COUNT: + end_index = i + break + # 鑾峰彇澶у崟鏁伴噺 average_up_count = 0 + average_num = round(num / count) for i in range(start_index, end_index + 1): data = total_data[i] val = data["val"] - if L2DataUtil.is_limit_up_price_buy(val): - if int(val["num"]) >= average_num: - average_up_count += data["re"] + if int(val["num"]) >= average_num: + average_up_count += data["re"] + # 淇濆瓨鏁版嵁 - cls.__save_average_data(code, average_num, average_up_count, start_index, end_index) + cls.__save_average_data(code, average_num, average_up_count, count, start_index, end_index) cls.__save_compute_info(code, 0, buy_exec_index) # 鏄惁闇�瑕佹挙鍗� @classmethod def need_cancel(cls, code, buy_exec_index, start_index, end_index): - average_num, average_up_count, a_start_index, a_end_index = cls.__get_average_data(code) + average_num, average_up_count, total_count, a_start_index, a_end_index = cls.__get_average_data(code) if average_num is None: return False, None cancel_count, process_index = cls.__get_compute_info(code) total_data = local_today_datas[code] + # 14:30杩囧悗涓嶅啀瀹堟姢 + if int(total_data[end_index]["val"]["time"].replace(":", "")) > int("143000"): + return False, None try: - for i in range(start_index, end_index + 1): + for i in range(min(start_index, buy_exec_index + 1), end_index + 1): if i <= buy_exec_index: continue if process_index >= i: @@ -2050,11 +2151,9 @@ # 涔板叆浣嶇疆瑕佸湪骞冲潎鍊艰绠楄寖鍥村唴 cancel_count += data["re"] process_index = i - if tool.trade_time_sub(val["time"], total_data[buy_exec_index]["val"]["time"]) > 3600: - continue sj = 0 # 5 * tool.trade_time_sub(val["time"],total_data[buy_exec_index]["val"]["time"]) - print("璁$畻缁撴灉", cancel_count, average_up_count, sj) - if cancel_count / (average_up_count - sj) >= 0.79: + print("h骞冲潎澶у崟璁$畻缁撴灉:", "鍙栨秷鏁伴噺", cancel_count, "澶у崟鎬绘暟", average_up_count, sj) + if cancel_count / (average_up_count - sj) >= 0.75: return True, i finally: cls.__save_compute_info(code, cancel_count, process_index) @@ -2094,6 +2193,8 @@ if __name__ == "__main__": + # trade_manager.start_cancel_buy("000637") + # t.sleep(10) # AverageBigNumComputer.test() # LongAverageBigNumComputer.test() # L2TradeDataProcessor.test() -- Gitblit v1.8.0