using Microsoft.Extensions.Logging; namespace Infrastructure.StockData; /// Stooq(stooq.com) 무인증 CSV 시세 호출 공통 — 인증 헤더 없음 + 간단 3회 재시도 (2s/4s 백오프). internal static class StooqHttp { public const string ClientName = "Stooq"; private const int MaxAttempts = 3; public static async Task GetStringWithRetryAsync(HttpClient client, string url, ILogger logger, CancellationToken ct) { for (var attempt = 1; ; attempt++) { try { using var response = await client.GetAsync(url, ct); response.EnsureSuccessStatusCode(); return await response.Content.ReadAsStringAsync(ct); } catch (Exception ex) when (ex is not OperationCanceledException && attempt < MaxAttempts) { logger.LogWarning(ex, "[Stooq] HTTP 실패 — 재시도 {Attempt}/{Max}", attempt, MaxAttempts); await Task.Delay(TimeSpan.FromSeconds(2 * attempt), ct); } } } }