mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-14 11:03:53 +00:00
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package bitgetapi
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/c9s/bbgo/pkg/testutil"
|
|
)
|
|
|
|
func getTestClientOrSkip(t *testing.T) *RestClient {
|
|
if b, _ := strconv.ParseBool(os.Getenv("CI")); b {
|
|
t.Skip("skip test for CI")
|
|
}
|
|
|
|
key, secret, ok := testutil.IntegrationTestConfigured(t, "BITGET")
|
|
if !ok {
|
|
t.Skip("BITGET_* env vars are not configured")
|
|
return nil
|
|
}
|
|
|
|
client := NewClient()
|
|
client.Auth(key, secret, os.Getenv("BITGET_API_PASSPHRASE"))
|
|
return client
|
|
}
|
|
|
|
func TestClient(t *testing.T) {
|
|
client := getTestClientOrSkip(t)
|
|
ctx := context.Background()
|
|
|
|
t.Run("GetAllTickersRequest", func(t *testing.T) {
|
|
req := client.NewGetAllTickersRequest()
|
|
tickers, err := req.Do(ctx)
|
|
assert.NoError(t, err)
|
|
t.Logf("tickers: %+v", tickers)
|
|
})
|
|
|
|
t.Run("GetTickerRequest", func(t *testing.T) {
|
|
req := client.NewGetTickerRequest()
|
|
req.Symbol("BTCUSDT_SPBL")
|
|
ticker, err := req.Do(ctx)
|
|
assert.NoError(t, err)
|
|
t.Logf("ticker: %+v", ticker)
|
|
})
|
|
|
|
t.Run("GetDepthRequest", func(t *testing.T) {
|
|
req := client.NewGetDepthRequest()
|
|
req.Symbol("BTCUSDT_SPBL")
|
|
depth, err := req.Do(ctx)
|
|
assert.NoError(t, err)
|
|
t.Logf("depth: %+v", depth)
|
|
})
|
|
|
|
t.Run("GetServerTimeRequest", func(t *testing.T) {
|
|
req := client.NewGetServerTimeRequest()
|
|
serverTime, err := req.Do(ctx)
|
|
assert.NoError(t, err)
|
|
t.Logf("time: %+v", serverTime)
|
|
})
|
|
|
|
t.Run("GetAccountAssetsRequest", func(t *testing.T) {
|
|
req := client.NewGetAccountAssetsRequest()
|
|
assets, err := req.Do(ctx)
|
|
assert.NoError(t, err)
|
|
t.Logf("assets: %+v", assets)
|
|
})
|
|
}
|