Add monitoring on queries with sentry alert + Fix check position list in db for backtest

This commit is contained in:
2025-10-10 00:15:02 +07:00
parent ffb98fe359
commit e4c2f8b7a5
24 changed files with 3340 additions and 179 deletions

View File

@@ -308,26 +308,27 @@ public class TradingBotBase : ITradingBot
// Second, process all finished positions to ensure they are updated in the database
// TODO : This should be removed in the future, when we have a better way to handle positions
foreach (var position in Positions.Values.Where(p => p.IsFinished()))
{
try
if (!Config.IsForBacktest)
foreach (var position in Positions.Values.Where(p => p.IsFinished()))
{
var positionInDatabase = await ServiceScopeHelpers.WithScopedService<ITradingService, Position>(
_scopeFactory,
async tradingService =>
{
return await tradingService.GetPositionByIdentifierAsync(position.Identifier);
});
if (positionInDatabase != null && positionInDatabase.Status != position.Status)
try
{
await UpdatePositionDatabase(position);
await LogInformation(
$"💾 Database Update\nPosition: `{position.Identifier}`\nStatus: `{position.Status}`\nUpdated in database");
var positionInDatabase = await ServiceScopeHelpers.WithScopedService<ITradingService, Position>(
_scopeFactory,
async tradingService =>
{
return await tradingService.GetPositionByIdentifierAsync(position.Identifier);
});
if (positionInDatabase != null && positionInDatabase.Status != position.Status)
{
await UpdatePositionDatabase(position);
await LogInformation(
$"💾 Database Update\nPosition: `{position.Identifier}`\nStatus: `{position.Status}`\nUpdated in database");
}
}
}
catch (Exception ex)
{
catch (Exception ex)
{
await LogWarning($"Failed to update finished position {position.Identifier} in database: {ex.Message}");
}
}