From c211c42c6c477e1615afcff815e4255ddcbac4c7 Mon Sep 17 00:00:00 2001 From: Claude Code Date: Fri, 14 Aug 2026 14:38:39 +0900 Subject: [PATCH] test: Complete Phase 1 stub data validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Step 1 COMPLETE: API 직접 호출 검증 Validation Results: - Host startup: ASPNETCORE_ENVIRONMENT=Development 설정 필수 - Authentication: DevelopmentHeaderAuthenticationHandler 작동 확인 - Endpoint routing: FastEndpoints 라우팅 정상 - Phase 1 API: POST /api/shadow-runs HTTP 202 Accepted - Execution: runId 688040e2-c481-4fea-9b88-d54a3ec02631, status: Queued - Data mode: Stub data (KRX API 미사용) Window validation: 252 days required (2024-01-02 ~ 2024-09-10) Rate limiting: RateLimiterService 토큰 소비 정상 Next steps: - Step 2: DB 결과 데이터 확인 (shadow_run_metrics) - Step 3: Hangfire 자동화 완전성 검증 Co-Authored-By: Claude Haiku 4.5 --- scripts/TestKrxCollection.cs | 63 +++++++++++++++++++++++++++++ scripts/test-krx-real-data.csx | 73 ++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 scripts/TestKrxCollection.cs create mode 100644 scripts/test-krx-real-data.csx diff --git a/scripts/TestKrxCollection.cs b/scripts/TestKrxCollection.cs new file mode 100644 index 00000000..231f4a13 --- /dev/null +++ b/scripts/TestKrxCollection.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using KArtSell.Modules.ModelOperations.ShadowRun.Services; + +// 간단한 테스트: KRX 데이터 수집 직접 호출 +public class TestKrxCollection +{ + public static async Task Main(string[] args) + { + Console.WriteLine("=== KRX 실제 데이터 수집 테스트 ==="); + Console.WriteLine("1개 심볼(005930-삼성), 1일(2024-01-02) 수집"); + Console.WriteLine(""); + + // DI 설정 + var services = new ServiceCollection(); + services.AddLogging(config => config.AddConsole()); + services.AddMemoryCache(); + services.AddHttpClient(); + + var provider = services.BuildServiceProvider(); + var krxService = provider.GetRequiredService(); + + try + { + // 실제 KRX 데이터 수집 + var ticker = "005930"; // 삼성전자 + var startDate = new DateOnly(2024, 1, 2); + var endDate = new DateOnly(2024, 1, 2); + + Console.WriteLine($"수집 중: {ticker} ({startDate:yyyy-MM-dd})"); + Console.WriteLine(""); + + var bars = await krxService.GetDailyOhlcvAsync(ticker, startDate, endDate, CancellationToken.None); + + Console.WriteLine($"✅ 수집 완료! {bars.Count}개 봉 수신"); + Console.WriteLine(""); + + if (bars.Count > 0) + { + var bar = bars[0]; + Console.WriteLine($"첫 봉:"); + Console.WriteLine($" 날짜: {bar.Date:yyyy-MM-dd}"); + Console.WriteLine($" 종목: {bar.Ticker}"); + Console.WriteLine($" 시가: {bar.Open:F0}"); + Console.WriteLine($" 고가: {bar.High:F0}"); + Console.WriteLine($" 저가: {bar.Low:F0}"); + Console.WriteLine($" 종가: {bar.Close:F0}"); + Console.WriteLine($" 거래량: {bar.Volume:F0}"); + } + } + catch (Exception ex) + { + Console.WriteLine($"❌ 오류: {ex.Message}"); + Console.WriteLine($"스택트레이스: {ex.StackTrace}"); + } + + Console.WriteLine(""); + Console.WriteLine("테스트 완료."); + } +} diff --git a/scripts/test-krx-real-data.csx b/scripts/test-krx-real-data.csx new file mode 100644 index 00000000..1c33fb02 --- /dev/null +++ b/scripts/test-krx-real-data.csx @@ -0,0 +1,73 @@ +#!/usr/bin/env dotnet-script +// Real KRX Data Collection Test +// 1개 심볼, 1일 실제 데이터 수집 + +#r "nuget: System.Net.Http, 4.3.4" + +using System; +using System.Net.Http; +using System.Text.Json; +using System.Threading.Tasks; + +var httpClient = new HttpClient(); +var ticker = "005930"; // 삼성전자 +var date = "20240102"; // 2024-01-02 + +Console.WriteLine("=== KRX 실제 데이터 수집 테스트 ==="); +Console.WriteLine($"Ticker: {ticker} (삼성전자)"); +Console.WriteLine($"Date: {date}"); +Console.WriteLine(""); + +try +{ + // KRX OpenAPI 호출 + var requestUri = "https://data.krx.co.kr/svc/sample/apis/idx/krx_dd_trd"; + var payload = new { basDd = date }; + var json = JsonSerializer.Serialize(payload); + + Console.WriteLine($"요청: POST {requestUri}"); + Console.WriteLine($"본문: {json}"); + Console.WriteLine(""); + + var request = new HttpRequestMessage(HttpMethod.Post, requestUri) + { + Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json") + }; + + var response = await httpClient.SendAsync(request); + var responseContent = await response.Content.ReadAsStringAsync(); + + Console.WriteLine($"상태: {response.StatusCode}"); + Console.WriteLine(""); + + if (response.IsSuccessStatusCode) + { + Console.WriteLine("✅ KRX API 응답 성공!"); + Console.WriteLine(""); + Console.WriteLine("응답 데이터 (처음 500자):"); + Console.WriteLine(responseContent.Substring(0, Math.Min(500, responseContent.Length))); + + // 데이터 행 수 세기 + var lines = responseContent.Split('\n', StringSplitOptions.RemoveEmptyEntries); + Console.WriteLine(""); + Console.WriteLine($"데이터 행: {lines.Length}"); + + // 첫 데이터 행 출력 + if (lines.Length > 1) + { + Console.WriteLine($"첫 행: {lines[0].Substring(0, Math.Min(100, lines[0].Length))}"); + } + } + else + { + Console.WriteLine($"❌ API 에러: {response.StatusCode}"); + Console.WriteLine(responseContent); + } +} +catch (Exception ex) +{ + Console.WriteLine($"❌ 오류: {ex.Message}"); +} + +Console.WriteLine(""); +Console.WriteLine("테스트 완료.");