From 3b872137fb8d0e894c868197eff915748c704a0e Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 09 九月 2024 00:49:58 +0800 Subject: [PATCH] 激进买入-买入完善 --- l2/l2_data_manager_new.py | 114 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 84 insertions(+), 30 deletions(-) diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py index e93e0b5..c689068 100644 --- a/l2/l2_data_manager_new.py +++ b/l2/l2_data_manager_new.py @@ -35,7 +35,8 @@ from log_module.log import logger_l2_trade_buy, logger_l2_process, logger_l2_error, logger_debug, \ logger_l2_not_buy_reasons, logger_real_place_order_position, logger_l2_trade_buy_queue -from trade.trade_data_manager import CodeActualPriceProcessor, PlaceOrderCountManager, AccountMoneyManager +from trade.trade_data_manager import CodeActualPriceProcessor, PlaceOrderCountManager, AccountMoneyManager, \ + RadicalBuyDealCodesManager from trade.trade_manager import TradeTargetCodeModeManager @@ -730,16 +731,19 @@ # 涓嶅浜庡彲涓嬪崟鐘舵�� return False __start_time = tool.get_now_timestamp() + order_begin_pos = cls.__get_order_begin_pos( + code) - can, need_clear_data, reason, is_valid_exec_index = cls.__can_buy_first(code) + if order_begin_pos.MODE_RADICAL == order_begin_pos.mode: + # 婵�杩涗笅鍗曚笉鍒ゆ柇鏉′欢 + can, need_clear_data, reason, is_valid_exec_index = True, False, "婵�杩涗笅鍗�", True + else: + can, need_clear_data, reason, is_valid_exec_index = cls.__can_buy_first(code) - # __start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - __start_time, "鏈�鍚庡垽鏂槸鍚﹁兘涓嬪崟", force=True) # 鍒犻櫎铏氭嫙涓嬪崟 if code in cls.unreal_buy_dict: cls.unreal_buy_dict.pop(code) - order_begin_pos = cls.__get_order_begin_pos( - code) if not can: if not is_valid_exec_index: if cls.__latest_exec_indexes.get(code) and cls.__latest_exec_indexes[code][ @@ -852,6 +856,32 @@ return True, "" @classmethod + def __is_on_limit_up_buy(cls, code, buy_exec_index): + total_data = local_today_datas.get(code) + latest_exec_indexes = cls.__latest_exec_indexes[code] + if not latest_exec_indexes: + latest_exec_indexes = [] + # 鍒ゆ柇鏄惁鏄偢寮�鍚庝拱鍏� + last_exec_index = 0 + if len(latest_exec_indexes) > 1: + last_exec_index = latest_exec_indexes[-2] + # 鑾峰彇鏈�杩戠殑闈炴定鍋滀环鎴愪氦鏃堕棿 + not_limit_up_trade_time_with_ms = current_price_process_manager.get_trade_not_limit_up_time_with_ms( + code) + is_limit_up_buy = True + if not_limit_up_trade_time_with_ms: + t1 = int( + L2DataUtil.get_time_with_ms(total_data[last_exec_index]["val"]).replace(":", "").replace(".", + "")) + t2 = int(not_limit_up_trade_time_with_ms.replace(":", "").replace(".", "")) + t3 = int(L2DataUtil.get_time_with_ms(total_data[buy_exec_index]["val"]).replace(":", "").replace( + ".", "")) + if t1 < t2 <= t3: + # 鐐告澘鏃堕棿鍦ㄤ袱娆′笅鍗曟椂闂翠腑闂� + is_limit_up_buy = False + return is_limit_up_buy + + @classmethod def __can_buy_first(cls, code): """ 鏄惁鍙互涓嬪崟 @@ -954,32 +984,12 @@ # 1.褰撳墠鎴愪氦浠蜂负娑ㄥ仠浠� # 2.璺濈鏈�杩戠殑闈炴澘涓婃垚浜ょ殑鏃堕棿澶т簬涓�涓槇鍊� if abs(limit_up_price - float(trade_price)) < 0.001: - latest_exec_indexes = cls.__latest_exec_indexes[code] - if not latest_exec_indexes: - latest_exec_indexes = [] - # 鍒ゆ柇鏄惁鏄偢寮�鍚庝拱鍏� - last_exec_index = 0 - if len(latest_exec_indexes) > 1: - last_exec_index = latest_exec_indexes[-2] - # 鑾峰彇鏈�杩戠殑闈炴定鍋滀环鎴愪氦鏃堕棿 - not_limit_up_trade_time_with_ms = current_price_process_manager.get_trade_not_limit_up_time_with_ms( - code) - - is_limit_up_buy = True - if not_limit_up_trade_time_with_ms: - t1 = int( - L2DataUtil.get_time_with_ms(total_data[last_exec_index]["val"]).replace(":", "").replace(".", - "")) - t2 = int(not_limit_up_trade_time_with_ms.replace(":", "").replace(".", "")) - t3 = int(L2DataUtil.get_time_with_ms(total_data[order_begin_pos.buy_exec_index]["val"]).replace(":", - "").replace( - ".", "")) - if t1 < t2 <= t3: - # 鐐告澘鏃堕棿鍦ㄤ袱娆′笅鍗曟椂闂翠腑闂� - is_limit_up_buy = False + is_limit_up_buy = cls.__is_on_limit_up_buy(code, order_begin_pos.buy_exec_index) if is_limit_up_buy: # 鏉夸笂涔颁笖闈炲姞缁� - + # 鑾峰彇鏈�杩戠殑闈炴定鍋滀环鎴愪氦鏃堕棿 + not_limit_up_trade_time_with_ms = current_price_process_manager.get_trade_not_limit_up_time_with_ms( + code) # 鍒ゆ柇鎴愪氦杩涘害鍒板綋鍓嶆暟鎹殑绗旀暟锛屽鏋滃皯浜�10绗斾笖杩樻湁鏈垚浜ょ殑澶у崟锛�>=299锛夊氨鍙互涓嬪崟 trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code) if trade_index is None: @@ -1726,7 +1736,7 @@ start = None return None - # 璁$畻婵�杩涗拱鐨勪笅鍗曚俊鍙� + # 璁$畻绉瀬涔扮殑涓嬪崟淇″彿 @classmethod def __compute_active_order_begin_pos(cls, code, continue_count, start_index, end_index): """ @@ -1824,6 +1834,50 @@ return False, -1, "鏈幏鍙栧埌婵�杩涗拱鐨勮捣濮嬩俊鍙�", '', OrderBeginPosInfo.MODE_NORMAL + # 璁$畻婵�杩涗拱鐨勪笅鍗曚俊鍙� + @classmethod + def __compute_radical_order_begin_pos(cls, code, start_index, end_index): + """ + 璁$畻婵�杩涗拱鍏ヤ俊鍙凤細 + 1.闈炴澘涓婃斁閲� + 2.妫�娴嬪埌299涓囧ぇ鍗曚拱鍏� + @param code: + @param start_index: + @param end_index: + @return: (鏄惁鑾峰彇鍒颁俊鍙�, 淇″彿浣嶇疆) + """ + # 婵�杩涗拱淇″彿鐨勬椂闂� + + + radical_data = RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict.get(code) + if not radical_data: + return False, None, "涓嶆弧瓒虫縺杩涗拱鐨勬潯浠�" + if t.time() > radical_data[0]: + return False, None, "瓒呰繃鐢熸晥鏃堕棿" + + + # 鍒ゆ柇鏄惁鏄澘涓婃斁閲� + if cls.__is_on_limit_up_buy(code, start_index): + return False, None, "鏉夸笂鏀鹃噺" + total_datas = local_today_datas[code] + min_num = int(29900 / gpcode_manager.get_limit_up_price_as_num(code)) + single_index = None + for i in range(start_index, end_index + 1): + data = total_datas[i] + val = data["val"] + if not L2DataUtil.is_limit_up_price_buy(val): + continue + if val["num"] < min_num: + continue + if int(val["orderNo"]) <= radical_data[1]: + # 涓诲姩涔板崟鍚庣殑鏁版嵁涓嶇畻 + continue + single_index = i + break + if single_index is not None: + return True, single_index, "鏈夊ぇ鍗�" + return False, None, "鏃犲ぇ鍗�" + @classmethod def test__compute_active_order_begin_pos(cls, code, continue_count, start_index, end_index): return cls.__compute_active_order_begin_pos(code, continue_count, start_index, end_index) -- Gitblit v1.8.0