动态步长-fix

This commit is contained in:
zhangkun9038@dingtalk.com 2025-11-27 16:32:10 +08:00
parent a0fb7e949c
commit 4ae9e506d5
2 changed files with 15 additions and 10 deletions

View File

@ -180,7 +180,7 @@ class GridManager:
# 建仓或加仓 → 将该网格标记为 FILLED
if grid_state:
grid_state.status = "filled"
grid_state.quantity += quantity
grid_state.quantity += quantity # ✅ 关键:增加该网格的持仓数量
grid_state.entry_price = price # 记录实际买入价
grid_state.entry_time = self.candle_index
@ -423,11 +423,12 @@ class GridManager:
if price < avg_grid_price:
# 下沿:应该是 FILLED
if self.total_quantity > 0:
grid_state.status = "filled"
grid_state.entry_price = self.avg_entry_price
grid_state.entry_time = candle_index
# 简化:把所有 filled 网格的持仓信息污盖到了均价
# 实际应用中会根据 trade.trades 进行细上漂歪
# 仅当不是 FILLED 或 quantity 为 0 时,才一次性设置
# 不然锻会每次慢成 FILLED造成或眅效率低
if grid_state.status != "filled" or grid_state.quantity == 0:
grid_state.status = "filled"
grid_state.entry_price = self.avg_entry_price
grid_state.entry_time = candle_index
else:
grid_state.status = "empty"
grid_state.quantity = 0
@ -436,10 +437,11 @@ class GridManager:
grid_state.status = "empty"
grid_state.quantity = 0
else:
# 不太可能抹挡,但为了严谨标记为 FILLED
grid_state.status = "filled"
grid_state.entry_price = self.avg_entry_price
grid_state.entry_time = candle_index
# 不太可能,但为了严谨标记为 FILLED
if self.total_quantity > 0:
grid_state.status = "filled"
grid_state.entry_price = self.avg_entry_price
grid_state.entry_time = candle_index
print(f"[GridManager] {self.pair} 从 Trade 对象同步 - "
f"持仓: {self.total_quantity:.6f}, "

View File

@ -298,6 +298,9 @@ class StaticGrid(IStrategy):
file=sys.stderr, flush=True)
if adjustment and adjustment.type == AdjustmentType.ADD:
# 订单可窲事执行,先更新网格状态(谨慎起见)
grid_manager.apply_adjustment(adjustment)
# 计算加仓金额
stake_amount = adjustment.quantity * self.STAKE
print(f"[StaticGrid] {pair} 加仓决策 - 数量: {adjustment.quantity}, 金额: {stake_amount} USDT",