From f03eb72394a3fac097bb3ab1f956a83f99f7bd0e Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期四, 03 十一月 2022 17:11:37 +0800 Subject: [PATCH] 优化撤单与动态m值计算 --- l2_data_manager_new.py | 75 ++++++++++++++++++++++--------------- 1 files changed, 44 insertions(+), 31 deletions(-) diff --git a/l2_data_manager_new.py b/l2_data_manager_new.py index 81a9a86..4c01846 100644 --- a/l2_data_manager_new.py +++ b/l2_data_manager_new.py @@ -226,7 +226,8 @@ __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) - __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time, "淇濆瓨鏁版嵁鏃堕棿") + __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time, + "淇濆瓨鏁版嵁鏃堕棿锛坽}锛�".format(len(add_datas))) finally: if code in cls.unreal_buy_dict: @@ -235,23 +236,10 @@ # 澶勭悊鏈寕鍗� @classmethod def __process_not_order(cls, code, start_index, end_index, capture_time): + _start_time = t.time() # 鑾峰彇闃堝�� threshold_money, msg = cls.__get_threshmoney(code) cls.__start_compute_buy(code, start_index, end_index, threshold_money, capture_time) - - @classmethod - def __statistic_count_l2_data_for_cancel(cls, code, start_index, end_index, has_cancel_single=False): - index, old_buy_count, old_cancel_count = l2_data_manager.TradePointManager.get_count_info_for_cancel_buy(code) - for i in range(start_index, end_index + 1): - buy_count, buy_cancel_count = cls.__count_l2_data_for_cancel(code, i, i) - old_buy_count += buy_count - - old_cancel_count += buy_cancel_count - if old_buy_count > 0 and (old_buy_count - old_cancel_count) / old_buy_count < 0.3 and has_cancel_single: - return i, True - l2_data_manager.TradePointManager.set_count_info_for_cancel_buy(code, end_index, old_buy_count, - old_cancel_count) - return end_index, False # 澶勭悊宸叉寕鍗� @classmethod @@ -274,7 +262,7 @@ if cancel_data: cls.debug(code, "瑙﹀彂鎾ゅ崟锛屾挙鍗曚綅缃細{} 锛屾挙鍗曞師鍥狅細{}", cancel_data["index"], cancel_msg) # 鎾ゅ崟 - cls.cancel_buy(code) + cls.cancel_buy(code,cancel_msg) # 缁х画璁$畻涓嬪崟 cls.__process_not_order(code, cancel_data["index"] + 1, end_index, capture_time) else: @@ -338,12 +326,12 @@ if codes_index.get(code) != 0: return False, "姘翠笅鎹�,涓嶆槸鑰佸ぇ锛屾槸鑰亄}".format(codes_index.get(code)) - # 13:00鍚庢定鍋滐紝鏈澘鍧椾腑娑ㄥ仠绁ㄦ暟<29涓嶈兘涔� + # 13:30鍚庢定鍋滐紝鏈澘鍧椾腑娑ㄥ仠绁ㄦ暟<29涓嶈兘涔� limit_up_time = limit_up_time_manager.get_limit_up_time(code) if limit_up_time is not None: - if int(limit_up_time.replace(":", "")) >= 130000 and global_util.industry_hot_num.get(industry) is not None: - if global_util.industry_hot_num.get(industry) < 29: - return False, "13:00鍚庢定鍋滐紝鏈澘鍧椾腑娑ㄥ仠绁ㄦ暟<29涓嶈兘涔�" + if int(limit_up_time.replace(":", "")) >= 133000 and global_util.industry_hot_num.get(industry) is not None: + if global_util.industry_hot_num.get(industry) < 16: + return False, "13:30鍚庢定鍋滐紝鏈澘鍧椾腑娑ㄥ仠绁ㄦ暟<16涓嶈兘涔�" if codes_index.get(code) is not None and codes_index.get(code) == 1: # 濡傛灉鑰佸ぇ宸茬粡涔版垚鍔熶簡锛岃�佷簩灏变笉闇�瑕佷拱浜� @@ -392,11 +380,8 @@ cls.debug(code, "鎵ц鎾ゅ崟寮傚父锛歿}", str(e)) @classmethod - def cancel_buy(cls, code): - # 鍒犻櫎澶х兢鎾や簨浠剁殑澶у崟 - l2_data_manager.L2BetchCancelBigNumProcessor.del_recod(code) + def cancel_buy(cls, code, msg=None): l2_data_manager.L2ContinueLimitUpCountManager.del_data(code) - if code in cls.unreal_buy_dict: cls.unreal_buy_dict.pop(code) # 鍙栨秷涔板叆鏍囪瘑 @@ -404,22 +389,22 @@ l2_data_manager.TradePointManager.delete_buy_cancel_point(code) l2_data_manager.TradePointManager.delete_compute_info_for_cancel_buy(code) l2_data_manager.TradePointManager.delete_count_info_for_cancel_buy(code) - # 鍒犻櫎澶х兢鎾や簨浠剁殑澶у崟 - l2_data_manager.L2BetchCancelBigNumProcessor.del_recod(code) else: cls.__cancel_buy(code) l2_data_manager.L2BigNumProcessor.del_big_num_pos(code) + cls.debug(code, "鎵ц鎾ゅ崟鎴愬姛锛屽師鍥狅細{}", msg) @classmethod def __start_compute_buy(cls, code, compute_start_index, compute_end_index, threshold_money, capture_time, new_add=True): if compute_end_index < compute_start_index: return - + _start_time = t.time() total_datas = local_today_datas[code] # 鑾峰彇涔板叆淇″彿璁$畻璧峰浣嶇疆 buy_single_index, buy_exec_index, buy_compute_index, num, count = cls.__get_order_begin_pos(code) + # 鏄惁涓烘柊鑾峰彇鍒扮殑浣嶇疆 if buy_single_index is None: # 鏈変拱鍏ヤ俊鍙� @@ -436,10 +421,16 @@ if buy_single_index is None: # 鏈幏鍙栧埌涔板叆淇″彿锛岀粓姝㈢▼搴� return None + + _start_time = t.time() + # 璁$畻m鍊煎ぇ鍗� cls.l2BigNumForMProcessor.process(code, max(buy_single_index, compute_start_index), compute_end_index, gpcode_manager.get_limit_up_price(code)) + _start_time = t.time() + threshold_money, msg = cls.__get_threshmoney(code) + _start_time = t.time() # 涔板叆绾拱棰濈粺璁� compute_index, buy_nums, buy_count, rebegin_buy_pos = cls.__sum_buy_num_for_order_3(code, max(buy_single_index, compute_start_index), @@ -447,8 +438,10 @@ count, threshold_money, buy_single_index, capture_time) + cls.debug(code, "m鍊�-{} m鍊煎洜瀛�-{}", threshold_money, msg) + _start_time = t.time() # 涔板叆淇″彿浣嶄笌璁$畻浣嶇疆闂撮殧2s鍙婁互涓婁簡 if rebegin_buy_pos is not None: # 闇�瑕侀噸鏂拌绠楃函涔伴 @@ -485,6 +478,8 @@ # 鏈揪鍒颁笅鍗曟潯浠讹紝淇濆瓨绾拱棰濓紝璁剧疆绾拱棰� # 璁板綍涔板叆淇″彿浣嶇疆 cls.__save_order_begin_data(code, buy_single_index, -1, compute_end_index, buy_nums, buy_count) + print("淇濆瓨澶у崟鏃堕棿", round((t.time() - _start_time) * 1000)) + _start_time = t.time() pass # 鑾峰彇涓嬪崟璧峰淇″彿 @@ -551,6 +546,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): + _start_time = t.time() total_datas = local_today_datas[code] buy_nums = origin_num buy_count = origin_count @@ -563,6 +559,7 @@ threshold_count = l2_trade_factor.L2TradeFactorUtil.get_safe_buy_count(code) buy_single_time_seconds = L2DataUtil.get_time_as_second(total_datas[buy_single_index]["val"]["time"]) + for i in range(compute_start_index, compute_end_index + 1): data = total_datas[i] _val = total_datas[i]["val"] @@ -617,14 +614,16 @@ cls.buy_debug(code, "灏氭湭鑾峰彇鍒颁拱鍏ユ墽琛岀偣锛岃捣濮嬭绠椾綅缃細{} 缁熻绾拱鎵嬫暟锛歿} 鐩爣绾拱鎵嬫暟锛歿} 缁熻绾拱鍗曟暟锛歿} 鐩爣绾拱鍗曟暟锛歿}", compute_start_index, buy_nums, threshold_num, buy_count, threshold_count) + return None, buy_nums, buy_count, None @classmethod def test(cls): - code = "002898" + code = "002556" l2_trade_test.clear_trade_data(code) load_l2_data(code, True) + _start = t.time() if True: state = trade_manager.get_trade_state(code) cls.random_key[code] = random.randint(0, 100000) @@ -632,15 +631,15 @@ try: if state == trade_manager.TRADE_STATE_BUY_DELEGATED or state == trade_manager.TRADE_STATE_BUY_PLACE_ORDER: # 宸叉寕鍗� - cls.__process_order(code, 0, 140, capture_timestamp) + cls.__process_order(code, 1552, 1641, capture_timestamp) else: # 鏈寕鍗� - cls.__process_not_order(code, 0, 140, capture_timestamp) + cls.__process_not_order(code, 1552, 1641, capture_timestamp) except Exception as e: logging.exception(e) + print("澶勭悊鏃堕棿", round((t.time() - _start) * 1000)) return - _start = t.time() # 鎸塻鎵归噺鍖栨暟鎹� total_datas = local_today_datas[code] start_time = total_datas[0]["val"]["time"] @@ -671,6 +670,20 @@ print("鏃堕棿鑺辫垂:", round((t.time() - _start) * 1000)) + @classmethod + def test1(cls): + code = "002556" + l2_trade_test.clear_trade_data(code) + l2_data_manager.local_latest_datas[code] = [] + load_l2_data(code, True) + _start = t.time() + capture_timestamp = 1999999999 + cls.process(code, l2_data_manager.local_today_datas[code][1552:1641], capture_timestamp) + print("鏃堕棿鑺辫垂:", round((t.time() - _start) * 1000)) + pass + if __name__ == "__main__": L2TradeDataProcessor.test() + print("----------------------") + L2TradeDataProcessor.test() -- Gitblit v1.8.0