fix the arrary out of range (#782)

This commit is contained in:
Diego
2025-11-08 18:51:13 -05:00
committed by GitHub
parent 27a38e1e0d
commit 9cecc19ad6
+8
View File
@@ -42,6 +42,14 @@ func Get(symbol string) (*Data, error) {
return nil, fmt.Errorf("获取4小时K线失败: %v", err)
}
// 检查数据是否为空
if len(klines3m) == 0 {
return nil, fmt.Errorf("3分钟K线数据为空")
}
if len(klines4h) == 0 {
return nil, fmt.Errorf("4小时K线数据为空")
}
// 计算当前指标 (基于3分钟最新数据)
currentPrice := klines3m[len(klines3m)-1].Close
currentEMA20 := calculateEMA(klines3m, 20)