tanya/test/okxAli/get_ticker_test.go

46 lines
1.1 KiB
Go
Raw Normal View History

2025-03-06 00:31:55 +08:00
package okx
import (
"fmt"
. "gitea.zjmud.xyz/phyer/tanya/okx"
"testing"
)
func TestGetTicker(t *testing.T) {
service := NewOkxPublicDataService()
params := TickerRequest{InstID: "BTC-USDT"}
ticker, err := service.GetTicker(params)
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
// 检查返回数据的结构
if ticker.InstID != "BTC-USDT" {
t.Errorf("Expected InstID 'BTC-USDT', got %s", ticker.InstID)
}
if ticker.Last == "" {
t.Error("Expected non-empty Last price")
}
if ticker.AskPx == "" || ticker.BidPx == "" {
t.Error("Expected non-empty AskPx and BidPx")
}
if ticker.Open24h == "" || ticker.High24h == "" || ticker.Low24h == "" {
t.Error("Expected non-empty 24h OHLC values")
}
if ticker.Vol24h == "" || ticker.VolCcy24h == "" {
t.Error("Expected non-empty 24h volume values")
}
}
func TestGetTicker_InvalidInstID(t *testing.T) {
service := NewOkxPublicDataService()
params := TickerRequest{InstID: "BTC-USDT"}
ticker, _ := service.GetTicker(params)
// if err == nil {
// t.Fatal("Expected an error for invalid instId, got nil")
// }
fmt.Println("ticker: ", ticker)
}