Compare commits

..

No commits in common. "89c6ca539781ad46c459179ea9a22b115b6e86f0" and "3fb2403e85d8e694ec8db60ee1ee5957baf94f46" have entirely different histories.

2 changed files with 5 additions and 14 deletions

View File

@ -104,14 +104,13 @@ public class MarketDataService : IMarketDataService
/// </summary>
private async Task<MarketPriceResponse> FetchPriceFromSourceAsync(string symbol, string assetType)
{
_logger.LogInformation("[数据源获取开始] Symbol={Symbol}, AssetType={AssetType}", symbol, assetType);
_logger.LogInformation("从数据源获取价格: {Symbol}, 资产类型: {AssetType}", symbol, assetType);
MarketPriceResponse response;
string source;
if (assetType.Equals("Crypto", StringComparison.OrdinalIgnoreCase))
{
_logger.LogInformation("[数据源] 使用 OKX 获取 {Symbol}", symbol);
response = await _okxService.GetCryptoPriceAsync(symbol);
source = "OKX";
}
@ -120,28 +119,22 @@ public class MarketDataService : IMarketDataService
// 股票优先Yahoo财经失败降级腾讯财经最后降级 Tiingo
try
{
_logger.LogInformation("[数据源] 尝试 Yahoo 获取 {Symbol}", symbol);
response = await _yahooService.GetStockPriceAsync(symbol);
source = "Yahoo";
_logger.LogInformation("[数据源] Yahoo 成功: {Symbol} = {Price}", symbol, response.Price);
}
catch (Exception ex)
{
_logger.LogWarning("[数据源] Yahoo 失败: {Symbol}, 错误: {Error}", symbol, ex.Message);
_logger.LogWarning(ex, "Yahoo财经获取失败降级使用 腾讯: {Symbol}", symbol);
try
{
_logger.LogInformation("[数据源] 降级使用腾讯获取 {Symbol}", symbol);
response = await _tencentService.GetStockPriceAsync(symbol);
source = "Tencent";
_logger.LogInformation("[数据源] 腾讯成功: {Symbol} = {Price}", symbol, response.Price);
}
catch (Exception tencentEx)
{
_logger.LogWarning("[数据源] 腾讯失败: {Symbol}, 错误: {Error}", symbol, tencentEx.Message);
_logger.LogInformation("[数据源] 最后降级使用 Tiingo 获取 {Symbol}", symbol);
_logger.LogWarning(tencentEx, "腾讯财经获取失败,降级使用 Tiingo: {Symbol}", symbol);
response = await _tiingoService.GetStockPriceAsync(symbol);
source = "Tiingo";
_logger.LogInformation("[数据源] Tiingo 成功: {Symbol} = {Price}", symbol, response.Price);
}
}
}

View File

@ -197,14 +197,12 @@ public class PortfolioService : IPortfolioService
try
{
var pos = allPositions.First(p => p.StockCode == code);
var assetType = pos.AssetType ?? "Stock";
_logger.LogDebug("批量获取价格: {Code}, AssetType={AssetType}", code, assetType);
var price = await _marketDataService.GetPriceAsync(code, assetType);
var price = await _marketDataService.GetPriceAsync(code, pos.AssetType ?? "Stock");
return (code, price);
}
catch (Exception ex)
{
_logger.LogError(ex, "批量获取价格失败: {Code}, 错误详情: {Message}", code, ex.Message);
_logger.LogWarning(ex, "批量获取价格失败: {Code}", code);
return (code, null);
}
}).ToList();