refactor: 移除腾讯历史K线降级逻辑,添加废弃标记和注释说明

This commit is contained in:
OpenClaw Agent 2026-03-17 04:30:53 +00:00
parent aa4f63455b
commit 1830b93207
2 changed files with 16 additions and 23 deletions

View File

@ -6,7 +6,11 @@ using Microsoft.Extensions.Logging;
namespace AssetManager.Infrastructure.Services; namespace AssetManager.Infrastructure.Services;
/// <summary> /// <summary>
/// 市场数据服务实现组合模式Yahoo财经优先腾讯财经降级Tiingo最终降级OKX处理加密货币 /// 市场数据服务实现(组合模式)
/// <para>数据源优先级:</para>
/// <para>- 实时价格Yahoo → 腾讯 → Tiingo</para>
/// <para>- 历史K线Yahoo → Tiingo腾讯历史接口已废弃</para>
/// <para>- 加密货币OKX</para>
/// </summary> /// </summary>
public class MarketDataService : IMarketDataService public class MarketDataService : IMarketDataService
{ {
@ -135,7 +139,8 @@ public class MarketDataService : IMarketDataService
} }
else else
{ {
// 股票优先Yahoo财经失败降级腾讯财经最后降级 Tiingo // 股票优先Yahoo财经失败降级 Tiingo
// 注腾讯财经历史K线接口已废弃不再作为降级数据源
try try
{ {
response = await _yahooService.GetStockHistoricalDataAsync(symbol, timeframe, limit); response = await _yahooService.GetStockHistoricalDataAsync(symbol, timeframe, limit);
@ -145,32 +150,16 @@ public class MarketDataService : IMarketDataService
} }
else else
{ {
throw new Exception("Yahoo财经返回空数据"); throw new InvalidOperationException("Yahoo财经返回空数据");
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogWarning(ex, "Yahoo财经历史数据获取失败降级使用 腾讯: {Symbol}", symbol); _logger.LogWarning(ex, "Yahoo财经历史数据获取失败降级使用 Tiingo: {Symbol}", symbol);
try
{
response = await _tencentService.GetStockHistoricalDataAsync(symbol, timeframe, limit);
if (response.Count > 0)
{
source = "Tencent";
}
else
{
throw new Exception("腾讯财经返回空数据");
}
}
catch (Exception tencentEx)
{
_logger.LogWarning(tencentEx, "腾讯财经历史数据获取失败,降级使用 Tiingo: {Symbol}", symbol);
response = await _tiingoService.GetStockHistoricalDataAsync(symbol, timeframe, limit); response = await _tiingoService.GetStockHistoricalDataAsync(symbol, timeframe, limit);
source = "Tiingo"; source = "Tiingo";
} }
} }
}
// 批量写入缓存 // 批量写入缓存
await SaveKlineCacheAsync(symbol, assetType, timeframe, response, source); await SaveKlineCacheAsync(symbol, assetType, timeframe, response, source);

View File

@ -18,12 +18,16 @@ public interface ITencentMarketService
/// <summary> /// <summary>
/// 获取股票历史K线数据 /// 获取股票历史K线数据
/// <para>⚠️ 注意腾讯历史K线接口 (web.ifzq.gtimg.cn) 已废弃,此方法会抛出异常</para>
/// </summary> /// </summary>
[Obsolete("腾讯历史K线接口已废弃请使用 Yahoo 或 Tiingo")]
Task<List<MarketDataResponse>> GetStockHistoricalDataAsync(string symbol, string timeframe, int limit); Task<List<MarketDataResponse>> GetStockHistoricalDataAsync(string symbol, string timeframe, int limit);
} }
/// <summary> /// <summary>
/// 腾讯财经市场数据服务实现(免费无限制,支持盘前盘后) /// 腾讯财经市场数据服务实现
/// <para>实时价格接口 (qt.gtimg.cn) 正常可用</para>
/// <para>历史K线接口 (web.ifzq.gtimg.cn) 已废弃</para>
/// </summary> /// </summary>
public class TencentMarketService : ITencentMarketService public class TencentMarketService : ITencentMarketService
{ {