优化前改动

This commit is contained in:
ddrwode
2026-02-05 17:45:59 +08:00
parent 3ba87c1648
commit 9f9ec214f8

View File

@@ -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]}")