59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package okx
|
|
|
|
import (
|
|
"fmt"
|
|
. "gitea.zjmud.xyz/phyer/tanya/okx"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestGetCandles(t *testing.T) {
|
|
service := NewOkxPublicDataService()
|
|
|
|
params := CandlesRequest{
|
|
InstID: "BTC-USDT",
|
|
Bar: "1H",
|
|
Limit: "10",
|
|
}
|
|
candles, err := service.GetCandles(params)
|
|
if err != nil {
|
|
t.Fatalf("Expected no error, got %v", err)
|
|
}
|
|
|
|
if len(candles) == 0 {
|
|
t.Fatal("Expected at least one candle, got none")
|
|
}
|
|
|
|
// 检查返回数据的结构
|
|
for _, candle := range candles {
|
|
if candle.Timestamp == "" {
|
|
t.Error("Expected non-empty Timestamp")
|
|
}
|
|
if candle.Open == "" || candle.High == "" || candle.Low == "" || candle.Close == "" {
|
|
t.Error("Expected non-empty OHLC values")
|
|
}
|
|
if candle.Volume == "" || candle.VolumeCcy == "" {
|
|
t.Error("Expected non-empty Volume and VolumeCcy")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGetCandles_InvalidInstID(t *testing.T) {
|
|
service := NewOkxPublicDataService()
|
|
|
|
layout := "2006-01-02 15:04:05"
|
|
startTime, _ := time.Parse(layout, "2023-01-01 00:00:00")
|
|
endTime, _ := time.Parse(layout, "2023-12-31 23:59:59")
|
|
candles, _ := service.GetCandles(CandlesRequest{
|
|
InstID: "BTC-USDT",
|
|
Bar: "1D",
|
|
Before: strconv.FormatInt(startTime.UnixMilli(), 10),
|
|
After: strconv.FormatInt(endTime.UnixMilli(), 10),
|
|
Limit: "50",
|
|
})
|
|
|
|
fmt.Println("Candles:", candles)
|
|
|
|
}
|