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.
This commit is contained in:
@@ -77,8 +77,10 @@ public class FuturesBot : TradingBotBase
|
|||||||
protected override async Task<Candle> GetCurrentCandleForPositionClose(Account account, string ticker)
|
protected override async Task<Candle> GetCurrentCandleForPositionClose(Account account, string ticker)
|
||||||
{
|
{
|
||||||
// For live trading, get real-time candle from exchange
|
// 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>(ticker);
|
||||||
return await ServiceScopeHelpers.WithScopedService<IExchangeService, Candle>(_scopeFactory,
|
return await ServiceScopeHelpers.WithScopedService<IExchangeService, Candle>(_scopeFactory,
|
||||||
async exchangeService => await exchangeService.GetCandle(Account, Config.Ticker, DateTime.UtcNow));
|
async exchangeService => await exchangeService.GetCandle(Account, tickerEnum, DateTime.UtcNow));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<bool> CheckBrokerPositions()
|
protected override async Task<bool> CheckBrokerPositions()
|
||||||
|
|||||||
@@ -143,8 +143,10 @@ public class SpotBot : TradingBotBase
|
|||||||
protected override async Task<Candle> GetCurrentCandleForPositionClose(Account account, string ticker)
|
protected override async Task<Candle> GetCurrentCandleForPositionClose(Account account, string ticker)
|
||||||
{
|
{
|
||||||
// For live trading, get real-time candle from exchange
|
// 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>(ticker);
|
||||||
return await ServiceScopeHelpers.WithScopedService<IExchangeService, Candle>(_scopeFactory,
|
return await ServiceScopeHelpers.WithScopedService<IExchangeService, Candle>(_scopeFactory,
|
||||||
async exchangeService => await exchangeService.GetCandle(Account, Config.Ticker, DateTime.UtcNow));
|
async exchangeService => await exchangeService.GetCandle(Account, tickerEnum, DateTime.UtcNow));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<bool> CheckBrokerPositions()
|
protected override async Task<bool> CheckBrokerPositions()
|
||||||
|
|||||||
@@ -477,7 +477,7 @@ public abstract class TradingBotBase : ITradingBot
|
|||||||
{
|
{
|
||||||
lastCandle = TradingBox.IsBacktestTrading(Config.TradingType)
|
lastCandle = TradingBox.IsBacktestTrading(Config.TradingType)
|
||||||
? LastCandle
|
? LastCandle
|
||||||
: await exchangeService.GetCandle(Account, Config.Ticker,
|
: await exchangeService.GetCandle(Account, positionForSignal.Ticker,
|
||||||
DateTime.UtcNow);
|
DateTime.UtcNow);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1177,7 +1177,7 @@ public abstract class TradingBotBase : ITradingBot
|
|||||||
{
|
{
|
||||||
if (Positions.ContainsKey(position.Identifier))
|
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
|
// Try broker history reconciliation first
|
||||||
var brokerHistoryReconciled = await ReconcileWithBrokerHistory(position, currentCandle);
|
var brokerHistoryReconciled = await ReconcileWithBrokerHistory(position, currentCandle);
|
||||||
|
|||||||
Reference in New Issue
Block a user