mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
add unit test for okex exchange
This commit is contained in:
parent
3b68d6558e
commit
cba5663fac
76
pkg/exchange/okex/okexapi/client_test.go
Normal file
76
pkg/exchange/okex/okexapi/client_test.go
Normal file
|
@ -0,0 +1,76 @@
|
|||
package okexapi
|
||||
|
||||
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, passphrase, ok := testutil.IntegrationTestWithPassphraseConfigured(t, "OKEX")
|
||||
if !ok {
|
||||
t.SkipNow()
|
||||
return nil
|
||||
}
|
||||
|
||||
client := NewClient()
|
||||
client.Auth(key, secret, passphrase)
|
||||
return client
|
||||
}
|
||||
|
||||
func TestClient_GetInstrumentsRequest(t *testing.T) {
|
||||
client := NewClient()
|
||||
ctx := context.Background()
|
||||
|
||||
ser := PublicDataService{client: client}
|
||||
req := ser.NewGetInstrumentsRequest()
|
||||
|
||||
instruments, err := req.
|
||||
InstrumentType(InstrumentTypeSpot).
|
||||
Do(ctx)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, instruments)
|
||||
t.Logf("instruments: %+v", instruments)
|
||||
}
|
||||
|
||||
func TestClient_GetFundingRateRequest(t *testing.T) {
|
||||
client := NewClient()
|
||||
ctx := context.Background()
|
||||
ser := PublicDataService{client: client}
|
||||
req := ser.NewGetFundingRate()
|
||||
|
||||
instrument, err := req.
|
||||
InstrumentID("BTC-USDT-SWAP").
|
||||
Do(ctx)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, instrument)
|
||||
t.Logf("instrument: %+v", instrument)
|
||||
}
|
||||
|
||||
func TestClient_PlaceOrderRequest(t *testing.T) {
|
||||
client := getTestClientOrSkip(t)
|
||||
ctx := context.Background()
|
||||
ser := TradeService{client: client}
|
||||
req := ser.NewPlaceOrderRequest()
|
||||
|
||||
order, err := req.
|
||||
InstrumentID("XTZ-BTC").
|
||||
TradeMode("cash").
|
||||
Side(SideTypeSell).
|
||||
OrderType(OrderTypeLimit).
|
||||
Price("0.001").
|
||||
Quantity("0.01").
|
||||
Do(ctx)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, order)
|
||||
t.Logf("order: %+v", order) // Right now account has no money
|
||||
}
|
|
@ -23,3 +23,16 @@ func IntegrationTestConfigured(t *testing.T, prefix string) (key, secret string,
|
|||
|
||||
return key, secret, ok
|
||||
}
|
||||
|
||||
func IntegrationTestWithPassphraseConfigured(t *testing.T, prefix string) (key, secret, passphrase string, ok bool) {
|
||||
var hasKey, hasSecret, hasPassphrase bool
|
||||
key, hasKey = os.LookupEnv(prefix + "_API_KEY")
|
||||
secret, hasSecret = os.LookupEnv(prefix + "_API_SECRET")
|
||||
passphrase, hasPassphrase = os.LookupEnv(prefix + "_API_PASSPHRASE")
|
||||
ok = hasKey && hasSecret && hasPassphrase && os.Getenv("TEST_"+prefix) == "1"
|
||||
if ok {
|
||||
t.Logf(prefix+" api integration test enabled, key = %s, secret = %s, passphrase= %s", maskSecret(key), maskSecret(secret), maskSecret(passphrase))
|
||||
}
|
||||
|
||||
return key, secret, passphrase, ok
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user