Refactor TradingBotBase to manage current balance more effectively. Introduced _currentBalance field to track balance updates during trading operations. Updated wallet balance logic to utilize _currentBalance for consistency. Added new entries to performance benchmark CSV files for recent test runs.
This commit is contained in:
@@ -40,6 +40,7 @@ public class TradingBotBase : ITradingBot
|
||||
public Dictionary<string, LightSignal> Signals { get; set; }
|
||||
public Dictionary<Guid, Position> Positions { get; set; }
|
||||
public Dictionary<DateTime, decimal> WalletBalances { get; set; }
|
||||
private decimal _currentBalance;
|
||||
public DateTime PreloadSince { get; set; }
|
||||
public int PreloadedCandlesCount { get; set; }
|
||||
public long ExecutionCount { get; set; } = 0;
|
||||
@@ -61,6 +62,7 @@ public class TradingBotBase : ITradingBot
|
||||
Signals = new Dictionary<string, LightSignal>();
|
||||
Positions = new Dictionary<Guid, Position>();
|
||||
WalletBalances = new Dictionary<DateTime, decimal>();
|
||||
_currentBalance = config.BotTradingBalance;
|
||||
PreloadSince = CandleHelpers.GetBotPreloadSinceFromTimeframe(config.Timeframe);
|
||||
}
|
||||
|
||||
@@ -457,18 +459,17 @@ public class TradingBotBase : ITradingBot
|
||||
|
||||
private void UpdateWalletBalances()
|
||||
{
|
||||
var date = DateTime.UtcNow;
|
||||
var date = Config.IsForBacktest ? LastCandle?.Date ?? DateTime.UtcNow : DateTime.UtcNow;
|
||||
|
||||
if (WalletBalances.Count == 0)
|
||||
{
|
||||
WalletBalances[date] = Config.BotTradingBalance;
|
||||
WalletBalances[date] = _currentBalance;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!WalletBalances.ContainsKey(date))
|
||||
{
|
||||
var previousBalance = WalletBalances.First().Value;
|
||||
WalletBalances[date] = previousBalance + TradingBox.GetTotalNetPnL(Positions);
|
||||
WalletBalances[date] = _currentBalance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2009,6 +2010,8 @@ public class TradingBotBase : ITradingBot
|
||||
|
||||
if (position.ProfitAndLoss != null)
|
||||
{
|
||||
// Update the current balance when position closes
|
||||
_currentBalance += position.ProfitAndLoss.Net;
|
||||
Config.BotTradingBalance += position.ProfitAndLoss.Net;
|
||||
|
||||
await LogDebug(
|
||||
|
||||
@@ -22,3 +22,5 @@ DateTime,TestName,CandlesCount,ExecutionTimeSeconds,ProcessingRateCandlesPerSec,
|
||||
2025-11-15T06:50:04Z,Telemetry_ETH_RSI_EMACROSS,5760,4.84,1190.4,29.01,19.10,35.17,0.0,0,0.0,0.0,0.0,0.0,-35450.45,20,-49.76,0.00,e814eb74,dev,development
|
||||
2025-11-15T07:11:55Z,Telemetry_ETH_RSI_EMACROSS,5760,5.44,1059.4,28.81,18.07,33.80,0.0,0,0.0,0.0,0.0,0.0,-35450.45,20,-49.76,0.00,bed25e72,dev,development
|
||||
2025-11-15T07:22:05Z,Telemetry_ETH_RSI_EMACROSS,5760,10.71,537.9,28.81,18.06,33.84,0.0,0,0.0,0.0,0.0,0.0,-35450.45,20,-49.76,0.00,49a693b4,dev,development
|
||||
2025-11-17T16:35:10Z,Telemetry_ETH_RSI_EMACROSS,5760,5.88,979.2,28.79,17.97,33.77,0.0,0,0.0,0.0,0.0,0.0,-35450.45,20,-49.76,0.00,091f617e,dev,development
|
||||
2025-11-17T16:49:22Z,Telemetry_ETH_RSI_EMACROSS,5760,4.61,1249.2,28.80,17.29,33.78,0.0,0,0.0,0.0,0.0,0.0,-35450.45,20,-49.76,0.00,091f617e,dev,development
|
||||
|
||||
|
@@ -67,3 +67,5 @@ DateTime,TestName,CandlesCount,ExecutionTimeSeconds,ProcessingRateCandlesPerSec,
|
||||
2025-11-15T06:50:04Z,Telemetry_ETH_RSI,5760,4.47,1286.2,28.81,20.58,34.89,3324.75,0,0.0,965.71,0.00,0.17,-30689.97,24,-51.70,0.00,e814eb74,dev,development
|
||||
2025-11-15T07:11:55Z,Telemetry_ETH_RSI,5760,3.365,1707.1,29.06,20.43,36.29,2872.29,0,0.0,371.33,0.00,0.06,-30689.97,24,-51.70,0.00,bed25e72,dev,development
|
||||
2025-11-15T07:22:05Z,Telemetry_ETH_RSI,5760,7.49,766.2,28.80,20.86,34.90,5992.19,0,0.0,916.71,0.00,0.16,-30689.97,24,-51.70,0.00,49a693b4,dev,development
|
||||
2025-11-17T16:35:10Z,Telemetry_ETH_RSI,5760,4.18,1373.1,29.03,20.63,36.17,3521.98,0,0.0,486.12,0.00,0.08,-30689.97,24,-51.70,0.00,091f617e,dev,development
|
||||
2025-11-17T16:49:22Z,Telemetry_ETH_RSI,5760,2.885,1990.6,29.02,20.35,35.08,2530.49,0,0.0,226.92,0.00,0.04,-30689.97,24,-51.70,0.00,091f617e,dev,development
|
||||
|
||||
|
Reference in New Issue
Block a user