refactor: 移除腾讯历史K线降级逻辑,添加废弃标记和注释说明
This commit is contained in:
parent
aa4f63455b
commit
1830b93207
@ -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);
|
||||||
|
|||||||
@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user