Fix roi with fees

This commit is contained in:
2025-09-28 21:42:08 +07:00
parent 37da5a80b2
commit 6267dad8fa
3 changed files with 28 additions and 29 deletions

View File

@@ -81,7 +81,8 @@ public class AgentGrain : Grain, IAgentGrain
UpdatedAt = DateTime.UtcNow,
ActiveStrategiesCount = 0,
TotalVolume = 0,
TotalBalance = 0
TotalBalance = 0,
TotalFees = 0
};
await _agentService.SaveOrUpdateAgentSummary(emptySummary);

View File

@@ -722,10 +722,10 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
var fees = _tradingBot.GetTotalFees();
var volume = TradingBox.GetTotalVolumeTraded(_tradingBot.Positions);
// Calculate ROI based on total investment
// Calculate ROI based on total investment (PnL minus fees)
var totalInvestment = _tradingBot.Positions.Values
.Sum(p => p.Open.Quantity * p.Open.Price);
var roi = totalInvestment > 0 ? (pnl / totalInvestment) * 100 : 0;
var roi = totalInvestment > 0 ? ((pnl - fees) / totalInvestment) * 100 : 0;
// Calculate long and short position counts
var longPositionCount = _tradingBot.Positions.Values

View File

@@ -1,12 +1,13 @@
import React, {useEffect, useState} from 'react'
import {PlayIcon, StopIcon} from '@heroicons/react/solid'
import moment from 'moment'
import {
BotClient,
BotStatus,
DataClient,
Position,
TradeDirection,
UserStrategyDetailsViewModel
BotClient,
BotStatus,
DataClient,
Position,
TradeDirection,
UserStrategyDetailsViewModel
} from '../../generated/ManagingApi'
import useApiUrlStore from '../../app/store/apiStore'
import {Toast} from '../../components/mollecules'
@@ -63,16 +64,22 @@ const AgentStrategy: React.FC<AgentStrategyProps> = ({ index }) => {
const formatDuration = (runtime?: Date | null) => {
if (!runtime) return '0h'
const now = new Date()
const start = new Date(runtime)
const diffMs = now.getTime() - start.getTime()
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24))
const diffHours = Math.floor((diffMs % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
if (diffDays > 0) {
return `${diffDays} week${diffDays > 6 ? 's' : ''} ${diffHours}h`
const start = moment(runtime)
const now = moment()
const duration = moment.duration(now.diff(start))
const days = Math.floor(duration.asDays())
const hours = duration.hours()
const minutes = duration.minutes()
if (days > 0) {
return `${days}d ${hours}h ${minutes}m`
} else if (hours > 0) {
return `${hours}h ${minutes}m`
} else {
return `${minutes}m`
}
return `${diffHours}h`
}
const getStatusBadge = (state: string | null | undefined) => {
@@ -176,10 +183,10 @@ const AgentStrategy: React.FC<AgentStrategyProps> = ({ index }) => {
</div>
<div className="flex gap-2">
<button
className={`btn btn-outline ${strategyData.state === 'Up' ? 'btn-error' : 'btn-success'}`}
className={`btn btn-outline ${strategyData.state === BotStatus.Running ? 'btn-error' : 'btn-success'}`}
onClick={() => toggleStrategyStatus(strategyData.state, strategyData.identifier || '')}
>
{strategyData.state === 'Up' ? (
{strategyData.state === BotStatus.Running ? (
<StopIcon width={15} />
) : (
<PlayIcon width={15} />
@@ -267,7 +274,7 @@ const AgentStrategy: React.FC<AgentStrategyProps> = ({ index }) => {
<h3 className="card-title">ROI</h3>
<div className="text-2xl font-bold">{formatPercentage(strategyData.roiPercentage)}</div>
<div className="text-sm text-success">
{formatPercentage(strategyData.roiLast24H)} Today
{formatPercentage(strategyData.roiPercentage)} Today
</div>
</div>
</div>
@@ -282,15 +289,6 @@ const AgentStrategy: React.FC<AgentStrategyProps> = ({ index }) => {
</div>
</div>
<div className="card bg-base-200">
<div className="card-body">
<h3 className="card-title">PnL %</h3>
<div className="text-2xl font-bold text-success">
{formatPercentage(strategyData.roiPercentage)}
</div>
</div>
</div>
<div className="card bg-base-200">
<div className="card-body">
<h3 className="card-title">Total Runtime</h3>