feat: 加密货币接口留空,待接入 OKX API
This commit is contained in:
parent
0cee3afe2f
commit
5f0c0e9636
@ -73,34 +73,8 @@ public class MarketDataService : IMarketDataService
|
|||||||
/// <returns>加密货币价格信息</returns>
|
/// <returns>加密货币价格信息</returns>
|
||||||
public async Task<MarketPriceResponse> GetCryptoPriceAsync(string symbol)
|
public async Task<MarketPriceResponse> GetCryptoPriceAsync(string symbol)
|
||||||
{
|
{
|
||||||
try
|
// 待接入 OKX API
|
||||||
{
|
throw new NotImplementedException("加密货币数据源待接入 OKX API");
|
||||||
_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<List<TiingoCryptoPriceResponse>>(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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -164,47 +138,8 @@ public class MarketDataService : IMarketDataService
|
|||||||
/// <returns>历史数据列表</returns>
|
/// <returns>历史数据列表</returns>
|
||||||
public async Task<List<MarketDataResponse>> GetCryptoHistoricalDataAsync(string symbol, string timeframe, int limit)
|
public async Task<List<MarketDataResponse>> GetCryptoHistoricalDataAsync(string symbol, string timeframe, int limit)
|
||||||
{
|
{
|
||||||
try
|
// 待接入 OKX API
|
||||||
{
|
throw new NotImplementedException("加密货币数据源待接入 OKX API");
|
||||||
_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<List<TiingoCryptoPriceResponse>>(url);
|
|
||||||
|
|
||||||
if (response == null || response.Count == 0 || response[0].priceData == null)
|
|
||||||
{
|
|
||||||
return new List<MarketDataResponse>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 取最近 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user