Reduce logs for backtests

This commit is contained in:
2025-10-10 01:59:27 +07:00
parent a3d6dd1238
commit 21314430ef
3 changed files with 46 additions and 30 deletions

View File

@@ -42,7 +42,7 @@ namespace Managing.Infrastructure.Exchanges
decimal? stopLossPrice = null,
decimal? takeProfitPrice = null)
{
_logger.LogInformation(
_logger.LogDebug(
$"OpenMarketTrade - {ticker} - Type: {tradeType} - {direction} - Price: {price} - Quantity: {quantity} - Leverage: {leverage} - SL: {stopLossPrice} - TP: {takeProfitPrice}");
if (isForPaperTrading)
@@ -59,7 +59,7 @@ namespace Managing.Infrastructure.Exchanges
{
_logger.LogWarning(
$"Gas fee too high for position opening: {gasFeeUsd:F2} USD (threshold: 0.5 USD). Cancelling position opening.");
// Return a cancelled trade
return BuildEmptyTrade(ticker, price, quantity, direction, leverage, tradeType, currentDate.Value,
TradeStatus.Cancelled);
@@ -282,8 +282,9 @@ namespace Managing.Infrastructure.Exchanges
}
catch (InvalidOperationException ex) when (ex.Message.Contains("no candle data available"))
{
_logger.LogWarning($"Primary price source failed for {ticker} at {date:yyyy-MM-dd HH:mm:ss}. Attempting fallback to current price.");
_logger.LogWarning(
$"Primary price source failed for {ticker} at {date:yyyy-MM-dd HH:mm:ss}. Attempting fallback to current price.");
// Fallback: Try to get current price instead of historical price
try
{
@@ -292,8 +293,11 @@ namespace Managing.Infrastructure.Exchanges
}
catch (Exception fallbackEx)
{
_logger.LogError(fallbackEx, $"Fallback price retrieval also failed for {ticker} at {date:yyyy-MM-dd HH:mm:ss}");
throw new InvalidOperationException($"Unable to retrieve price for {ticker}. Both primary and fallback methods failed. Please check if the ticker is valid and data sources are accessible.", ex);
_logger.LogError(fallbackEx,
$"Fallback price retrieval also failed for {ticker} at {date:yyyy-MM-dd HH:mm:ss}");
throw new InvalidOperationException(
$"Unable to retrieve price for {ticker}. Both primary and fallback methods failed. Please check if the ticker is valid and data sources are accessible.",
ex);
}
}
}