Compare commits
2 Commits
3fb2403e85
...
89c6ca5397
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89c6ca5397 | ||
|
|
8022731b34 |
@ -104,13 +104,14 @@ public class MarketDataService : IMarketDataService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task<MarketPriceResponse> FetchPriceFromSourceAsync(string symbol, string assetType)
|
private async Task<MarketPriceResponse> FetchPriceFromSourceAsync(string symbol, string assetType)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("从数据源获取价格: {Symbol}, 资产类型: {AssetType}", symbol, assetType);
|
_logger.LogInformation("[数据源获取开始] Symbol={Symbol}, AssetType={AssetType}", symbol, assetType);
|
||||||
|
|
||||||
MarketPriceResponse response;
|
MarketPriceResponse response;
|
||||||
string source;
|
string source;
|
||||||
|
|
||||||
if (assetType.Equals("Crypto", StringComparison.OrdinalIgnoreCase))
|
if (assetType.Equals("Crypto", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("[数据源] 使用 OKX 获取 {Symbol}", symbol);
|
||||||
response = await _okxService.GetCryptoPriceAsync(symbol);
|
response = await _okxService.GetCryptoPriceAsync(symbol);
|
||||||
source = "OKX";
|
source = "OKX";
|
||||||
}
|
}
|
||||||
@ -119,22 +120,28 @@ public class MarketDataService : IMarketDataService
|
|||||||
// 股票:优先Yahoo财经,失败降级腾讯财经,最后降级 Tiingo
|
// 股票:优先Yahoo财经,失败降级腾讯财经,最后降级 Tiingo
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("[数据源] 尝试 Yahoo 获取 {Symbol}", symbol);
|
||||||
response = await _yahooService.GetStockPriceAsync(symbol);
|
response = await _yahooService.GetStockPriceAsync(symbol);
|
||||||
source = "Yahoo";
|
source = "Yahoo";
|
||||||
|
_logger.LogInformation("[数据源] Yahoo 成功: {Symbol} = {Price}", symbol, response.Price);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogWarning(ex, "Yahoo财经获取失败,降级使用 腾讯: {Symbol}", symbol);
|
_logger.LogWarning("[数据源] Yahoo 失败: {Symbol}, 错误: {Error}", symbol, ex.Message);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("[数据源] 降级使用腾讯获取 {Symbol}", symbol);
|
||||||
response = await _tencentService.GetStockPriceAsync(symbol);
|
response = await _tencentService.GetStockPriceAsync(symbol);
|
||||||
source = "Tencent";
|
source = "Tencent";
|
||||||
|
_logger.LogInformation("[数据源] 腾讯成功: {Symbol} = {Price}", symbol, response.Price);
|
||||||
}
|
}
|
||||||
catch (Exception tencentEx)
|
catch (Exception tencentEx)
|
||||||
{
|
{
|
||||||
_logger.LogWarning(tencentEx, "腾讯财经获取失败,降级使用 Tiingo: {Symbol}", symbol);
|
_logger.LogWarning("[数据源] 腾讯失败: {Symbol}, 错误: {Error}", symbol, tencentEx.Message);
|
||||||
|
_logger.LogInformation("[数据源] 最后降级使用 Tiingo 获取 {Symbol}", symbol);
|
||||||
response = await _tiingoService.GetStockPriceAsync(symbol);
|
response = await _tiingoService.GetStockPriceAsync(symbol);
|
||||||
source = "Tiingo";
|
source = "Tiingo";
|
||||||
|
_logger.LogInformation("[数据源] Tiingo 成功: {Symbol} = {Price}", symbol, response.Price);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -197,12 +197,14 @@ public class PortfolioService : IPortfolioService
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var pos = allPositions.First(p => p.StockCode == code);
|
var pos = allPositions.First(p => p.StockCode == code);
|
||||||
var price = await _marketDataService.GetPriceAsync(code, pos.AssetType ?? "Stock");
|
var assetType = pos.AssetType ?? "Stock";
|
||||||
|
_logger.LogDebug("批量获取价格: {Code}, AssetType={AssetType}", code, assetType);
|
||||||
|
var price = await _marketDataService.GetPriceAsync(code, assetType);
|
||||||
return (code, price);
|
return (code, price);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogWarning(ex, "批量获取价格失败: {Code}", code);
|
_logger.LogError(ex, "批量获取价格失败: {Code}, 错误详情: {Message}", code, ex.Message);
|
||||||
return (code, null);
|
return (code, null);
|
||||||
}
|
}
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user