From 9f9ec214f884d6d8b56025cec46d345a488a2087 Mon Sep 17 00:00:00 2001 From: ddrwode <34234@3来 34> Date: Thu, 5 Feb 2026 17:45:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=89=8D=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bitmart/四分之一,五分钟,反手条件充足.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bitmart/四分之一,五分钟,反手条件充足.py b/bitmart/四分之一,五分钟,反手条件充足.py index 09938a0..57aff8a 100644 --- a/bitmart/四分之一,五分钟,反手条件充足.py +++ b/bitmart/四分之一,五分钟,反手条件充足.py @@ -29,6 +29,7 @@ class BitmartFuturesTransaction: self.pbar = tqdm(total=30, desc="等待K线", ncols=80) self.last_kline_time = None # 上一次处理的K线时间戳,用于判断是否是新K线 + self.reverse_executed_this_kline = False # 当前K线是否已执行过反手,防止同一根K线多次反手 self.leverage = "100" # 高杠杆(全仓模式下可开更大仓位) self.open_type = "cross" # 全仓模式 @@ -487,6 +488,13 @@ class BitmartFuturesTransaction: time.sleep(5) continue + # 检查是否进入新的K线,如果是则重置反手标记 + current_kline_time = current_kline['id'] + if self.last_kline_time != current_kline_time: + self.last_kline_time = current_kline_time + self.reverse_executed_this_kline = False + logger.info(f"进入新K线: {current_kline_time}") + # 2. 获取当前价格 current_price = self.get_current_price() if not current_price: @@ -505,11 +513,20 @@ class BitmartFuturesTransaction: # 4. 检查信号 signal = self.check_signal(current_price, prev_kline, current_kline) - # 5. 有信号则执行交易 + # 5. 如果是反手信号且当前K线已执行过反手,则跳过 + if signal and signal[0].startswith('reverse_') and self.reverse_executed_this_kline: + logger.info(f"当前K线已执行过反手,跳过信号: {signal[0]}") + signal = None + + # 6. 有信号则执行交易 if signal: trade_success = self.execute_trade(signal, size=1) if trade_success: logger.success(f"交易执行完成: {signal[0]}, 当前持仓状态: {self.start}") + # 如果是反手操作成功,标记当前K线已执行反手 + if signal[0].startswith('reverse_'): + self.reverse_executed_this_kline = True + logger.info("已标记当前K线反手完成,同一K线内不再反手") page_start = True else: logger.warning(f"交易执行失败或被阻止: {signal[0]}")