AssetManager.API/AssetManager.Services/TickerService.cs
OpenClaw Agent 1977dd609d fix: 请求收益曲线时自动回填历史数据
- GetNavHistoryAsync现在会自动检查是否有历史数据
- 无历史数据时自动调用BackfillNavHistoryInternalAsync
- 拆分内部回填方法,避免重复验证权限
2026-03-13 16:21:31 +00:00

52 lines
1.5 KiB
C#
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AssetManager.Data;
using AssetManager.Models.DTOs;
using Microsoft.Extensions.Logging;
using SqlSugar;
namespace AssetManager.Services;
/// <summary>
/// 股票代码服务实现
/// </summary>
public class TickerService : ITickerService
{
private readonly ILogger<TickerService> _logger;
private readonly ISqlSugarClient _db;
public TickerService(ILogger<TickerService> logger, ISqlSugarClient db)
{
_logger = logger;
_db = db;
}
/// <summary>
/// 模糊搜索股票代码
/// </summary>
public async Task<List<TickerSearchResult>> SearchTickerAsync(string keyword, int limit = 20)
{
_logger.LogInformation($"Search ticker with keyword: {keyword}, limit: {limit}");
if (string.IsNullOrWhiteSpace(keyword))
{
return new List<TickerSearchResult>();
}
// 模糊搜索ticker 包含 keyword 或者 exchange 包含 keyword 或者 name 包含 keyword
var results = await _db.Queryable<TiingoTicker>()
.Where(t => t.Ticker.Contains(keyword) || t.Exchange.Contains(keyword) || (t.Name != null && t.Name.Contains(keyword)))
.Take(limit)
.OrderBy(t => t.Ticker)
.Select(t => new TickerSearchResult
{
Ticker = t.Ticker,
Name = t.Name,
Exchange = t.Exchange,
AssetType = t.AssetType,
PriceCurrency = t.PriceCurrency
})
.ToListAsync();
return results;
}
}