fix(hedger): persist accumulated PnL and fees across restarts

This commit is contained in:
2025-12-21 10:47:34 +01:00
parent 857d1b91f0
commit 50aa497037

View File

@ -438,16 +438,14 @@ class ScalperHedger:
self.strategy_start_time = int(time.time() * 1000) self.strategy_start_time = int(time.time() * 1000)
self.trade_history_seen = set() self.trade_history_seen = set()
self.accumulated_pnl = Decimal("0.0")
self.accumulated_fees = Decimal("0.0") # Resume PnL from file if available, otherwise 0.0
self.accumulated_pnl = to_decimal(position_data.get('hedge_pnl_realized', 0.0))
self.accumulated_fees = to_decimal(position_data.get('hedge_fees_paid', 0.0))
self.active_position_id = position_data['token_id'] self.active_position_id = position_data['token_id']
update_position_stats(self.active_position_id, { logger.info(f"[DELTA] Strat Init: Pos {self.active_position_id} | Range: {lower}-{upper} | Entry: {entry_price} | Start Px: {start_price:.2f} | Resumed PnL: {self.accumulated_pnl:.2f}")
"hedge_pnl_realized": 0.0,
"hedge_fees_paid": 0.0
})
logger.info(f"[DELTA] Strat Init: Pos {self.active_position_id} | Range: {lower}-{upper} | Entry: {entry_price} | Start Px: {start_price:.2f}")
except Exception as e: except Exception as e:
logger.error(f"Failed to init strategy: {e}") logger.error(f"Failed to init strategy: {e}")