bbgo_origin/pkg/exchange/binance/ticker_test.go

55 lines
1.4 KiB
Go
Raw Permalink Normal View History

2021-02-06 17:35:23 +00:00
package binance
import (
"context"
2021-12-04 17:11:47 +00:00
"os"
2021-02-06 17:35:23 +00:00
"testing"
2021-02-07 21:58:30 +00:00
"github.com/stretchr/testify/assert"
2021-02-06 17:35:23 +00:00
)
2021-12-04 16:58:01 +00:00
func TestExchange_QueryTickers_AllSymbols(t *testing.T) {
2021-12-04 17:11:47 +00:00
key := os.Getenv("BINANCE_API_KEY")
secret := os.Getenv("BINANCE_API_SECRET")
if len(key) == 0 && len(secret) == 0 {
t.Skip("api key/secret are not configured")
return
}
e := New(key, secret)
2021-02-06 17:35:23 +00:00
got, err := e.QueryTickers(context.Background())
2021-12-04 16:58:01 +00:00
if assert.NoError(t, err) {
assert.True(t, len(got) > 1, "binance: attempting to get all symbol tickers, but get 1 or less")
2021-02-06 17:35:23 +00:00
}
}
2021-12-04 16:58:01 +00:00
func TestExchange_QueryTickers_SomeSymbols(t *testing.T) {
2021-12-04 17:11:47 +00:00
key := os.Getenv("BINANCE_API_KEY")
secret := os.Getenv("BINANCE_API_SECRET")
if len(key) == 0 && len(secret) == 0 {
t.Skip("api key/secret are not configured")
return
}
e := New(key, secret)
2021-02-06 17:35:23 +00:00
got, err := e.QueryTickers(context.Background(), "BTCUSDT", "ETHUSDT")
2021-12-04 16:58:01 +00:00
if assert.NoError(t, err) {
assert.Len(t, got, 2, "binance: attempting to get two symbols, but number of tickers do not match")
2021-02-06 17:35:23 +00:00
}
}
2021-12-04 16:58:01 +00:00
func TestExchange_QueryTickers_SingleSymbol(t *testing.T) {
2021-12-04 17:11:47 +00:00
key := os.Getenv("BINANCE_API_KEY")
secret := os.Getenv("BINANCE_API_SECRET")
if len(key) == 0 && len(secret) == 0 {
t.Skip("api key/secret are not configured")
return
}
e := New(key, secret)
2021-02-06 17:35:23 +00:00
got, err := e.QueryTickers(context.Background(), "BTCUSDT")
2021-12-04 16:58:01 +00:00
if assert.NoError(t, err) {
assert.Len(t, got, 1, "binance: attempting to get one symbol, but number of tickers do not match")
2021-02-06 17:35:23 +00:00
}
}