From 5f0c0e9636384514d39fcadaf884faa35e967d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=99=BE=E7=90=83?= Date: Fri, 6 Mar 2026 08:50:07 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8A=A0=E5=AF=86=E8=B4=A7=E5=B8=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=95=99=E7=A9=BA=EF=BC=8C=E5=BE=85=E6=8E=A5?= =?UTF-8?q?=E5=85=A5=20OKX=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/MarketDataService.cs | 73 +------------------ 1 file changed, 4 insertions(+), 69 deletions(-) diff --git a/AssetManager.Infrastructure/Services/MarketDataService.cs b/AssetManager.Infrastructure/Services/MarketDataService.cs index 341dbb1..1081850 100644 --- a/AssetManager.Infrastructure/Services/MarketDataService.cs +++ b/AssetManager.Infrastructure/Services/MarketDataService.cs @@ -73,34 +73,8 @@ public class MarketDataService : IMarketDataService /// 加密货币价格信息 public async Task GetCryptoPriceAsync(string symbol) { - try - { - _logger.LogInformation($"Requesting crypto price for symbol: {symbol}"); - - // Tiingo 加密货币最新价格端点 - var url = $"https://api.tiingo.com/tiingo/crypto/prices?tickers={symbol}&token={_tiingoApiKey}"; - var response = await _httpClient.GetFromJsonAsync>(url); - - if (response == null || response.Count == 0 || response[0].priceData == null || response[0].priceData.Count == 0) - { - throw new Exception($"No data found for {symbol}"); - } - - var latest = response[0].priceData[0]; - return new MarketPriceResponse - { - Symbol = symbol, - Price = latest.close ?? 0, - PreviousClose = 0, // Tiingo crypto 端点没有 prevClose,暂时用 0 - Timestamp = latest.date ?? DateTime.UtcNow, - AssetType = "Crypto" - }; - } - catch (Exception ex) - { - _logger.LogError(ex, $"Error getting crypto price for {symbol}"); - throw; - } + // 待接入 OKX API + throw new NotImplementedException("加密货币数据源待接入 OKX API"); } /// @@ -164,47 +138,8 @@ public class MarketDataService : IMarketDataService /// 历史数据列表 public async Task> GetCryptoHistoricalDataAsync(string symbol, string timeframe, int limit) { - try - { - _logger.LogInformation($"Requesting crypto historical data for symbol: {symbol}, timeframe: {timeframe}, limit: {limit}"); - - var endDate = DateTime.UtcNow; - var startDate = CalculateStartDate(endDate, timeframe, limit); - - // Tiingo 加密货币历史数据端点(不带 resampleFreq) - var url = $"https://api.tiingo.com/tiingo/crypto/prices?tickers={symbol}&startDate={startDate:yyyy-MM-dd}&endDate={endDate:yyyy-MM-dd}&token={_tiingoApiKey}"; - var response = await _httpClient.GetFromJsonAsync>(url); - - if (response == null || response.Count == 0 || response[0].priceData == null) - { - return new List(); - } - - // 取最近 limit 条 - var result = response[0].priceData! - .OrderByDescending(x => x.date) - .Take(limit) - .OrderBy(x => x.date) - .Select(x => new MarketDataResponse - { - Symbol = symbol, - Open = x.open ?? 0, - High = x.high ?? 0, - Low = x.low ?? 0, - Close = x.close ?? 0, - Volume = x.volume ?? 0, - Timestamp = x.date ?? DateTime.UtcNow, - AssetType = "Crypto" - }) - .ToList(); - - return result; - } - catch (Exception ex) - { - _logger.LogError(ex, $"Error getting crypto historical data for {symbol}"); - throw; - } + // 待接入 OKX API + throw new NotImplementedException("加密货币数据源待接入 OKX API"); } ///