Fix roi with fees
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React, {useEffect, useState} from 'react'
|
||||
import {PlayIcon, StopIcon} from '@heroicons/react/solid'
|
||||
import moment from 'moment'
|
||||
import {
|
||||
BotClient,
|
||||
BotStatus,
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user