package okx import ( . "gitea.zjmud.xyz/phyer/tanya/okx" "testing" ) func TestGetInstruments(t *testing.T) { service := NewOkxPublicDataService() // 使用默认的正式环境 URL params := InstrumentsRequest{InstType: "SPOT"} instruments, err := service.GetInstruments(params) if err != nil { t.Fatalf("Expected no error, got %v", err) } if len(instruments) == 0 { t.Fatal("Expected at least one instrument, got none") } // 检查返回数据的结构 for _, inst := range instruments { if inst.InstType != "SPOT" { t.Errorf("Expected InstType 'SPOT', got %s", inst.InstType) } if inst.InstID == "" { t.Error("Expected non-empty InstID") } if inst.BaseCcy == "" || inst.QuoteCcy == "" { t.Error("Expected non-empty BaseCcy and QuoteCcy") } } } func TestGetInstruments_InvalidInstType(t *testing.T) { service := NewOkxPublicDataService() params := InstrumentsRequest{InstType: "INVALID"} _, err := service.GetInstruments(params) if err == nil { t.Fatal("Expected an error for invalid instType, got nil") } }