46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
![]() |
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)
|
||
|
}
|