From bc4725ca19c197923d86a4e8c9799a04c1b2052b Mon Sep 17 00:00:00 2001 From: cryptooda Date: Wed, 7 Jan 2026 01:44:05 +0700 Subject: [PATCH] Refactor FuturesBot and SpotBot to utilize ticker enum for candle retrieval - Updated GetCurrentCandleForPositionClose method in both FuturesBot and SpotBot to parse the ticker parameter into an enum, enhancing type safety and clarity. - Adjusted TradingBotBase to use the position's ticker for candle retrieval, ensuring consistency across trading bot implementations. --- src/Managing.Application/Bots/FuturesBot.cs | 4 +++- src/Managing.Application/Bots/SpotBot.cs | 4 +++- src/Managing.Application/Bots/TradingBotBase.cs | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Managing.Application/Bots/FuturesBot.cs b/src/Managing.Application/Bots/FuturesBot.cs index e0c57926..bfa7a8d4 100644 --- a/src/Managing.Application/Bots/FuturesBot.cs +++ b/src/Managing.Application/Bots/FuturesBot.cs @@ -77,8 +77,10 @@ public class FuturesBot : TradingBotBase protected override async Task GetCurrentCandleForPositionClose(Account account, string ticker) { // For live trading, get real-time candle from exchange + // ticker parameter is a string representation of the position's ticker + var tickerEnum = Enum.Parse(ticker); return await ServiceScopeHelpers.WithScopedService(_scopeFactory, - async exchangeService => await exchangeService.GetCandle(Account, Config.Ticker, DateTime.UtcNow)); + async exchangeService => await exchangeService.GetCandle(Account, tickerEnum, DateTime.UtcNow)); } protected override async Task CheckBrokerPositions() diff --git a/src/Managing.Application/Bots/SpotBot.cs b/src/Managing.Application/Bots/SpotBot.cs index bb103fe1..db8ee70d 100644 --- a/src/Managing.Application/Bots/SpotBot.cs +++ b/src/Managing.Application/Bots/SpotBot.cs @@ -143,8 +143,10 @@ public class SpotBot : TradingBotBase protected override async Task GetCurrentCandleForPositionClose(Account account, string ticker) { // For live trading, get real-time candle from exchange + // ticker parameter is a string representation of the position's ticker + var tickerEnum = Enum.Parse(ticker); return await ServiceScopeHelpers.WithScopedService(_scopeFactory, - async exchangeService => await exchangeService.GetCandle(Account, Config.Ticker, DateTime.UtcNow)); + async exchangeService => await exchangeService.GetCandle(Account, tickerEnum, DateTime.UtcNow)); } protected override async Task CheckBrokerPositions() diff --git a/src/Managing.Application/Bots/TradingBotBase.cs b/src/Managing.Application/Bots/TradingBotBase.cs index 68747a17..5c976051 100644 --- a/src/Managing.Application/Bots/TradingBotBase.cs +++ b/src/Managing.Application/Bots/TradingBotBase.cs @@ -477,7 +477,7 @@ public abstract class TradingBotBase : ITradingBot { lastCandle = TradingBox.IsBacktestTrading(Config.TradingType) ? LastCandle - : await exchangeService.GetCandle(Account, Config.Ticker, + : await exchangeService.GetCandle(Account, positionForSignal.Ticker, DateTime.UtcNow); }); @@ -1177,7 +1177,7 @@ public abstract class TradingBotBase : ITradingBot { if (Positions.ContainsKey(position.Identifier)) { - Candle currentCandle = await GetCurrentCandleForPositionClose(Account, Config.Ticker.ToString()); + Candle currentCandle = await GetCurrentCandleForPositionClose(Account, position.Ticker.ToString()); // Try broker history reconciliation first var brokerHistoryReconciled = await ReconcileWithBrokerHistory(position, currentCandle);