添加价格范围限制,确保不超过decimal(20,8)最大范围

This commit is contained in:
claw_bot 2026-03-12 06:11:55 +00:00
parent f9d24203c6
commit a62d892b4b

View File

@ -342,14 +342,14 @@ public class MarketDataService : IMarketDataService
source = "Tiingo"; source = "Tiingo";
} }
// 写入缓存保留8位小数避免字段超出范围 // 写入缓存保留8位小数强制转换为12位整数+8位小数避免MySql字段溢出
var cacheEntity = new MarketPriceCache var cacheEntity = new MarketPriceCache
{ {
Id = cacheKey, Id = cacheKey,
Symbol = symbol.ToUpper(), Symbol = symbol.ToUpper(),
AssetType = assetType.ToUpper(), AssetType = assetType.ToUpper(),
Price = Math.Round(response.Price, 8), Price = Math.Round(Math.Clamp(response.Price, 0, 999999999999.99999999m), 8),
PreviousClose = response.PreviousClose > 0 ? Math.Round(response.PreviousClose, 8) : null, PreviousClose = response.PreviousClose > 0 ? Math.Round(Math.Clamp(response.PreviousClose.Value, 0, 999999999999.99999999m), 8) : null,
Source = source, Source = source,
FetchedAt = DateTime.Now, FetchedAt = DateTime.Now,
ExpiredAt = GetCacheExpirationTime(assetType) ExpiredAt = GetCacheExpirationTime(assetType)