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"); } ///