From 57b3603302caf04c3405259d2484827e57ee05c6 Mon Sep 17 00:00:00 2001 From: cryptooda Date: Sun, 28 Sep 2025 22:44:03 +0700 Subject: [PATCH] update position count to open position only --- .../Grains/PlatformSummaryGrain.cs | 13 ++- .../src/pages/dashboardPage/agentSearch.tsx | 93 +++++-------------- 2 files changed, 30 insertions(+), 76 deletions(-) diff --git a/src/Managing.Application/Grains/PlatformSummaryGrain.cs b/src/Managing.Application/Grains/PlatformSummaryGrain.cs index a688e63e..01fefc83 100644 --- a/src/Managing.Application/Grains/PlatformSummaryGrain.cs +++ b/src/Managing.Application/Grains/PlatformSummaryGrain.cs @@ -159,13 +159,16 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable _state.State.PositionCountByAsset[ticker]++; - // Position count breakdown by direction - update state directly - if (!_state.State.PositionCountByDirection.ContainsKey(direction)) + // Position count breakdown by direction - only count finished positions + if (!position.IsFinished()) { - _state.State.PositionCountByDirection[direction] = 0; - } + if (!_state.State.PositionCountByDirection.ContainsKey(direction)) + { + _state.State.PositionCountByDirection[direction] = 0; + } - _state.State.PositionCountByDirection[direction]++; + _state.State.PositionCountByDirection[direction]++; + } } _state.State.TotalPlatformVolume = totalVolume; diff --git a/src/Managing.WebApp/src/pages/dashboardPage/agentSearch.tsx b/src/Managing.WebApp/src/pages/dashboardPage/agentSearch.tsx index e2dfbe21..5cd0b0b5 100644 --- a/src/Managing.WebApp/src/pages/dashboardPage/agentSearch.tsx +++ b/src/Managing.WebApp/src/pages/dashboardPage/agentSearch.tsx @@ -16,12 +16,6 @@ interface AgentData { positions: Position[] } -const FILTERS = [ - { label: '1D', value: '1D', days: 1 }, - { label: '1W', value: '1W', days: 7 }, - { label: '1M', value: '1M', days: 30 }, - { label: 'Total', value: 'Total', days: null }, -] function AgentSearch({ index }: { index: number }) { const { apiUrl } = useApiUrlStore() @@ -29,7 +23,6 @@ function AgentSearch({ index }: { index: number }) { const [agentData, setAgentData] = useState(null) const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState(null) - const [selectedFilter, setSelectedFilter] = useState('Total') const searchAgent = async () => { if (!agentName.trim()) return @@ -75,20 +68,6 @@ function AgentSearch({ index }: { index: number }) { } } - // Filter balances based on selected time period - const getFilteredBalances = () => { - if (!agentData?.balances?.agentBalances) return [] - - const filterObj = FILTERS.find(f => f.value === selectedFilter) - if (!filterObj?.days) return agentData.balances.agentBalances // Total - return all - - const now = new Date() - const cutoff = new Date(now.getTime() - filterObj.days * 24 * 60 * 60 * 1000) - - return agentData.balances.agentBalances.filter(balance => - balance.time && new Date(balance.time) >= cutoff - ) - } // Calculate current total balance const getCurrentBalance = () => { @@ -104,25 +83,13 @@ function AgentSearch({ index }: { index: number }) { } } - // Calculate PnL for the selected time period - const calculateFilteredPnL = () => { - const filteredBalances = getFilteredBalances() - if (filteredBalances.length < 2) return 0 - - const startBalance = filteredBalances[0] - const endBalance = filteredBalances[filteredBalances.length - 1] - - const startValue = startBalance.totalValue || 0 - const endValue = endBalance.totalValue || 0 - - return endValue - startValue - } // Calculate summary statistics from strategies const calculateSummary = () => { if (!agentData?.strategies.length) return null const totalPnL = agentData.strategies.reduce((sum, strategy) => sum + (strategy.pnL || 0), 0) + const totalNetPnL = agentData.strategies.reduce((sum, strategy) => sum + (strategy.netPnL || 0), 0) const totalVolume = agentData.strategies.reduce((sum, strategy) => sum + (strategy.totalVolumeTraded || 0), 0) const totalWins = agentData.strategies.reduce((sum, strategy) => sum + (strategy.wins || 0), 0) const totalLosses = agentData.strategies.reduce((sum, strategy) => sum + (strategy.losses || 0), 0) @@ -130,12 +97,9 @@ function AgentSearch({ index }: { index: number }) { ? agentData.strategies.reduce((sum, strategy) => sum + (strategy.winRate || 0), 0) / agentData.strategies.length : 0 - // Calculate filtered PnL based on selected time period - const filteredPnL = calculateFilteredPnL() - return { totalPnL, - filteredPnL, + totalNetPnL, totalVolume, totalWins, totalLosses, @@ -252,18 +216,6 @@ function AgentSearch({ index }: { index: number }) { {summary && ( - {/* Time Filter Buttons */} -
- {FILTERS.map(f => ( - - ))} -
{/* Current Balance Display */} {currentBalance && ( @@ -303,21 +255,6 @@ function AgentSearch({ index }: { index: number }) { - -
-
PnL ({selectedFilter})
-
- = 0 ? 'text-green-500' : 'text-red-500'}> - {summary.filteredPnL >= 0 ? '+' : ''}${summary.filteredPnL.toLocaleString(undefined, { maximumFractionDigits: 2 })} - -
-
- = 0 ? 'text-green-500' : 'text-red-500'}> - {currentBalance ? `${((summary.filteredPnL / currentBalance.totalValue) * 100).toFixed(2)}%` : ''} - -
-
-
@@ -331,8 +268,8 @@ function AgentSearch({ index }: { index: number }) {
ROI
- = 0 ? 'text-green-500' : 'text-red-500'}> - {((summary.totalPnL / (summary.totalVolume || 1)) * 100).toFixed(2)}% + = 0 ? 'text-green-500' : 'text-red-500'}> + {((summary.totalNetPnL / (summary.totalVolume || 1)) * 100).toFixed(2)}%
Return on Investment
@@ -347,7 +284,21 @@ function AgentSearch({ index }: { index: number }) { {summary.totalPnL >= 0 ? '+' : ''}${summary.totalPnL.toLocaleString(undefined, { maximumFractionDigits: 2 })}
-
All time P&L
+
+ Net: = 0 ? 'text-green-500' : 'text-red-500'}> + {summary.totalNetPnL >= 0 ? '+' : ''}${summary.totalNetPnL.toLocaleString(undefined, { maximumFractionDigits: 2 })} + +
+
+
+ + +
+
Total Fees
+
+ ${(summary.totalPnL - summary.totalNetPnL).toLocaleString(undefined, { maximumFractionDigits: 2 })} +
+
Fees paid across all strategies
@@ -361,7 +312,7 @@ function AgentSearch({ index }: { index: number }) { Name Ticker Status - PnL + Net PnL ROI Runtime Avg Winrate @@ -374,8 +325,8 @@ function AgentSearch({ index }: { index: number }) { {strategy.state} - = 0 ? 'text-green-500' : 'text-red-500'}> - {strategy.pnL && strategy.pnL >= 0 ? '+' : ''}${(strategy.pnL || 0).toFixed(2)} + = 0 ? 'text-green-500' : 'text-red-500'}> + {strategy.netPnL && strategy.netPnL >= 0 ? '+' : ''}${(strategy.netPnL || 0).toFixed(2)} = 0 ? 'text-green-500' : 'text-red-500'}> {strategy.roiPercentage && strategy.roiPercentage >= 0 ? '+' : ''}{(strategy.roiPercentage || 0).toFixed(2)}%