From 2f2516749615da866e96d8d24e499b7ecbb63a3e Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 23 六月 2025 12:28:52 +0800 Subject: [PATCH] 默认交易模式变更/真实下单位置计算位置修改 --- utils/buy_strategy_util.py | 137 ++++++++++++++++++++++++++++----------------- 1 files changed, 84 insertions(+), 53 deletions(-) diff --git a/utils/buy_strategy_util.py b/utils/buy_strategy_util.py index 40c8872..7d0960d 100644 --- a/utils/buy_strategy_util.py +++ b/utils/buy_strategy_util.py @@ -3,10 +3,12 @@ """ import time -from code_attribute import gpcode_manager +from code_attribute import gpcode_manager, code_volumn_manager from l2 import l2_data_util, l2_data_source_util, transaction_progress from l2.l2_data_util import L2DataUtil from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager +from log_module import async_log_util +from log_module.log import logger_l2_error from settings.trade_setting import MarketSituationManager, TradeBlockBuyModeManager from trade import trade_data_manager from utils import tool, buy_condition_util, global_util @@ -43,7 +45,7 @@ break continue # 涓庡綋鍓嶆椂闂寸浉宸�3s鐨勭粨鏉� - if tool.trade_time_sub_with_ms(end_time_with_ms, l2_data_util.L2DataUtil.get_time_with_ms(val)) > 6000: + if tool.trade_time_sub_with_ms(end_time_with_ms, l2_data_util.L2DataUtil.get_time_with_ms(val)) > 10000: break cancel_count += 1 @@ -141,33 +143,52 @@ @param trade_index: @return: """ - total_data = l2_data_util.local_today_datas.get(code) - total_count = 0 - total_big_count = 0 - for i in range(trade_index + 1, total_data[-1]["index"] + 1): - data = total_data[i] - val = data["val"] - if not l2_data_util.L2DataUtil.is_limit_up_price_buy(val): - continue - money = val["num"] * float(val["price"]) - if money < 5000: - continue + # 鑾峰彇浠婃棩鎴愪氦閲忎笌鍙傝�冮噺 + # today = get_today_volumn(code) + # max60, yesterday = get_histry_volumn(code) + try: + today_volume = code_volumn_manager.CodeVolumeManager().get_today_volumn_cache(code) + histry_volumn = code_volumn_manager.CodeVolumeManager().get_histry_volumn(code) + if not today_volume or not histry_volumn: + return False, "灏氭湭鑾峰彇鍒伴噺" + threshhold_volume = (histry_volumn[0][0] - today_volume) // 3 + limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) + threshhold_volumes = threshhold_volume // 100, int(50000 / limit_up_price), int(200000 / limit_up_price) - left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2( - code, - i, - total_data, - l2_data_util.local_today_canceled_buyno_map.get( - code)) - if left_count > 0: - total_count += 1 - if money > 29900: - total_big_count += 1 - if total_count > 10: - break - if total_count > 10 or total_big_count < 1: - return False, f"鏈垚浜ゆ暟閲�-{total_count}锛屽ぇ鍗曟暟閲�-{total_big_count}" - return True, "" + total_data = l2_data_util.local_today_datas.get(code) + total_count = 0 + total_big_count = 0 + total_num = 0 + for i in range(trade_index + 1, total_data[-1]["index"] + 1): + data = total_data[i] + val = data["val"] + if not l2_data_util.L2DataUtil.is_limit_up_price_buy(val): + continue + money = val["num"] * float(val["price"]) + if money < 5000: + continue + + left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2( + code, + i, + total_data, + l2_data_util.local_today_canceled_buyno_map.get( + code)) + if left_count > 0: + total_num += val["num"] + total_count += 1 + if money > 29900: + total_big_count += 1 + if threshhold_volumes[2] < total_num: + break + if threshhold_volumes[1] <= total_num <= threshhold_volumes[2] and total_num < threshhold_volumes[ + 0] and total_big_count > 0: + # 鍓╀綑鐨勫�煎湪500w-2000w涔嬮棿鎵嶄細鍙備笌璁$畻 + return True, "" + return False, f"鏈垚浜ゆ墜鏁�-{total_num}锛岄槇鍊�-{threshhold_volumes[0]}锛屽ぇ鍗曟暟閲�-{total_big_count}" + except Exception as e: + async_log_util.error(logger_l2_error, f"璁$畻鏄惁璺濈鎴愪氦杩涘害浣嶇疆杩戯細{str(e)}") + return False, "璁$畻寮傚父" def is_quantization(code, start_index, end_index): @@ -178,18 +199,33 @@ @param end_index: @return:(鏄惁鏄噺鍖�, 涓嬫鍙互涓嬪崟鏃堕棿) """ - THRESHOLD_BUY_COUNT = 20 - if end_index - start_index + 1 < THRESHOLD_BUY_COUNT: - # 鎬绘暟灏忎簬闃堝�� - return False, None + + # 闃堝�肩殑鍙栧�艰寖鍥� + THRESHOLD_MONEY_RANGE = 1e5, 3e5 + today_volume = code_volumn_manager.CodeVolumeManager().get_today_volumn_cache(code) + histry_volumn = code_volumn_manager.CodeVolumeManager().get_histry_volumn(code) + if not today_volume or not histry_volumn: + return False, "灏氭湭鑾峰彇鍒伴噺" + threshhold_volume = (histry_volumn[0][0] - today_volume) // 6 // 100 + limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) + threshhold_volumes_range = int(THRESHOLD_MONEY_RANGE[0] / limit_up_price), int( + THRESHOLD_MONEY_RANGE[1] / limit_up_price) + if threshhold_volume < threshhold_volumes_range[0]: + threshhold_volume = threshhold_volumes_range[0] + if threshhold_volume > threshhold_volumes_range[1]: + threshhold_volume = threshhold_volumes_range[1] total_datas = l2_data_util.local_today_datas.get(code) + + time_as_ms = tool.trade_time_sub_with_ms( + L2DataUtil.get_time_with_ms(total_datas[end_index]["val"]), + L2DataUtil.get_time_with_ms(total_datas[start_index]["val"])) + if time_as_ms > (10 if tool.is_sz_code(code) else 100): + return False, "闈為噺鍖�" + limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) - buy_count = 0 + total_buy_nums = 0 min_num = int(5000 / limit_up_price) - trade_index, is_default = transaction_progress.TradeBuyQueue().get_traded_index(code) - if trade_index is None: - trade_index = 0 # 鑾峰彇鎴愪氦杩涘害浣� for i in range(start_index, end_index + 1): val = total_datas[i]["val"] @@ -197,25 +233,20 @@ continue if val["num"] < min_num: continue - buy_count += 1 - if buy_count > THRESHOLD_BUY_COUNT: + total_buy_nums += val["num"] + if total_buy_nums > threshhold_volume: break - if buy_count > THRESHOLD_BUY_COUNT: + if total_buy_nums > threshhold_volume: # 鍒ゆ柇鏄惁涓洪噺鍖� - time_as_ms = tool.trade_time_sub_with_ms( - L2DataUtil.get_time_with_ms(total_datas[end_index]["val"]), - L2DataUtil.get_time_with_ms(total_datas[start_index]["val"])) - if time_as_ms <= 10 if tool.is_sz_code(code) else 100: - # 娣辫瘉10ms鍐咃紝涓婅瘉100ms鍐呭氨鍒ゅ畾涓洪噺鍖� - HuaXinSellOrderStatisticManager.clear_latest_deal_volume(code) - next_buy_time = time.time() + buy_condition_util.get_cancel_and_buy_space_time( - code) / 1000 - # 濡傛灉鏄娆′笅鍗曪紝澧炲姞涓�娆′笅鍗曟鏁� - place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code) - if place_order_count == 0: - trade_data_manager.PlaceOrderCountManager().place_order(code) - return True, next_buy_time, f"鎵ц浣嶆壒娆℃暟鎹噺({buy_count})澶т簬{THRESHOLD_BUY_COUNT} {start_index}-{end_index}" - return False, None + # 娣辫瘉10ms鍐咃紝涓婅瘉100ms鍐呭氨鍒ゅ畾涓洪噺鍖� + HuaXinSellOrderStatisticManager.clear_latest_deal_volume(code) + next_buy_time = time.time() + buy_condition_util.get_cancel_and_buy_space_time( + code) / 1000 + # 濡傛灉鏄娆′笅鍗曪紝澧炲姞涓�娆′笅鍗曟鏁� + place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code) + if place_order_count == 0: + trade_data_manager.PlaceOrderCountManager().place_order(code) + return True, next_buy_time, f"鎵ц浣嶆壒娆℃暟鎹噺({total_buy_nums})澶т簬{threshhold_volume} {start_index}-{end_index}" else: return False, None -- Gitblit v1.8.0