Add netPnl in db for position
This commit is contained in:
@@ -11,6 +11,7 @@ using Managing.Domain.Scenarios;
|
||||
using Managing.Domain.Statistics;
|
||||
using Managing.Domain.Strategies;
|
||||
using Managing.Domain.Strategies.Base;
|
||||
using Managing.Domain.Trades;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -481,6 +482,9 @@ public class DataController : ControllerBase
|
||||
// Fetch positions associated with this bot using the provided trading service
|
||||
var positions = await tradingService.GetPositionsByInitiatorIdentifierAsync(strategy.Identifier);
|
||||
|
||||
// Convert positions to view models
|
||||
var positionViewModels = positions.Select(MapPositionToViewModel).ToList();
|
||||
|
||||
// Convert agent balance history to wallet balances dictionary
|
||||
var walletBalances = agentBalanceHistory?.AgentBalances?
|
||||
.ToDictionary(b => b.Time, b => b.TotalValue) ?? new Dictionary<DateTime, decimal>();
|
||||
@@ -498,7 +502,7 @@ public class DataController : ControllerBase
|
||||
VolumeLast24H = volumeLast24h,
|
||||
Wins = wins,
|
||||
Losses = losses,
|
||||
Positions = positions.ToList(),
|
||||
Positions = positionViewModels,
|
||||
Identifier = strategy.Identifier,
|
||||
WalletBalances = walletBalances,
|
||||
Ticker = strategy.Ticker
|
||||
@@ -783,4 +787,29 @@ public class DataController : ControllerBase
|
||||
PositionCountByDirection = state.PositionCountByDirection ?? new Dictionary<TradeDirection, int>()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps a Position domain object to a PositionViewModel
|
||||
/// </summary>
|
||||
/// <param name="position">The position domain object to map</param>
|
||||
/// <returns>A PositionViewModel with the same properties</returns>
|
||||
private static PositionViewModel MapPositionToViewModel(Position position)
|
||||
{
|
||||
return new PositionViewModel
|
||||
{
|
||||
Date = position.Date,
|
||||
AccountId = position.AccountId,
|
||||
OriginDirection = position.OriginDirection,
|
||||
Ticker = position.Ticker,
|
||||
Open = position.Open,
|
||||
StopLoss = position.StopLoss,
|
||||
TakeProfit1 = position.TakeProfit1,
|
||||
ProfitAndLoss = position.ProfitAndLoss,
|
||||
UiFees = position.UiFees,
|
||||
GasFees = position.GasFees,
|
||||
Status = position.Status,
|
||||
SignalIdentifier = position.SignalIdentifier,
|
||||
Identifier = position.Identifier,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user