fix backtest below 10usdc + update trade
This commit is contained in:
@@ -420,6 +420,12 @@ public class TradingBotBase : ITradingBot
|
||||
if (!internalPosition.Status.Equals(PositionStatus.New))
|
||||
{
|
||||
internalPosition.Status = PositionStatus.Filled;
|
||||
|
||||
// Update Open trade status when position becomes Filled
|
||||
if (internalPosition.Open != null)
|
||||
{
|
||||
internalPosition.Open.SetStatus(TradeStatus.Filled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -431,7 +437,8 @@ public class TradingBotBase : ITradingBot
|
||||
|
||||
if (orders.Any())
|
||||
{
|
||||
if (orders.Count() >= 3)
|
||||
var ordersCount = orders.Count();
|
||||
if (ordersCount >= 3)
|
||||
{
|
||||
var currentTime = Config.IsForBacktest ? LastCandle?.Date ?? DateTime.UtcNow : DateTime.UtcNow;
|
||||
var timeSinceRequest = currentTime - positionForSignal.Open.Date;
|
||||
@@ -467,7 +474,7 @@ public class TradingBotBase : ITradingBot
|
||||
$"⏳ **Waiting for Orders**\nPosition has `{orders.Count()}` open orders\nElapsed: `{timeSinceRequest.TotalMinutes:F1}min`\nWaiting `{remainingMinutes:F1}min` more before canceling");
|
||||
}
|
||||
}
|
||||
else if (orders.Count() == 2 && Positions[internalPosition.Identifier].Status == PositionStatus.New)
|
||||
else if (ordersCount == 2)
|
||||
{
|
||||
// Check if position is already open on broker with 2 orders
|
||||
await LogInformation(
|
||||
@@ -488,7 +495,6 @@ public class TradingBotBase : ITradingBot
|
||||
UpdatePositionPnl(positionForSignal.Identifier, brokerPosition.ProfitAndLoss.Realized);
|
||||
await SetPositionStatus(signal.Identifier, PositionStatus.Filled);
|
||||
|
||||
|
||||
// Notify platform summary about the executed trade
|
||||
await NotifyAgentAndPlatformGrainAsync(AgentSummaryEventType.PositionOpened,
|
||||
$"Position found on broker with 2 orders: {internalPosition.Identifier}", internalPosition);
|
||||
@@ -1118,6 +1124,7 @@ public class TradingBotBase : ITradingBot
|
||||
{
|
||||
closingPrice = position.StopLoss.Price;
|
||||
position.StopLoss.SetDate(currentCandle.Date);
|
||||
position.StopLoss.SetStatus(TradeStatus.Filled);
|
||||
|
||||
Logger.LogInformation(
|
||||
$"🛑 **Stop Loss Execution Confirmed**\n" +
|
||||
@@ -1129,6 +1136,7 @@ public class TradingBotBase : ITradingBot
|
||||
{
|
||||
closingPrice = position.TakeProfit1.Price;
|
||||
position.TakeProfit1.SetDate(currentCandle.Date);
|
||||
position.TakeProfit1.SetStatus(TradeStatus.Filled);
|
||||
|
||||
Logger.LogInformation(
|
||||
$"🎯 **Take Profit Execution Confirmed**\n" +
|
||||
@@ -1154,10 +1162,12 @@ public class TradingBotBase : ITradingBot
|
||||
if (isManualCloseProfitable)
|
||||
{
|
||||
position.TakeProfit1.SetDate(currentCandle.Date);
|
||||
position.TakeProfit1.SetStatus(TradeStatus.Filled);
|
||||
}
|
||||
else
|
||||
{
|
||||
position.StopLoss.SetDate(currentCandle.Date);
|
||||
position.StopLoss.SetStatus(TradeStatus.Filled);
|
||||
}
|
||||
|
||||
Logger.LogInformation(
|
||||
@@ -1193,6 +1203,15 @@ public class TradingBotBase : ITradingBot
|
||||
|
||||
await SetPositionStatus(position.SignalIdentifier, PositionStatus.Finished);
|
||||
|
||||
// Update position in database with all trade changes
|
||||
if (!Config.IsForBacktest)
|
||||
{
|
||||
await ServiceScopeHelpers.WithScopedService<ITradingService>(_scopeFactory, async tradingService =>
|
||||
{
|
||||
await tradingService.UpdatePositionAsync(position);
|
||||
});
|
||||
}
|
||||
|
||||
// Update the last position closing time for cooldown period tracking
|
||||
LastPositionClosingTime = Config.IsForBacktest ? currentCandle.Date : DateTime.UtcNow;
|
||||
|
||||
@@ -1299,6 +1318,12 @@ public class TradingBotBase : ITradingBot
|
||||
Positions.Values.First(p => p.SignalIdentifier == signalIdentifier).Status = positionStatus;
|
||||
await LogInformation(
|
||||
$"📊 **Position Status Change**\nPosition: `{signalIdentifier}`\nStatus: `{position.Status}` → `{positionStatus}`");
|
||||
|
||||
// Update Open trade status when position becomes Filled
|
||||
if (positionStatus == PositionStatus.Filled && position.Open != null)
|
||||
{
|
||||
position.Open.SetStatus(TradeStatus.Filled);
|
||||
}
|
||||
}
|
||||
|
||||
SetSignalStatus(signalIdentifier,
|
||||
|
||||
Reference in New Issue
Block a user