bbgo_origin/pkg/exchange/max/maxapi/trade_test.go

53 lines
1.1 KiB
Go
Raw Normal View History

2022-04-21 06:52:44 +00:00
package max
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestTradeService(t *testing.T) {
key, secret, ok := integrationTestConfigured(t, "MAX")
if !ok {
t.SkipNow()
}
ctx := context.Background()
client := NewRestClient(ProductionAPIURL)
client.Auth(key, secret)
t.Run("default timestamp", func(t *testing.T) {
req := client.TradeService.NewPrivateTradeRequest()
until := time.Now().AddDate(0, -6, 0)
trades, err := req.Market("btcusdt").
Timestamp(until).
Do(ctx)
if assert.NoError(t, err) {
assert.NotEmptyf(t, trades, "got %d trades", len(trades))
for _, td := range trades {
t.Logf("trade: %+v", td)
assert.True(t, td.CreatedAtMilliSeconds.Time().Before(until))
}
}
})
t.Run("desc and pagination = false", func(t *testing.T) {
req := client.TradeService.NewPrivateTradeRequest()
trades, err := req.Market("btcusdt").
Pagination(false).
OrderBy("asc").
Do(ctx)
if assert.NoError(t, err) {
assert.NotEmptyf(t, trades, "got %d trades", len(trades))
for _, td := range trades {
t.Logf("trade: %+v", td)
}
}
})
}