feat(ta): dynamic settings, IFinlyticLogger, live log streaming, and EF migration

This commit is contained in:
2026-08-15 21:30:05 +02:00
parent a94c36a878
commit 1522c3480f
9 changed files with 494 additions and 89 deletions
@@ -3,9 +3,11 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using FinlyticCore.Services;
using FinlyticCore.Services.Yahoo;
using FinlyticTechnicalAnalysis.Entities;
using Microsoft.Extensions.Logging;
using FinlyticTechnicalAnalysis.Util;
using Microsoft.Extensions.Configuration;
namespace FinlyticTechnicalAnalysis.Services;
@@ -40,17 +42,17 @@ public interface IYahooMarketDataScraper
public class YahooMarketDataScraper : IYahooMarketDataScraper
{
private readonly YahooFinanceClient _yahooClient;
private readonly Microsoft.Extensions.Configuration.IConfiguration _configuration;
private readonly ILogger<YahooMarketDataScraper> _logger;
private readonly IConfiguration _configuration;
private readonly IFinlyticLogger<YahooMarketDataScraper> _finlyticLogger;
public YahooMarketDataScraper(
YahooFinanceClient yahooClient,
Microsoft.Extensions.Configuration.IConfiguration configuration,
ILogger<YahooMarketDataScraper> logger)
IConfiguration configuration,
IFinlyticLogger<YahooMarketDataScraper> finlyticLogger)
{
_yahooClient = yahooClient;
_configuration = configuration;
_logger = logger;
_finlyticLogger = finlyticLogger;
}
/// <summary>
@@ -66,7 +68,6 @@ public class YahooMarketDataScraper : IYahooMarketDataScraper
return cleanIsin;
}
// Crypto / Trade Republic interne ISINs (beginnend mit 'X', z. B. XF000BTC0017)
if (cleanIsin.StartsWith("X", StringComparison.OrdinalIgnoreCase))
{
var (cryptoSubtitle, cryptoName) = await FinlyticCore.Utils.CryptoSubtitleResolver.ResolveCryptoInfoAsync(
@@ -82,8 +83,7 @@ public class YahooMarketDataScraper : IYahooMarketDataScraper
var res = await FetchHistoricalCandlesWithCurrencyAsync(candidate, "5d", "1d", cancellationToken);
if (res.Candles.Count > 0)
{
_logger.LogInformation("[{Channel}] Resolved Crypto ISIN {Isin} to {Symbol} using Subtitle {Sub}",
"TechnicalAnalysisChannel", cleanIsin, candidate, cryptoSubtitle);
await _finlyticLogger.LogInfoAsync(SettingKeys.TechnicalAnalysisChannel, "[YahooMarketDataScraper] Resolved Crypto ISIN {Isin} to {Symbol} using Subtitle {Sub}", cleanIsin, candidate, cryptoSubtitle);
return candidate;
}
}
@@ -118,7 +118,7 @@ public class YahooMarketDataScraper : IYahooMarketDataScraper
}
catch (Exception ex)
{
_logger.LogWarning(ex, "[{Channel}] Failed to resolve Yahoo ticker for ISIN {Isin}", "TechnicalAnalysisChannel", cleanIsin);
await _finlyticLogger.LogWarningAsync(SettingKeys.TechnicalAnalysisChannel, ex, "[YahooMarketDataScraper] Failed to resolve Yahoo ticker for ISIN {Isin}", cleanIsin);
}
return null;
@@ -150,11 +150,10 @@ public class YahooMarketDataScraper : IYahooMarketDataScraper
if (resultObj == null)
{
_logger.LogWarning("[{Channel}] No chart data returned from Yahoo Client for symbol {Symbol}", "TechnicalAnalysisChannel", symbol);
await _finlyticLogger.LogWarningAsync(SettingKeys.TechnicalAnalysisChannel, "[YahooMarketDataScraper] No chart data returned from Yahoo Client for symbol {Symbol}", symbol);
return new YahooCandlesResult(results, detectedCurrency);
}
// Extract currency metadata
if (!string.IsNullOrWhiteSpace(resultObj.Meta?.Currency))
{
detectedCurrency = resultObj.Meta.Currency.ToUpperInvariant();
@@ -184,7 +183,6 @@ public class YahooMarketDataScraper : IYahooMarketDataScraper
var close = i < closes.Count && closes[i].HasValue ? (decimal)closes[i]!.Value : open;
var vol = i < volumes.Count && volumes[i].HasValue ? (long)volumes[i]!.Value : 0L;
// Skip invalid or empty weekend/holiday records
if (close <= 0m && open <= 0m) continue;
results.Add(new MarketCandleEntity
@@ -200,12 +198,12 @@ public class YahooMarketDataScraper : IYahooMarketDataScraper
});
}
_logger.LogInformation("[{Channel}] Successfully fetched {Count} candles for {Symbol} ({Range}, {Interval}, Currency: {Currency})",
"TechnicalAnalysisChannel", results.Count, symbol, range, interval, detectedCurrency);
await _finlyticLogger.LogInfoAsync(SettingKeys.TechnicalAnalysisChannel, "[YahooMarketDataScraper] Successfully fetched {Count} candles for {Symbol} ({Range}, {Interval}, Currency: {Currency})",
results.Count, symbol, range, interval, detectedCurrency);
}
catch (Exception ex)
{
_logger.LogError(ex, "[{Channel}] Error fetching historical candles for {Symbol}", "TechnicalAnalysisChannel", symbol);
await _finlyticLogger.LogErrorAsync(SettingKeys.TechnicalAnalysisChannel, ex, "[YahooMarketDataScraper] Error fetching historical candles for {Symbol}", symbol);
}
return new YahooCandlesResult(results, detectedCurrency);