2023-07-21 09:05:19 +00:00
|
|
|
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()
|
|
|
|
|
2023-07-31 02:00:38 +00:00
|
|
|
srv := &PublicDataService{client: client}
|
|
|
|
req := srv.NewGetInstrumentsRequest()
|
2023-07-21 09:05:19 +00:00
|
|
|
|
|
|
|
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()
|
2023-07-31 02:00:38 +00:00
|
|
|
srv := &PublicDataService{client: client}
|
|
|
|
req := srv.NewGetFundingRate()
|
2023-07-21 09:05:19 +00:00
|
|
|
|
|
|
|
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()
|
2023-07-31 02:00:38 +00:00
|
|
|
srv := &TradeService{client: client}
|
|
|
|
req := srv.NewPlaceOrderRequest()
|
2023-07-21 09:05:19 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|