mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 07:26:47 +00:00
* gatio: fix MessageID regression (cherry-pick me) * Update exchanges/gateio/gateio_wrapper_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * glorious: AI * Update exchanges/gateio/gateio_wrapper.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * thrasher: use optimisation in okx as well * okx: Add length check in tests for string -> uuid conversion * thrasher: nits --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
92 lines
2.8 KiB
Go
92 lines
2.8 KiB
Go
package gateio
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/gofrs/uuid"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
|
)
|
|
|
|
func TestCancelAllOrders(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
_, err := e.CancelAllOrders(t.Context(), nil)
|
|
require.ErrorIs(t, err, order.ErrCancelOrderIsNil)
|
|
|
|
_, err = e.CancelAllOrders(t.Context(), &order.Cancel{Pair: currency.EMPTYPAIR, AssetType: 1336})
|
|
require.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
|
|
|
|
_, err = e.CancelAllOrders(t.Context(), &order.Cancel{Pair: currency.NewBTCUSDT(), AssetType: 1336})
|
|
require.ErrorIs(t, err, asset.ErrNotSupported)
|
|
|
|
_, err = e.CancelAllOrders(t.Context(), &order.Cancel{
|
|
Pair: currency.NewBTCUSDT(),
|
|
AssetType: asset.Options,
|
|
Side: order.ClosePosition,
|
|
})
|
|
require.ErrorIs(t, err, order.ErrSideIsInvalid)
|
|
|
|
_, err = e.CancelAllOrders(t.Context(), &order.Cancel{
|
|
Pair: currency.NewPair(currency.BTC, currency.EMPTYCODE),
|
|
AssetType: asset.USDTMarginedFutures,
|
|
Side: order.Long,
|
|
})
|
|
require.ErrorIs(t, err, errInvalidSettlementQuote)
|
|
|
|
_, err = e.CancelAllOrders(t.Context(), &order.Cancel{
|
|
Pair: currency.NewPair(currency.BTC, currency.EMPTYCODE),
|
|
AssetType: asset.USDTMarginedFutures,
|
|
Side: order.Short,
|
|
})
|
|
require.ErrorIs(t, err, errInvalidSettlementQuote)
|
|
|
|
_, err = e.CancelAllOrders(t.Context(), &order.Cancel{
|
|
Pair: currency.NewPair(currency.BTC, currency.EMPTYCODE),
|
|
AssetType: asset.USDTMarginedFutures,
|
|
Side: order.AnySide,
|
|
})
|
|
require.ErrorIs(t, err, errInvalidSettlementQuote)
|
|
|
|
sharedtestvalues.SkipTestIfCredentialsUnset(t, e, canManipulateRealOrders)
|
|
|
|
for _, a := range e.GetAssetTypes(false) {
|
|
t.Run(a.String(), func(t *testing.T) {
|
|
t.Parallel()
|
|
r := &order.Cancel{
|
|
OrderID: "1",
|
|
AccountID: "1",
|
|
AssetType: a,
|
|
Pair: currency.EMPTYPAIR,
|
|
}
|
|
_, err := e.CancelAllOrders(t.Context(), r)
|
|
assert.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
|
|
|
|
r.Pair = getPair(t, a)
|
|
_, err = e.CancelAllOrders(t.Context(), r)
|
|
assert.NoError(t, err)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMessageID(t *testing.T) {
|
|
t.Parallel()
|
|
id := e.MessageID()
|
|
require.Len(t, id, 32, "message ID must be 32 characters long for usage as a request ID")
|
|
got, err := uuid.FromString(id)
|
|
require.NoError(t, err, "ID string must convert back to a UUID")
|
|
require.Equal(t, uuid.V7, got.Version(), "message ID must be a UUID v7")
|
|
require.Len(t, got.String(), 36, "UUID v7 string representation must be 36 characters long")
|
|
}
|
|
|
|
// 7610378 143.3 ns/op 48 B/op 2 allocs/op
|
|
func BenchmarkMessageID(b *testing.B) {
|
|
for b.Loop() {
|
|
_ = e.MessageID()
|
|
}
|
|
}
|