qbtrade/pkg/exchange/bybit/bybitapi/v3/client_test.go

45 lines
1016 B
Go
Raw Normal View History

2024-06-27 14:42:38 +00:00
package v3
import (
"context"
"os"
"strconv"
"testing"
"time"
"github.com/stretchr/testify/assert"
"git.qtrade.icu/lychiyu/qbtrade/pkg/exchange/bybit/bybitapi"
"git.qtrade.icu/lychiyu/qbtrade/pkg/testutil"
)
func getTestClientOrSkip(t *testing.T) *bybitapi.RestClient {
if b, _ := strconv.ParseBool(os.Getenv("CI")); b {
t.Skip("skip test for CI")
}
key, secret, ok := testutil.IntegrationTestConfigured(t, "BYBIT")
if !ok {
t.Skip("BYBIT_* env vars are not configured")
return nil
}
client, err := bybitapi.NewClient()
assert.NoError(t, err)
client.Auth(key, secret)
return client
}
func TestClient(t *testing.T) {
client := getTestClientOrSkip(t)
v3Client := Client{Client: client}
ctx := context.Background()
t.Run("GetTradeRequest", func(t *testing.T) {
startTime := time.Date(2023, 7, 27, 16, 13, 9, 0, time.UTC)
apiResp, err := v3Client.NewGetTradesRequest().Symbol("BTCUSDT").StartTime(startTime).Do(ctx)
assert.NoError(t, err)
t.Logf("apiResp: %+v", apiResp)
})
}