From a5eaa98f55e665de19564022993503d9427d74c8 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期二, 07 十一月 2023 17:06:50 +0800 Subject: [PATCH] 非快速下单增加板上买模式 --- l2/l2_data_manager_new.py | 92 +++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 82 insertions(+), 10 deletions(-) diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py index 9a21ba1..6abd491 100644 --- a/l2/l2_data_manager_new.py +++ b/l2/l2_data_manager_new.py @@ -9,6 +9,7 @@ from db.redis_manager_delegate import RedisUtils from l2.huaxin import l2_huaxin_util, huaxin_delegate_postion_manager from l2.l2_sell_manager import L2MarketSellManager +from l2.transaction_progress import TradeBuyQueue from log_module import async_log_util, log_export from third_data import kpl_data_manager, block_info from utils import global_util, ths_industry_util, tool @@ -203,6 +204,8 @@ class L2TradeDataProcessor: unreal_buy_dict = {} volume_rate_info = {} + # 鏈�杩戠殑闂數涓嬪崟浣嶇疆,鏍煎紡涓簕code:(鎬诲崠鏃堕棿,鎬诲崠棰�)} + __latest_fast_place_order_info_dict = {} __codeActualPriceProcessor = CodeActualPriceProcessor() __ths_l2_trade_queue_manager = trade_queue_manager.thsl2tradequeuemanager() __thsBuy1VolumnManager = trade_queue_manager.THSBuy1VolumnManager() @@ -1008,10 +1011,27 @@ cls.unreal_buy_dict[code] = (buy_exec_index, capture_time) trade_result_manager.virtual_buy_success(code) + # 鏄惁鏄湪鏉夸笂涔� + @classmethod + def __is_at_limit_up_buy(cls, code_): + # 鎬诲崠涓�0锛屽綋鍓嶆垚浜や环涓烘定鍋滀环灏卞垽鏂负鏉夸笂涔� + current_sell_data = cls.__L2MarketSellManager.get_current_total_sell_data(code_) + if current_sell_data and tool.trade_time_sub(tool.get_now_time_str(), current_sell_data[0]) < 5: + # 5s鍐呯殑鏁版嵁鎵嶆湁鏁� + if current_sell_data[1] <= 0: + # 鎬诲崠涓�0 + trade_price = current_price_process_manager.get_trade_price(code_) + limit_up_price = gpcode_manager.get_limit_up_price(code_) + if trade_price and limit_up_price and abs(float(trade_price) - float(limit_up_price)) <= 0.001: + # 褰撳墠鎴愪氦浠蜂负娑ㄥ仠浠� + return True + return False + @classmethod def __start_compute_buy(cls, code, compute_start_index, compute_end_index, threshold_money, capture_time, is_first_code, new_add=True): + if compute_end_index < compute_start_index: return @@ -1057,6 +1077,37 @@ _index = None buy_single_index = _index if has_single: + # 鍒ゆ柇鏄惁鏄澘涓婁拱 + order_begin_pos.at_limit_up = cls.__is_at_limit_up_buy(code) + # -------------璁$畻淇″彿浣嶅埌鎴愪氦浣嶇殑绾拱棰濓紙杩囪繙鍒欎负鏃犳晥浣嶇疆锛�------------------- + if order_begin_pos.at_limit_up: + # 鑾峰彇鎴愪氦杩涘害浣嶇疆 + trade_index, is_default = TradeBuyQueue().get_traded_index(code) + if trade_index and not is_default: + m_base_val = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code) + thresh_hold_num = m_base_val // (float(gpcode_manager.get_limit_up_price(code)) * 100) + # 鐪熷疄涓嬪崟浣嶅埌鎴愪氦浣嶇疆鐨勭函涔伴 + total_num = 0 + for i in range(trade_index + 1, order_begin_pos.buy_single_index): + data = total_datas[i] + val = data["val"] + if not L2DataUtil.is_limit_up_price_buy(val): + continue + left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2( + code, + data["index"], + total_datas, + local_today_canceled_buyno_map.get( + code)) + total_num += left_count * val["num"] + if total_num > thresh_hold_num: + break + if total_num > thresh_hold_num: + # 璺濈鎴愪氦杩涘害浣嶇疆杩囪繙 + l2_log.debug(code, + f"鑾峰彇鐨勪俊鍙蜂綅鏃犳晥锛堟澘涓婁拱锛岃寖鍥达細{trade_index + 1}-{order_begin_pos.buy_single_index} 鏈垚浜ゆ�绘墜{total_num}/闃堝�納thresh_hold_num}锛�") + return None + cls.__last_buy_single_dict[code] = buy_single_index new_get_single = True order_begin_pos.num = 0 @@ -1066,11 +1117,12 @@ # 鏆傛椂鎵�8鎶� order_begin_pos.threshold_money = int(sell_info[1] * 0.8) # 娣辫瘉鎬诲崠澶т簬1000涓囩殑绁紝m鍊兼墦5鎶� - if code.find('00')==0 and sell_info[1] > 1000*10000: + if code.find('00') == 0 and sell_info[1] > 1000 * 10000: order_begin_pos.threshold_money = int(sell_info[1] * 0.5) - l2_log.debug(code, "鑾峰彇鍒颁拱鍏ヤ俊鍙疯捣濮嬬偣锛歿} ,璁$畻鑼冨洿锛歿}-{} 锛岄噺姣旓細{}锛屾暟鎹細{} 妯″紡锛歿}锛坽}锛�", buy_single_index, + l2_log.debug(code, "鑾峰彇鍒颁拱鍏ヤ俊鍙疯捣濮嬬偣锛歿} ,璁$畻鑼冨洿锛歿}-{} 锛岄噺姣旓細{}锛屾槸鍚︽澘涓婁拱锛歿}锛屾暟鎹細{} 妯″紡锛歿}锛坽}锛�", buy_single_index, compute_start_index, - compute_end_index, cls.volume_rate_info[code], total_datas[buy_single_index], + compute_end_index, cls.volume_rate_info[code], order_begin_pos.at_limit_up, + total_datas[buy_single_index], order_begin_pos.mode, fast_msg) # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "涓嬪崟淇″彿璁$畻鏃堕棿") @@ -1114,7 +1166,8 @@ order_begin_pos.count, threshold_money, order_begin_pos.buy_single_index, - order_begin_pos.max_num_set) + order_begin_pos.max_num_set, + order_begin_pos.at_limit_up) l2_log.debug(code, "m鍊�-{} 閲忔瘮:{} rebegin_buy_pos:{}", threshold_money, cls.volume_rate_info[code][0], rebegin_buy_pos) @@ -1126,10 +1179,10 @@ return if new_buy_exec_index is not None: - l2_log.debug(code, "鑾峰彇鍒颁拱鍏ユ墽琛屼綅缃細{} m鍊硷細{} 绾拱鎵嬫暟锛歿} 绾拱鍗曟暟锛歿} 鏁版嵁锛歿} ,閲忔瘮:{} ,涓嬪崟妯″紡锛歿}", new_buy_exec_index, + l2_log.debug(code, "鑾峰彇鍒颁拱鍏ユ墽琛屼綅缃細{} m鍊硷細{} 绾拱鎵嬫暟锛歿} 绾拱鍗曟暟锛歿} 鏄惁鏉夸笂涔帮細{} 鏁版嵁锛歿} ,閲忔瘮:{} ,涓嬪崟妯″紡锛歿}", new_buy_exec_index, threshold_money, buy_nums, - buy_count, total_datas[new_buy_exec_index], cls.volume_rate_info[code], order_begin_pos.mode) + buy_count, order_begin_pos.at_limit_up, total_datas[new_buy_exec_index], cls.volume_rate_info[code], order_begin_pos.mode) cls.__save_order_begin_data(code, OrderBeginPosInfo(buy_single_index=buy_single_index, buy_exec_index=new_buy_exec_index, buy_compute_index=new_buy_exec_index, @@ -1143,6 +1196,10 @@ l2_log.debug(code, "delete_buy_cancel_point") # 鐩存帴涓嬪崟 ordered = cls.__buy(code, capture_time, total_datas[-1], total_datas[-1]["index"], is_first_code) + + # 淇濆瓨闂數涓嬪崟鐨勪拱鍏ヤ俊鎭� + if order_begin_pos.mode == OrderBeginPosInfo.MODE_FAST: + cls.__latest_fast_place_order_info_dict[code] = (order_begin_pos.sell_info[0], order_begin_pos.sell_info[1]) # 鏁版嵁鏄惁澶勭悊瀹屾瘯 if new_buy_exec_index < compute_end_index: @@ -1312,7 +1369,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, max_num_set): + threshold_money, buy_single_index, max_num_set, at_limit_up=False): _start_time = t.time() total_datas = local_today_datas[code] # is_first_code = gpcode_manager.FirstCodeManager().is_in_first_record_cache(code) @@ -1322,10 +1379,25 @@ limit_up_price = gpcode_manager.get_limit_up_price(code) if limit_up_price is None: raise Exception("娑ㄥ仠浠锋棤娉曡幏鍙�") - # 鐩爣鎵嬫暟 - threshold_num = round(threshold_money / (limit_up_price * 100)) + + threshold_num = None # 澶х洰鏍囨墜鏁帮紙婊¤冻杩欎釜灏变笉闇�瑕佺湅瀹夊叏绗旀暟锛� - threshold_max_num = int(threshold_num * 1.2) + threshold_max_num = None + # ----------------璋冩暣鏉夸笂涓嬪崟鐨刴鍊间笌瀹夊叏绗旀暟---------------- + if at_limit_up: + # 鏉夸笂涔帮紝鑾峰彇鏈�杩戜竴娆¢棯鐢典笅鍗曠殑鎬诲崠棰� + sell_data = cls.__latest_fast_place_order_info_dict.get(code) + if sell_data: + # 鏈夎繃闂數涓嬪崟 + # 鎬诲崠鐨勪竴鍗婁綔涓簃鍊� + threshold_num = int(sell_data[1] / (limit_up_price * 100)) // 2 + threshold_max_num = 0 + + if not threshold_num: + # 鐩爣鎵嬫暟 + threshold_num = round(threshold_money / (limit_up_price * 100)) + if not threshold_max_num: + threshold_max_num = int(threshold_num * 1.2) # place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code) # 鐩爣璁㈠崟鏁伴噺 -- Gitblit v1.8.0