From d9a8ea84c7bc6b1f67c9054ad0a6e08228b369b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=99=BE=E7=90=83?= Date: Fri, 6 Mar 2026 08:33:55 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=20Tiingo=20API=20Key?= =?UTF-8?q?=20&=20=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A8=20/tiingo/daily=20?= =?UTF-8?q?=E7=AB=AF=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/MarketDataService.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/AssetManager.Infrastructure/Services/MarketDataService.cs b/AssetManager.Infrastructure/Services/MarketDataService.cs index d46ae06..497e4b3 100644 --- a/AssetManager.Infrastructure/Services/MarketDataService.cs +++ b/AssetManager.Infrastructure/Services/MarketDataService.cs @@ -23,7 +23,7 @@ public class MarketDataService : IMarketDataService _logger = logger; _httpClient = httpClientFactory.CreateClient(); // TODO: 从配置读取 Tiingo API Key - _tiingoApiKey = Environment.GetEnvironmentVariable("TIINGO_API_KEY") ?? "YOUR_TIINGO_API_KEY"; + _tiingoApiKey = Environment.GetEnvironmentVariable("TIINGO_API_KEY") ?? "bd00fee76d3012b047473078904001b33322cb46"; _httpClient.DefaultRequestHeaders.Add("Authorization", $"Token {_tiingoApiKey}"); } @@ -38,21 +38,23 @@ public class MarketDataService : IMarketDataService { _logger.LogInformation($"Requesting stock price for symbol: {symbol}"); - // Tiingo 最新价格端点 - var url = $"https://api.tiingo.com/iex/{symbol}?token={_tiingoApiKey}"; - var response = await _httpClient.GetFromJsonAsync>(url); + // Tiingo 日线最新价格端点(取最近1条) + var url = $"https://api.tiingo.com/tiingo/daily/{symbol}/prices?token={_tiingoApiKey}"; + var response = await _httpClient.GetFromJsonAsync>(url); if (response == null || response.Count == 0) { throw new Exception($"No data found for {symbol}"); } - var latest = response[0]; + var latest = response[^1]; + decimal? prevClose = response.Count >= 2 ? response[^2].close : null; + return new MarketPriceResponse { Symbol = symbol, - Price = latest.tngoLast ?? latest.close ?? 0, - PreviousClose = latest.prevClose ?? 0, + Price = latest.close ?? 0, + PreviousClose = prevClose ?? 0, Timestamp = latest.date ?? DateTime.UtcNow, AssetType = "Stock" };