diff --git a/user_data/strategies/grid_manager.py b/user_data/strategies/grid_manager.py index 487bacaf..4b02f77e 100644 --- a/user_data/strategies/grid_manager.py +++ b/user_data/strategies/grid_manager.py @@ -1364,53 +1364,7 @@ class GridManager: file=sys.stderr, flush=True) return [] - def calculate_pnl(self) -> Dict[str, float]: - """ - 通过对比 currentGridList 和 historyGridList 计算盈亏 - - Returns: - 包含以下字段的字典: - - total_entry_cost: 总建仓成本 - - total_filled_revenue: 总兑现收益 - - realized_pnl: 已实现盈亏 - - unrealized_pnl: 未实现盈亏 - - total_pnl: 总盈亏 - """ - try: - history = self.get_history_grid_list() - current = self.get_current_grid_list() - - # 计算已兑现的盈亏 - realized_pnl = sum(grid.profit or 0.0 for grid in history) - - # 计算未实现的盈亏(当前持仓) - unrealized_pnl = 0.0 - if self.current_price and self.avg_entry_price > 0: - unrealized_pnl = (self.current_price - self.avg_entry_price) * self.total_quantity - - # 总成本和收益 - total_entry_cost = sum( - (grid.entry_price or 0) * grid.quantity - for grid in history if grid.direction == 'buy' - ) - total_filled_revenue = sum( - (grid.filled_price or 0) * grid.quantity - for grid in history if grid.direction == 'sell' - ) - - return { - 'total_entry_cost': total_entry_cost, - 'total_filled_revenue': total_filled_revenue, - 'realized_pnl': realized_pnl, - 'unrealized_pnl': unrealized_pnl, - 'total_pnl': realized_pnl + unrealized_pnl, - } - except Exception as e: - print(f"[GridManager] {self.pair} 计算盈亏失败: {str(e)}", - file=sys.stderr, flush=True) - return {} - - # ===== Pointer Index 操作接口 ===== + # ===== Pointer Index 操作接口 ====== def move_pointer_left(self) -> bool: """