mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 23:16:52 +00:00
common: Replace StringDataCompare with slices.Contains and cleanup string funcs (#1631)
* common: Replace StringDataCompare with slices.Contains and cleanup string funcs * common/docs: Update SliceDifference and remove outdated steps from ADD_NEW_EXCHANGE.md * common: Improve SliceDifference
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
@@ -21,15 +21,9 @@ func TestString(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestToStringArray(t *testing.T) {
|
||||
func TestStrings(t *testing.T) {
|
||||
t.Parallel()
|
||||
a := Items{Spot, Futures}
|
||||
result := a.Strings()
|
||||
for x := range a {
|
||||
if !common.StringDataCompare(result, a[x].String()) {
|
||||
t.Fatal("TestToStringArray returned an unexpected result")
|
||||
}
|
||||
}
|
||||
assert.ElementsMatch(t, Items{Spot, Futures}.Strings(), []string{"spot", "futures"})
|
||||
}
|
||||
|
||||
func TestContains(t *testing.T) {
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
@@ -257,7 +257,7 @@ func (b *Binance) GetFuturesKlineData(ctx context.Context, symbol currency.Pair,
|
||||
if limit > 0 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
if !common.StringDataCompare(validFuturesIntervals, interval) {
|
||||
if !slices.Contains(validFuturesIntervals, interval) {
|
||||
return nil, errors.New("invalid interval parsed")
|
||||
}
|
||||
params.Set("interval", interval)
|
||||
@@ -369,14 +369,14 @@ func (b *Binance) GetFuturesKlineData(ctx context.Context, symbol currency.Pair,
|
||||
func (b *Binance) GetContinuousKlineData(ctx context.Context, pair, contractType, interval string, limit int64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
params := url.Values{}
|
||||
params.Set("pair", pair)
|
||||
if !common.StringDataCompare(validContractType, contractType) {
|
||||
if !slices.Contains(validContractType, contractType) {
|
||||
return nil, errors.New("invalid contractType")
|
||||
}
|
||||
params.Set("contractType", contractType)
|
||||
if limit > 0 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
if !common.StringDataCompare(validFuturesIntervals, interval) {
|
||||
if !slices.Contains(validFuturesIntervals, interval) {
|
||||
return nil, errors.New("invalid interval parsed")
|
||||
}
|
||||
params.Set("interval", interval)
|
||||
@@ -491,7 +491,7 @@ func (b *Binance) GetIndexPriceKlines(ctx context.Context, pair, interval string
|
||||
if limit > 0 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
if !common.StringDataCompare(validFuturesIntervals, interval) {
|
||||
if !slices.Contains(validFuturesIntervals, interval) {
|
||||
return nil, errors.New("invalid interval parsed")
|
||||
}
|
||||
params.Set("interval", interval)
|
||||
@@ -610,7 +610,7 @@ func (b *Binance) GetMarkPriceKline(ctx context.Context, symbol currency.Pair, i
|
||||
if limit > 0 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
if !common.StringDataCompare(validFuturesIntervals, interval) {
|
||||
if !slices.Contains(validFuturesIntervals, interval) {
|
||||
return nil, errors.New("invalid interval parsed")
|
||||
}
|
||||
params.Set("interval", interval)
|
||||
@@ -833,11 +833,11 @@ func (b *Binance) GetOpenInterestStats(ctx context.Context, pair, contractType,
|
||||
if pair != "" {
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
if !common.StringDataCompare(validContractType, contractType) {
|
||||
if !slices.Contains(validContractType, contractType) {
|
||||
return resp, errors.New("invalid contractType")
|
||||
}
|
||||
params.Set("contractType", contractType)
|
||||
if !common.StringDataCompare(validFuturesIntervals, period) {
|
||||
if !slices.Contains(validFuturesIntervals, period) {
|
||||
return resp, errors.New("invalid period")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -859,7 +859,7 @@ func (b *Binance) GetTraderFuturesAccountRatio(ctx context.Context, pair, period
|
||||
var resp []TopTraderAccountRatio
|
||||
params := url.Values{}
|
||||
params.Set("pair", pair)
|
||||
if !common.StringDataCompare(validFuturesIntervals, period) {
|
||||
if !slices.Contains(validFuturesIntervals, period) {
|
||||
return resp, errors.New("invalid period")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -881,7 +881,7 @@ func (b *Binance) GetTraderFuturesPositionsRatio(ctx context.Context, pair, peri
|
||||
var resp []TopTraderPositionRatio
|
||||
params := url.Values{}
|
||||
params.Set("pair", pair)
|
||||
if !common.StringDataCompare(validFuturesIntervals, period) {
|
||||
if !slices.Contains(validFuturesIntervals, period) {
|
||||
return resp, errors.New("invalid period")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -903,7 +903,7 @@ func (b *Binance) GetMarketRatio(ctx context.Context, pair, period string, limit
|
||||
var resp []TopTraderPositionRatio
|
||||
params := url.Values{}
|
||||
params.Set("pair", pair)
|
||||
if !common.StringDataCompare(validFuturesIntervals, period) {
|
||||
if !slices.Contains(validFuturesIntervals, period) {
|
||||
return resp, errors.New("invalid period")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -925,14 +925,14 @@ func (b *Binance) GetFuturesTakerVolume(ctx context.Context, pair, contractType,
|
||||
var resp []TakerBuySellVolume
|
||||
params := url.Values{}
|
||||
params.Set("pair", pair)
|
||||
if !common.StringDataCompare(validContractType, contractType) {
|
||||
if !slices.Contains(validContractType, contractType) {
|
||||
return resp, errors.New("invalid contractType")
|
||||
}
|
||||
params.Set("contractType", contractType)
|
||||
if limit > 0 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
if !common.StringDataCompare(validFuturesIntervals, period) {
|
||||
if !slices.Contains(validFuturesIntervals, period) {
|
||||
return resp, errors.New("invalid period parsed")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -951,14 +951,14 @@ func (b *Binance) GetFuturesBasisData(ctx context.Context, pair, contractType, p
|
||||
var resp []FuturesBasisData
|
||||
params := url.Values{}
|
||||
params.Set("pair", pair)
|
||||
if !common.StringDataCompare(validContractType, contractType) {
|
||||
if !slices.Contains(validContractType, contractType) {
|
||||
return resp, errors.New("invalid contractType")
|
||||
}
|
||||
params.Set("contractType", contractType)
|
||||
if limit > 0 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
if !common.StringDataCompare(validFuturesIntervals, period) {
|
||||
if !slices.Contains(validFuturesIntervals, period) {
|
||||
return resp, errors.New("invalid period parsed")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -986,7 +986,7 @@ func (b *Binance) FuturesNewOrder(ctx context.Context, x *FuturesNewOrderRequest
|
||||
params.Set("symbol", symbolValue)
|
||||
params.Set("side", x.Side)
|
||||
if x.PositionSide != "" {
|
||||
if !common.StringDataCompare(validPositionSide, x.PositionSide) {
|
||||
if !slices.Contains(validPositionSide, x.PositionSide) {
|
||||
return resp, errors.New("invalid positionSide")
|
||||
}
|
||||
params.Set("positionSide", x.PositionSide)
|
||||
@@ -1005,13 +1005,13 @@ func (b *Binance) FuturesNewOrder(ctx context.Context, x *FuturesNewOrderRequest
|
||||
params.Set("closePosition", x.ClosePosition)
|
||||
}
|
||||
if x.WorkingType != "" {
|
||||
if !common.StringDataCompare(validWorkingType, x.WorkingType) {
|
||||
if !slices.Contains(validWorkingType, x.WorkingType) {
|
||||
return resp, errors.New("invalid workingType")
|
||||
}
|
||||
params.Set("workingType", x.WorkingType)
|
||||
}
|
||||
if x.NewOrderRespType != "" {
|
||||
if !common.StringDataCompare(validNewOrderRespType, x.NewOrderRespType) {
|
||||
if !slices.Contains(validNewOrderRespType, x.NewOrderRespType) {
|
||||
return resp, errors.New("invalid newOrderRespType")
|
||||
}
|
||||
params.Set("newOrderRespType", x.NewOrderRespType)
|
||||
@@ -1052,17 +1052,17 @@ func (b *Binance) FuturesBatchOrder(ctx context.Context, data []PlaceBatchOrderD
|
||||
}
|
||||
data[x].Symbol = formattedPair.String()
|
||||
if data[x].PositionSide != "" {
|
||||
if !common.StringDataCompare(validPositionSide, data[x].PositionSide) {
|
||||
if !slices.Contains(validPositionSide, data[x].PositionSide) {
|
||||
return resp, errors.New("invalid positionSide")
|
||||
}
|
||||
}
|
||||
if data[x].WorkingType != "" {
|
||||
if !common.StringDataCompare(validWorkingType, data[x].WorkingType) {
|
||||
if !slices.Contains(validWorkingType, data[x].WorkingType) {
|
||||
return resp, errors.New("invalid workingType")
|
||||
}
|
||||
}
|
||||
if data[x].NewOrderRespType != "" {
|
||||
if !common.StringDataCompare(validNewOrderRespType, data[x].NewOrderRespType) {
|
||||
if !slices.Contains(validNewOrderRespType, data[x].NewOrderRespType) {
|
||||
return resp, errors.New("invalid newOrderRespType")
|
||||
}
|
||||
}
|
||||
@@ -1274,7 +1274,7 @@ func (b *Binance) FuturesChangeMarginType(ctx context.Context, symbol currency.P
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
if !common.StringDataCompare(validMarginType, marginType) {
|
||||
if !slices.Contains(validMarginType, marginType) {
|
||||
return resp, errors.New("invalid marginType")
|
||||
}
|
||||
params.Set("marginType", marginType)
|
||||
@@ -1291,7 +1291,7 @@ func (b *Binance) ModifyIsolatedPositionMargin(ctx context.Context, symbol curre
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
if positionSide != "" {
|
||||
if !common.StringDataCompare(validPositionSide, positionSide) {
|
||||
if !slices.Contains(validPositionSide, positionSide) {
|
||||
return resp, errors.New("invalid positionSide")
|
||||
}
|
||||
params.Set("positionSide", positionSide)
|
||||
@@ -1393,7 +1393,7 @@ func (b *Binance) FuturesIncomeHistory(ctx context.Context, symbol currency.Pair
|
||||
params.Set("symbol", symbolValue)
|
||||
}
|
||||
if incomeType != "" {
|
||||
if !common.StringDataCompare(validIncomeType, incomeType) {
|
||||
if !slices.Contains(validIncomeType, incomeType) {
|
||||
return resp, fmt.Errorf("invalid incomeType: %v", incomeType)
|
||||
}
|
||||
params.Set("incomeType", incomeType)
|
||||
@@ -1433,7 +1433,7 @@ func (b *Binance) FuturesForceOrders(ctx context.Context, symbol currency.Pair,
|
||||
params.Set("symbol", symbolValue)
|
||||
}
|
||||
if autoCloseType != "" {
|
||||
if !common.StringDataCompare(validAutoCloseTypes, autoCloseType) {
|
||||
if !slices.Contains(validAutoCloseTypes, autoCloseType) {
|
||||
return resp, errors.New("invalid autoCloseType")
|
||||
}
|
||||
params.Set("autoCloseType", autoCloseType)
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
@@ -96,7 +96,7 @@ func (b *Binance) UFuturesOrderbook(ctx context.Context, symbol currency.Pair, l
|
||||
params.Set("symbol", symbolValue)
|
||||
strLimit := strconv.FormatInt(limit, 10)
|
||||
if strLimit != "" {
|
||||
if !common.StringDataCompare(uValidOBLimits, strLimit) {
|
||||
if !slices.Contains(uValidOBLimits, strLimit) {
|
||||
return nil, fmt.Errorf("invalid limit: %v", limit)
|
||||
}
|
||||
params.Set("limit", strLimit)
|
||||
@@ -228,7 +228,7 @@ func (b *Binance) UKlineData(ctx context.Context, symbol currency.Pair, interval
|
||||
return nil, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
if !common.StringDataCompare(validFuturesIntervals, interval) {
|
||||
if !slices.Contains(validFuturesIntervals, interval) {
|
||||
return nil, errors.New("invalid interval")
|
||||
}
|
||||
params.Set("interval", interval)
|
||||
@@ -494,7 +494,7 @@ func (b *Binance) UOpenInterestStats(ctx context.Context, symbol currency.Pair,
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
if !common.StringDataCompare(uValidPeriods, period) {
|
||||
if !slices.Contains(uValidPeriods, period) {
|
||||
return resp, errors.New("invalid period")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -520,7 +520,7 @@ func (b *Binance) UTopAcccountsLongShortRatio(ctx context.Context, symbol curren
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
if !common.StringDataCompare(uValidPeriods, period) {
|
||||
if !slices.Contains(uValidPeriods, period) {
|
||||
return resp, errors.New("invalid period")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -546,7 +546,7 @@ func (b *Binance) UTopPostionsLongShortRatio(ctx context.Context, symbol currenc
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
if !common.StringDataCompare(uValidPeriods, period) {
|
||||
if !slices.Contains(uValidPeriods, period) {
|
||||
return resp, errors.New("invalid period")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -572,7 +572,7 @@ func (b *Binance) UGlobalLongShortRatio(ctx context.Context, symbol currency.Pai
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
if !common.StringDataCompare(uValidPeriods, period) {
|
||||
if !slices.Contains(uValidPeriods, period) {
|
||||
return resp, errors.New("invalid period")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -598,7 +598,7 @@ func (b *Binance) UTakerBuySellVol(ctx context.Context, symbol currency.Pair, pe
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
if !common.StringDataCompare(uValidPeriods, period) {
|
||||
if !slices.Contains(uValidPeriods, period) {
|
||||
return resp, errors.New("invalid period")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -646,7 +646,7 @@ func (b *Binance) UFuturesNewOrder(ctx context.Context, data *UFuturesNewOrderRe
|
||||
params.Set("symbol", symbolValue)
|
||||
params.Set("side", data.Side)
|
||||
if data.PositionSide != "" {
|
||||
if !common.StringDataCompare(validPositionSide, data.PositionSide) {
|
||||
if !slices.Contains(validPositionSide, data.PositionSide) {
|
||||
return resp, errors.New("invalid positionSide")
|
||||
}
|
||||
params.Set("positionSide", data.PositionSide)
|
||||
@@ -663,13 +663,13 @@ func (b *Binance) UFuturesNewOrder(ctx context.Context, data *UFuturesNewOrderRe
|
||||
params.Set("closePosition", data.ClosePosition)
|
||||
}
|
||||
if data.WorkingType != "" {
|
||||
if !common.StringDataCompare(validWorkingType, data.WorkingType) {
|
||||
if !slices.Contains(validWorkingType, data.WorkingType) {
|
||||
return resp, errors.New("invalid workingType")
|
||||
}
|
||||
params.Set("workingType", data.WorkingType)
|
||||
}
|
||||
if data.NewOrderRespType != "" {
|
||||
if !common.StringDataCompare(validNewOrderRespType, data.NewOrderRespType) {
|
||||
if !slices.Contains(validNewOrderRespType, data.NewOrderRespType) {
|
||||
return resp, errors.New("invalid newOrderRespType")
|
||||
}
|
||||
params.Set("newOrderRespType", data.NewOrderRespType)
|
||||
@@ -707,17 +707,17 @@ func (b *Binance) UPlaceBatchOrders(ctx context.Context, data []PlaceBatchOrderD
|
||||
}
|
||||
data[x].Symbol = formattedPair.String()
|
||||
if data[x].PositionSide != "" {
|
||||
if !common.StringDataCompare(validPositionSide, data[x].PositionSide) {
|
||||
if !slices.Contains(validPositionSide, data[x].PositionSide) {
|
||||
return resp, errors.New("invalid positionSide")
|
||||
}
|
||||
}
|
||||
if data[x].WorkingType != "" {
|
||||
if !common.StringDataCompare(validWorkingType, data[x].WorkingType) {
|
||||
if !slices.Contains(validWorkingType, data[x].WorkingType) {
|
||||
return resp, errors.New("invalid workingType")
|
||||
}
|
||||
}
|
||||
if data[x].NewOrderRespType != "" {
|
||||
if !common.StringDataCompare(validNewOrderRespType, data[x].NewOrderRespType) {
|
||||
if !slices.Contains(validNewOrderRespType, data[x].NewOrderRespType) {
|
||||
return resp, errors.New("invalid newOrderRespType")
|
||||
}
|
||||
}
|
||||
@@ -916,7 +916,7 @@ func (b *Binance) UChangeInitialMarginType(ctx context.Context, symbol currency.
|
||||
return err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
if !common.StringDataCompare(validMarginType, marginType) {
|
||||
if !slices.Contains(validMarginType, marginType) {
|
||||
return errors.New("invalid marginType")
|
||||
}
|
||||
params.Set("marginType", marginType)
|
||||
@@ -1034,7 +1034,7 @@ func (b *Binance) UAccountIncomeHistory(ctx context.Context, symbol currency.Pai
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
if incomeType != "" {
|
||||
if !common.StringDataCompare(validIncomeType, incomeType) {
|
||||
if !slices.Contains(validIncomeType, incomeType) {
|
||||
return resp, errors.New("invalid incomeType")
|
||||
}
|
||||
params.Set("incomeType", incomeType)
|
||||
@@ -1094,7 +1094,7 @@ func (b *Binance) UAccountForcedOrders(ctx context.Context, symbol currency.Pair
|
||||
params.Set("symbol", symbolValue)
|
||||
}
|
||||
if autoCloseType != "" {
|
||||
if !common.StringDataCompare(validAutoCloseTypes, autoCloseType) {
|
||||
if !slices.Contains(validAutoCloseTypes, autoCloseType) {
|
||||
return resp, errors.New("invalid incomeType")
|
||||
}
|
||||
params.Set("autoCloseType", autoCloseType)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -436,7 +437,7 @@ func (b *Bitfinex) GetPairs(ctx context.Context, a asset.Item) ([]string, error)
|
||||
}
|
||||
filtered := make([]string, 0, len(list))
|
||||
for x := range list {
|
||||
if common.StringDataCompare(filter, list[x]) {
|
||||
if slices.Contains(filter, list[x]) {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, list[x])
|
||||
@@ -1262,7 +1263,7 @@ func (b *Bitfinex) GetAccountSummary(ctx context.Context) (AccountSummary, error
|
||||
func (b *Bitfinex) NewDeposit(ctx context.Context, method, walletName string, renew uint8) (*Deposit, error) {
|
||||
if walletName == "" {
|
||||
walletName = "funding"
|
||||
} else if !common.StringDataCompare(AcceptedWalletNames, walletName) {
|
||||
} else if !slices.Contains(AcceptedWalletNames, walletName) {
|
||||
return nil,
|
||||
fmt.Errorf("walletname: [%s] is not allowed, supported: %s",
|
||||
walletName,
|
||||
@@ -1463,7 +1464,7 @@ func (b *Bitfinex) WithdrawFIAT(ctx context.Context, withdrawalType, walletType
|
||||
// NewOrder submits a new order and returns a order information
|
||||
// Major Upgrade needed on this function to include all query params
|
||||
func (b *Bitfinex) NewOrder(ctx context.Context, currencyPair, orderType string, amount, price float64, buy, hidden bool) (Order, error) {
|
||||
if !common.StringDataCompare(AcceptedOrderType, orderType) {
|
||||
if !slices.Contains(AcceptedOrderType, orderType) {
|
||||
return Order{}, fmt.Errorf("order type %s not accepted", orderType)
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ func (a *acceptableMethodStore) lookup(curr currency.Code) []string {
|
||||
defer a.m.RUnlock()
|
||||
var methods []string
|
||||
for k, v := range a.a {
|
||||
if common.StringDataCompareInsensitive(v, curr.Upper().String()) {
|
||||
if common.StringSliceCompareInsensitive(v, curr.Upper().String()) {
|
||||
methods = append(methods, k)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -914,7 +914,7 @@ func (b *Bitfinex) WithdrawCryptocurrencyFunds(ctx context.Context, withdrawRequ
|
||||
}
|
||||
method := methods[0]
|
||||
if len(methods) > 1 && withdrawRequest.Crypto.Chain != "" {
|
||||
if !common.StringDataCompareInsensitive(methods, withdrawRequest.Crypto.Chain) {
|
||||
if !common.StringSliceCompareInsensitive(methods, withdrawRequest.Crypto.Chain) {
|
||||
return nil, fmt.Errorf("invalid chain %s supplied, %v available", withdrawRequest.Crypto.Chain, methods)
|
||||
}
|
||||
method = withdrawRequest.Crypto.Chain
|
||||
|
||||
@@ -358,7 +358,7 @@ func (b *BTCMarkets) Subscribe(subs subscription.List) error {
|
||||
|
||||
var errs error
|
||||
for _, s := range subs {
|
||||
if baseReq.Key == "" && common.StringDataContains(authChannels, s.Channel) {
|
||||
if baseReq.Key == "" && common.StringSliceContains(authChannels, s.Channel) {
|
||||
if err := b.authWsSubscibeReq(baseReq); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -1343,7 +1344,7 @@ func (by *Bybit) GetCoinGreeks(ctx context.Context, baseCoin string) (*CoinGreek
|
||||
// GetFeeRate retrieves the trading fee rate.
|
||||
func (by *Bybit) GetFeeRate(ctx context.Context, category, symbol, baseCoin string) (*AccountFee, error) {
|
||||
params := url.Values{}
|
||||
if !common.StringDataContains(validCategory, category) {
|
||||
if !slices.Contains(validCategory, category) {
|
||||
return nil, fmt.Errorf("%w, valid category values are %v", errInvalidCategory, validCategory)
|
||||
}
|
||||
if category != "" {
|
||||
@@ -1470,7 +1471,7 @@ func (by *Bybit) GetCoinExchangeRecords(ctx context.Context, fromCoin, toCoin, c
|
||||
|
||||
// GetDeliveryRecord retrieves delivery records of USDC futures and Options, sorted by deliveryTime in descending order
|
||||
func (by *Bybit) GetDeliveryRecord(ctx context.Context, category, symbol, cursor string, expiryDate time.Time, limit int64) (*DeliveryRecord, error) {
|
||||
if !common.StringDataContains([]string{cLinear, cOption}, category) {
|
||||
if !slices.Contains([]string{cLinear, cOption}, category) {
|
||||
return nil, fmt.Errorf("%w, valid category values are %v", errInvalidCategory, []string{cLinear, cOption})
|
||||
}
|
||||
params := url.Values{}
|
||||
@@ -1493,7 +1494,7 @@ func (by *Bybit) GetDeliveryRecord(ctx context.Context, category, symbol, cursor
|
||||
|
||||
// GetUSDCSessionSettlement retrieves session settlement records of USDC perpetual and futures
|
||||
func (by *Bybit) GetUSDCSessionSettlement(ctx context.Context, category, symbol, cursor string, limit int64) (*SettlementSession, error) {
|
||||
if !common.StringDataContains([]string{cLinear}, category) {
|
||||
if category != cLinear {
|
||||
return nil, fmt.Errorf("%w, valid category value is %v", errInvalidCategory, cLinear)
|
||||
}
|
||||
params := url.Values{}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -224,9 +225,8 @@ func (c *CoinbasePro) GetHistoricRates(ctx context.Context, currencyPair, start,
|
||||
values.Set("end", "")
|
||||
}
|
||||
|
||||
allowedGranularities := [6]int64{60, 300, 900, 3600, 21600, 86400}
|
||||
validGran, _ := common.InArray(granularity, allowedGranularities)
|
||||
if !validGran {
|
||||
allowedGranularities := []int64{60, 300, 900, 3600, 21600, 86400}
|
||||
if !slices.Contains(allowedGranularities, granularity) {
|
||||
return nil, errors.New("Invalid granularity value: " + strconv.FormatInt(granularity, 10) + ". Allowed values are {60, 300, 900, 3600, 21600, 86400}")
|
||||
}
|
||||
if granularity > 0 {
|
||||
|
||||
@@ -136,7 +136,7 @@ func (h *HUOBI) GetSwapKlineData(ctx context.Context, code currency.Pair, period
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if !common.StringDataCompareInsensitive(validPeriods, period) {
|
||||
if !common.StringSliceCompareInsensitive(validPeriods, period) {
|
||||
return resp, errors.New("invalid period value received")
|
||||
}
|
||||
params := url.Values{}
|
||||
@@ -248,7 +248,7 @@ func (h *HUOBI) GetOpenInterestInfo(ctx context.Context, code currency.Pair, per
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if !common.StringDataCompareInsensitive(validPeriods, period) {
|
||||
if !common.StringSliceCompareInsensitive(validPeriods, period) {
|
||||
return resp, errors.New("invalid period value received")
|
||||
}
|
||||
if size <= 0 || size > 1200 {
|
||||
@@ -287,7 +287,7 @@ func (h *HUOBI) GetTraderSentimentIndexAccount(ctx context.Context, code currenc
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if !common.StringDataCompareInsensitive(validPeriods, period) {
|
||||
if !common.StringSliceCompareInsensitive(validPeriods, period) {
|
||||
return resp, errors.New("invalid period value received")
|
||||
}
|
||||
params := url.Values{}
|
||||
@@ -305,7 +305,7 @@ func (h *HUOBI) GetTraderSentimentIndexPosition(ctx context.Context, code curren
|
||||
return resp, err
|
||||
}
|
||||
|
||||
if !common.StringDataCompareInsensitive(validPeriods, period) {
|
||||
if !common.StringSliceCompareInsensitive(validPeriods, period) {
|
||||
return resp, errors.New("invalid period value received")
|
||||
}
|
||||
params := url.Values{}
|
||||
@@ -372,7 +372,7 @@ func (h *HUOBI) GetPremiumIndexKlineData(ctx context.Context, code currency.Pair
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if !common.StringDataCompareInsensitive(validPeriods, period) {
|
||||
if !common.StringSliceCompareInsensitive(validPeriods, period) {
|
||||
return resp, errors.New("invalid period value received")
|
||||
}
|
||||
if size <= 0 || size > 1200 {
|
||||
@@ -393,7 +393,7 @@ func (h *HUOBI) GetEstimatedFundingRates(ctx context.Context, code currency.Pair
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if !common.StringDataCompareInsensitive(validPeriods, period) {
|
||||
if !common.StringSliceCompareInsensitive(validPeriods, period) {
|
||||
return resp, errors.New("invalid period value received")
|
||||
}
|
||||
if size <= 0 || size > 1200 {
|
||||
@@ -414,13 +414,13 @@ func (h *HUOBI) GetBasisData(ctx context.Context, code currency.Pair, period, ba
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if !common.StringDataCompareInsensitive(validPeriods, period) {
|
||||
if !common.StringSliceCompareInsensitive(validPeriods, period) {
|
||||
return resp, errors.New("invalid period value received")
|
||||
}
|
||||
if size <= 0 || size > 1200 {
|
||||
return resp, errors.New("invalid size provided, only values between 1-1200 are supported")
|
||||
}
|
||||
if !common.StringDataCompareInsensitive(validBasisPriceTypes, basisPriceType) {
|
||||
if !common.StringSliceCompareInsensitive(validBasisPriceTypes, basisPriceType) {
|
||||
return resp, errors.New("invalid period value received")
|
||||
}
|
||||
params := url.Values{}
|
||||
@@ -581,7 +581,7 @@ func (h *HUOBI) GetSwapOrderLimitInfo(ctx context.Context, code currency.Pair, o
|
||||
return resp, err
|
||||
}
|
||||
req["contract_code"] = codeValue
|
||||
if !common.StringDataCompareInsensitive(validOrderTypes, orderType) {
|
||||
if !common.StringSliceCompareInsensitive(validOrderTypes, orderType) {
|
||||
return resp, errors.New("invalid ordertype provided")
|
||||
}
|
||||
req["order_price_type"] = orderType
|
||||
@@ -635,7 +635,7 @@ func (h *HUOBI) AccountTransferData(ctx context.Context, code currency.Pair, sub
|
||||
req["contract_code"] = codeValue
|
||||
req["subUid"] = subUID
|
||||
req["amount"] = amount
|
||||
if !common.StringDataCompareInsensitive(validTransferType, transferType) {
|
||||
if !common.StringSliceCompareInsensitive(validTransferType, transferType) {
|
||||
return resp, errors.New("invalid transferType received")
|
||||
}
|
||||
req["type"] = transferType
|
||||
@@ -651,7 +651,7 @@ func (h *HUOBI) AccountTransferRecords(ctx context.Context, code currency.Pair,
|
||||
return resp, err
|
||||
}
|
||||
req["contract_code"] = codeValue
|
||||
if !common.StringDataCompareInsensitive(validTransferType, transferType) {
|
||||
if !common.StringSliceCompareInsensitive(validTransferType, transferType) {
|
||||
return resp, errors.New("invalid transferType received")
|
||||
}
|
||||
req["type"] = transferType
|
||||
@@ -682,7 +682,7 @@ func (h *HUOBI) PlaceSwapOrders(ctx context.Context, code currency.Pair, clientO
|
||||
}
|
||||
req["direction"] = direction
|
||||
req["offset"] = offset
|
||||
if !common.StringDataCompareInsensitive(validOrderTypes, orderPriceType) {
|
||||
if !common.StringSliceCompareInsensitive(validOrderTypes, orderPriceType) {
|
||||
return resp, errors.New("invalid ordertype provided")
|
||||
}
|
||||
req["order_price_type"] = orderPriceType
|
||||
@@ -750,7 +750,7 @@ func (h *HUOBI) PlaceLightningCloseOrder(ctx context.Context, contractCode curre
|
||||
req["client_order_id"] = clientOrderID
|
||||
}
|
||||
if orderPriceType != "" {
|
||||
if !common.StringDataCompareInsensitive(validLightningOrderPriceType, orderPriceType) {
|
||||
if !common.StringSliceCompareInsensitive(validLightningOrderPriceType, orderPriceType) {
|
||||
return resp, errors.New("invalid orderPriceType")
|
||||
}
|
||||
req["order_price_type"] = orderPriceType
|
||||
@@ -913,7 +913,7 @@ func (h *HUOBI) PlaceSwapTriggerOrder(ctx context.Context, contractCode currency
|
||||
req["volume"] = volume
|
||||
req["lever_rate"] = leverageRate
|
||||
req["order_price"] = orderPrice
|
||||
if !common.StringDataCompareInsensitive(validOrderPriceType, orderPriceType) {
|
||||
if !common.StringSliceCompareInsensitive(validOrderPriceType, orderPriceType) {
|
||||
return resp, errors.New("invalid order price type")
|
||||
}
|
||||
req["order_price_type"] = orderPriceType
|
||||
|
||||
@@ -91,7 +91,7 @@ func (h *HUOBI) FGetContractInfo(ctx context.Context, symbol, contractType strin
|
||||
params.Set("symbol", symbol)
|
||||
}
|
||||
if contractType != "" {
|
||||
if !common.StringDataCompareInsensitive(validContractTypes, contractType) {
|
||||
if !common.StringSliceCompareInsensitive(validContractTypes, contractType) {
|
||||
return resp, errors.New("invalid contractType")
|
||||
}
|
||||
params.Set("contract_type", contractType)
|
||||
@@ -130,7 +130,7 @@ func (h *HUOBI) FContractPriceLimitations(ctx context.Context, symbol, contractT
|
||||
params.Set("symbol", symbol)
|
||||
}
|
||||
if contractType != "" {
|
||||
if !common.StringDataCompareInsensitive(validContractTypes, contractType) {
|
||||
if !common.StringSliceCompareInsensitive(validContractTypes, contractType) {
|
||||
return resp, fmt.Errorf("invalid contractType: %s", contractType)
|
||||
}
|
||||
params.Set("contract_type", contractType)
|
||||
@@ -164,7 +164,7 @@ func (h *HUOBI) ContractOpenInterestUSDT(ctx context.Context, contractCode, pair
|
||||
params.Set("pair", p)
|
||||
}
|
||||
if contractType != "" {
|
||||
if !common.StringDataCompareInsensitive(validContractTypes, contractType) {
|
||||
if !common.StringSliceCompareInsensitive(validContractTypes, contractType) {
|
||||
return nil, errors.New("invalid contractType")
|
||||
}
|
||||
params.Set("contract_type", contractType)
|
||||
@@ -187,7 +187,7 @@ func (h *HUOBI) FContractOpenInterest(ctx context.Context, symbol, contractType
|
||||
params.Set("symbol", symbol)
|
||||
}
|
||||
if contractType != "" {
|
||||
if !common.StringDataCompareInsensitive(validContractTypes, contractType) {
|
||||
if !common.StringSliceCompareInsensitive(validContractTypes, contractType) {
|
||||
return resp, errors.New("invalid contractType")
|
||||
}
|
||||
params.Set("contract_type", contractType)
|
||||
@@ -263,7 +263,7 @@ func (h *HUOBI) FGetKlineData(ctx context.Context, symbol currency.Pair, period
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
if !common.StringDataCompareInsensitive(validFuturesPeriods, period) {
|
||||
if !common.StringSliceCompareInsensitive(validFuturesPeriods, period) {
|
||||
return resp, errors.New("invalid period value received")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -375,11 +375,11 @@ func (h *HUOBI) FQueryHisOpenInterest(ctx context.Context, symbol, contractType,
|
||||
if symbol != "" {
|
||||
params.Set("symbol", symbol)
|
||||
}
|
||||
if !common.StringDataCompareInsensitive(validContractTypes, contractType) {
|
||||
if !common.StringSliceCompareInsensitive(validContractTypes, contractType) {
|
||||
return resp, fmt.Errorf("%w %v", errInvalidContractType, contractType)
|
||||
}
|
||||
params.Set("contract_type", contractType)
|
||||
if !common.StringDataCompareInsensitive(validPeriods, period) {
|
||||
if !common.StringSliceCompareInsensitive(validPeriods, period) {
|
||||
return resp, errors.New("invalid period")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -417,7 +417,7 @@ func (h *HUOBI) FQueryTopAccountsRatio(ctx context.Context, symbol, period strin
|
||||
if symbol != "" {
|
||||
params.Set("symbol", symbol)
|
||||
}
|
||||
if !common.StringDataCompareInsensitive(validPeriods, period) {
|
||||
if !common.StringSliceCompareInsensitive(validPeriods, period) {
|
||||
return resp, errors.New("invalid period")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -432,7 +432,7 @@ func (h *HUOBI) FQueryTopPositionsRatio(ctx context.Context, symbol, period stri
|
||||
if symbol != "" {
|
||||
params.Set("symbol", symbol)
|
||||
}
|
||||
if !common.StringDataCompareInsensitive(validPeriods, period) {
|
||||
if !common.StringSliceCompareInsensitive(validPeriods, period) {
|
||||
return resp, errors.New("invalid period")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -476,7 +476,7 @@ func (h *HUOBI) FIndexKline(ctx context.Context, symbol currency.Pair, period st
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
if !common.StringDataCompareInsensitive(validFuturesPeriods, period) {
|
||||
if !common.StringSliceCompareInsensitive(validFuturesPeriods, period) {
|
||||
return resp, errors.New("invalid period value received")
|
||||
}
|
||||
params.Set("period", period)
|
||||
@@ -497,12 +497,12 @@ func (h *HUOBI) FGetBasisData(ctx context.Context, symbol currency.Pair, period,
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
if !common.StringDataCompareInsensitive(validFuturesPeriods, period) {
|
||||
if !common.StringSliceCompareInsensitive(validFuturesPeriods, period) {
|
||||
return resp, errors.New("invalid period value received")
|
||||
}
|
||||
params.Set("period", period)
|
||||
if basisPriceType != "" {
|
||||
if common.StringDataCompareInsensitive(validBasisPriceTypes, basisPriceType) {
|
||||
if common.StringSliceCompareInsensitive(validBasisPriceTypes, basisPriceType) {
|
||||
params.Set("basis_price_type", basisPriceType)
|
||||
}
|
||||
}
|
||||
@@ -632,7 +632,7 @@ func (h *HUOBI) FGetOrderLimits(ctx context.Context, symbol, orderPriceType stri
|
||||
req["symbol"] = symbol
|
||||
}
|
||||
if orderPriceType != "" {
|
||||
if !common.StringDataCompareInsensitive(validFuturesOrderPriceTypes, orderPriceType) {
|
||||
if !common.StringSliceCompareInsensitive(validFuturesOrderPriceTypes, orderPriceType) {
|
||||
return resp, errors.New("invalid orderPriceType")
|
||||
}
|
||||
req["order_price_type"] = orderPriceType
|
||||
@@ -697,7 +697,7 @@ func (h *HUOBI) FTransfer(ctx context.Context, subUID, symbol, transferType stri
|
||||
req["symbol"] = symbol
|
||||
req["subUid"] = subUID
|
||||
req["amount"] = amount
|
||||
if !common.StringDataCompareInsensitive(validTransferType, transferType) {
|
||||
if !common.StringSliceCompareInsensitive(validTransferType, transferType) {
|
||||
return resp, errors.New("invalid transferType received")
|
||||
}
|
||||
req["type"] = transferType
|
||||
@@ -711,7 +711,7 @@ func (h *HUOBI) FGetTransferRecords(ctx context.Context, symbol, transferType st
|
||||
if symbol != "" {
|
||||
req["symbol"] = symbol
|
||||
}
|
||||
if !common.StringDataCompareInsensitive(validTransferType, transferType) {
|
||||
if !common.StringSliceCompareInsensitive(validTransferType, transferType) {
|
||||
return resp, errors.New("invalid transferType received")
|
||||
}
|
||||
req["type"] = transferType
|
||||
@@ -750,7 +750,7 @@ func (h *HUOBI) FOrder(ctx context.Context, contractCode currency.Pair, symbol,
|
||||
req["symbol"] = symbol
|
||||
}
|
||||
if contractType != "" {
|
||||
if !common.StringDataCompareInsensitive(validContractTypes, contractType) {
|
||||
if !common.StringSliceCompareInsensitive(validContractTypes, contractType) {
|
||||
return resp, errors.New("invalid contractType")
|
||||
}
|
||||
req["contract_type"] = contractType
|
||||
@@ -773,10 +773,10 @@ func (h *HUOBI) FOrder(ctx context.Context, contractCode currency.Pair, symbol,
|
||||
req["client_order_id"] = id
|
||||
}
|
||||
req["direction"] = direction
|
||||
if !common.StringDataCompareInsensitive(validOffsetTypes, offset) {
|
||||
if !common.StringSliceCompareInsensitive(validOffsetTypes, offset) {
|
||||
return resp, errors.New("invalid offset amounts")
|
||||
}
|
||||
if !common.StringDataCompareInsensitive(validFuturesOrderPriceTypes, orderPriceType) {
|
||||
if !common.StringSliceCompareInsensitive(validFuturesOrderPriceTypes, orderPriceType) {
|
||||
return resp, errors.New("invalid orderPriceType")
|
||||
}
|
||||
req["order_price_type"] = orderPriceType
|
||||
@@ -807,14 +807,14 @@ func (h *HUOBI) FPlaceBatchOrder(ctx context.Context, data []fBatchOrderData) (F
|
||||
data[x].ContractCode = formattedPair.String()
|
||||
}
|
||||
if data[x].ContractType != "" {
|
||||
if !common.StringDataCompareInsensitive(validContractTypes, data[x].ContractType) {
|
||||
if !common.StringSliceCompareInsensitive(validContractTypes, data[x].ContractType) {
|
||||
return resp, errors.New("invalid contractType")
|
||||
}
|
||||
}
|
||||
if !common.StringDataCompareInsensitive(validOffsetTypes, data[x].Offset) {
|
||||
if !common.StringSliceCompareInsensitive(validOffsetTypes, data[x].Offset) {
|
||||
return resp, errors.New("invalid offset amounts")
|
||||
}
|
||||
if !common.StringDataCompareInsensitive(validFuturesOrderPriceTypes, data[x].OrderPriceType) {
|
||||
if !common.StringSliceCompareInsensitive(validFuturesOrderPriceTypes, data[x].OrderPriceType) {
|
||||
return resp, errors.New("invalid orderPriceType")
|
||||
}
|
||||
}
|
||||
@@ -847,7 +847,7 @@ func (h *HUOBI) FCancelAllOrders(ctx context.Context, contractCode currency.Pair
|
||||
req["symbol"] = symbol
|
||||
}
|
||||
if contractType != "" {
|
||||
if !common.StringDataCompareInsensitive(validContractTypes, contractType) {
|
||||
if !common.StringSliceCompareInsensitive(validContractTypes, contractType) {
|
||||
return resp, errors.New("invalid contractType")
|
||||
}
|
||||
req["contract_type"] = contractType
|
||||
@@ -868,7 +868,7 @@ func (h *HUOBI) FFlashCloseOrder(ctx context.Context, contractCode currency.Pair
|
||||
req := make(map[string]interface{})
|
||||
req["symbol"] = symbol
|
||||
if contractType != "" {
|
||||
if !common.StringDataCompareInsensitive(validContractTypes, contractType) {
|
||||
if !common.StringSliceCompareInsensitive(validContractTypes, contractType) {
|
||||
return resp, errors.New("invalid contractType")
|
||||
}
|
||||
req["contract_type"] = contractType
|
||||
@@ -886,7 +886,7 @@ func (h *HUOBI) FFlashCloseOrder(ctx context.Context, contractCode currency.Pair
|
||||
req["client_order_id"] = clientOrderID
|
||||
}
|
||||
if orderPriceType != "" {
|
||||
if !common.StringDataCompareInsensitive(validOPTypes, orderPriceType) {
|
||||
if !common.StringSliceCompareInsensitive(validOPTypes, orderPriceType) {
|
||||
return resp, errors.New("invalid orderPriceType")
|
||||
}
|
||||
req["orderPriceType"] = orderPriceType
|
||||
@@ -1040,7 +1040,7 @@ func (h *HUOBI) FPlaceTriggerOrder(ctx context.Context, contractCode currency.Pa
|
||||
req["symbol"] = symbol
|
||||
}
|
||||
if contractType != "" {
|
||||
if !common.StringDataCompareInsensitive(validContractTypes, contractType) {
|
||||
if !common.StringSliceCompareInsensitive(validContractTypes, contractType) {
|
||||
return resp, fmt.Errorf("invalid contractType: %s", contractType)
|
||||
}
|
||||
req["contract_type"] = contractType
|
||||
@@ -1058,7 +1058,7 @@ func (h *HUOBI) FPlaceTriggerOrder(ctx context.Context, contractCode currency.Pa
|
||||
}
|
||||
req["trigger_type"] = tType
|
||||
req["direction"] = direction
|
||||
if !common.StringDataCompareInsensitive(validOffsetTypes, offset) {
|
||||
if !common.StringSliceCompareInsensitive(validOffsetTypes, offset) {
|
||||
return resp, errors.New("invalid offset")
|
||||
}
|
||||
req["offset"] = offset
|
||||
@@ -1066,7 +1066,7 @@ func (h *HUOBI) FPlaceTriggerOrder(ctx context.Context, contractCode currency.Pa
|
||||
req["volume"] = volume
|
||||
req["lever_rate"] = leverageRate
|
||||
req["order_price"] = orderPrice
|
||||
if !common.StringDataCompareInsensitive(validOrderPriceType, orderPriceType) {
|
||||
if !common.StringSliceCompareInsensitive(validOrderPriceType, orderPriceType) {
|
||||
return resp, errors.New("invalid order price type")
|
||||
}
|
||||
req["order_price_type"] = orderPriceType
|
||||
@@ -1095,7 +1095,7 @@ func (h *HUOBI) FCancelAllTriggerOrders(ctx context.Context, contractCode curren
|
||||
req["contract_code"] = codeValue
|
||||
}
|
||||
if contractType != "" {
|
||||
if !common.StringDataCompareInsensitive(validContractTypes, contractType) {
|
||||
if !common.StringSliceCompareInsensitive(validContractTypes, contractType) {
|
||||
return resp, nil
|
||||
}
|
||||
req["contract_type"] = contractType
|
||||
@@ -1256,7 +1256,7 @@ func (h *HUOBI) formatFuturesCode(p currency.Code) (string, error) {
|
||||
|
||||
// formatFuturesPair handles pairs in the format as "BTC-NW" and "BTC210827"
|
||||
func (h *HUOBI) formatFuturesPair(p currency.Pair, convertQuoteToExpiry bool) (string, error) {
|
||||
if common.StringDataCompareInsensitive(validContractShortTypes, p.Quote.String()) {
|
||||
if common.StringSliceCompareInsensitive(validContractShortTypes, p.Quote.String()) {
|
||||
if convertQuoteToExpiry {
|
||||
cp, err := h.convertContractShortHandToExpiry(p, time.Now())
|
||||
if err != nil {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -117,7 +118,7 @@ func (k *Kraken) FuturesBatchOrder(ctx context.Context, data []PlaceBatchOrderDa
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if !common.StringDataCompare(validBatchOrderType, data[x].PlaceOrderType) {
|
||||
if !slices.Contains(validBatchOrderType, data[x].PlaceOrderType) {
|
||||
return resp, fmt.Errorf("%s %w",
|
||||
data[x].PlaceOrderType,
|
||||
errInvalidBatchOrderType)
|
||||
@@ -175,12 +176,12 @@ func (k *Kraken) FuturesSendOrder(ctx context.Context, orderType order.Type, sym
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
if !common.StringDataCompare(validSide, side) {
|
||||
if !slices.Contains(validSide, side) {
|
||||
return resp, errors.New("invalid side")
|
||||
}
|
||||
params.Set("side", side)
|
||||
if triggerSignal != "" {
|
||||
if !common.StringDataCompare(validTriggerSignal, triggerSignal) {
|
||||
if !slices.Contains(validTriggerSignal, triggerSignal) {
|
||||
return resp, errors.New("invalid triggerSignal")
|
||||
}
|
||||
params.Set("triggerSignal", triggerSignal)
|
||||
@@ -189,7 +190,7 @@ func (k *Kraken) FuturesSendOrder(ctx context.Context, orderType order.Type, sym
|
||||
params.Set("cliOrdId", clientOrderID)
|
||||
}
|
||||
if reduceOnly != "" {
|
||||
if !common.StringDataCompare(validReduceOnly, reduceOnly) {
|
||||
if !slices.Contains(validReduceOnly, reduceOnly) {
|
||||
return resp, errors.New("invalid reduceOnly")
|
||||
}
|
||||
params.Set("reduceOnly", reduceOnly)
|
||||
|
||||
@@ -1215,7 +1215,7 @@ channels:
|
||||
for _, p := range channelsToSubscribe[i].Pairs {
|
||||
outbound.Pairs = append(outbound.Pairs, p.String())
|
||||
}
|
||||
if common.StringDataContains(authenticatedChannels, channelsToSubscribe[i].Channel) {
|
||||
if common.StringSliceContains(authenticatedChannels, channelsToSubscribe[i].Channel) {
|
||||
outbound.Subscription.Token = authToken
|
||||
}
|
||||
|
||||
@@ -1227,7 +1227,7 @@ channels:
|
||||
for _, subs := range subscriptions {
|
||||
for i := range *subs {
|
||||
var err error
|
||||
if common.StringDataContains(authenticatedChannels, (*subs)[i].Subscription.Name) {
|
||||
if common.StringSliceContains(authenticatedChannels, (*subs)[i].Subscription.Name) {
|
||||
_, err = k.Websocket.AuthConn.SendMessageReturnResponse(context.TODO(), (*subs)[i].RequestID, (*subs)[i])
|
||||
} else {
|
||||
_, err = k.Websocket.Conn.SendMessageReturnResponse(context.TODO(), (*subs)[i].RequestID, (*subs)[i])
|
||||
@@ -1261,7 +1261,7 @@ channels:
|
||||
}
|
||||
|
||||
var id int64
|
||||
if common.StringDataContains(authenticatedChannels, channelsToUnsubscribe[x].Channel) {
|
||||
if common.StringSliceContains(authenticatedChannels, channelsToUnsubscribe[x].Channel) {
|
||||
id = k.Websocket.AuthConn.GenerateMessageID(false)
|
||||
} else {
|
||||
id = k.Websocket.Conn.GenerateMessageID(false)
|
||||
@@ -1276,7 +1276,7 @@ channels:
|
||||
},
|
||||
RequestID: id,
|
||||
}
|
||||
if common.StringDataContains(authenticatedChannels, channelsToUnsubscribe[x].Channel) {
|
||||
if common.StringSliceContains(authenticatedChannels, channelsToUnsubscribe[x].Channel) {
|
||||
unsub.Subscription.Token = authToken
|
||||
}
|
||||
unsub.Channels = append(unsub.Channels, channelsToUnsubscribe[x])
|
||||
@@ -1286,7 +1286,7 @@ channels:
|
||||
var errs error
|
||||
for i := range unsubs {
|
||||
var err error
|
||||
if common.StringDataContains(authenticatedChannels, unsubs[i].Subscription.Name) {
|
||||
if common.StringSliceContains(authenticatedChannels, unsubs[i].Subscription.Name) {
|
||||
_, err = k.Websocket.AuthConn.SendMessageReturnResponse(context.TODO(), unsubs[i].RequestID, unsubs[i])
|
||||
} else {
|
||||
_, err = k.Websocket.Conn.SendMessageReturnResponse(context.TODO(), unsubs[i].RequestID, unsubs[i])
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -301,7 +302,7 @@ func (ku *Kucoin) GetKlines(ctx context.Context, pair, period string, start, end
|
||||
if period == "" {
|
||||
return nil, errors.New("period can not be empty")
|
||||
}
|
||||
if !common.StringDataContains(validPeriods, period) {
|
||||
if !slices.Contains(validPeriods, period) {
|
||||
return nil, errors.New("invalid period")
|
||||
}
|
||||
params.Set("type", period)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -332,7 +333,7 @@ func (ku *Kucoin) GetFuturesKline(ctx context.Context, granularity int64, symbol
|
||||
if granularity == 0 {
|
||||
return nil, errors.New("granularity can not be empty")
|
||||
}
|
||||
if !common.StringDataContains(validGranularity, strconv.FormatInt(granularity, 10)) {
|
||||
if !slices.Contains(validGranularity, strconv.FormatInt(granularity, 10)) {
|
||||
return nil, errors.New("invalid granularity")
|
||||
}
|
||||
params := url.Values{}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -776,7 +777,7 @@ func (p *Poloniex) GetDepositAddress(ctx context.Context, cryptocurrency currenc
|
||||
|
||||
address, ok = depositAddrs.Addresses[strings.ToUpper(targetCurrency)]
|
||||
if !ok {
|
||||
if len(coinParams.ChildChains) > 1 && chain != "" && !common.StringDataCompare(coinParams.ChildChains, targetCurrency) {
|
||||
if len(coinParams.ChildChains) > 1 && chain != "" && !slices.Contains(coinParams.ChildChains, targetCurrency) {
|
||||
// rather than assume, return an error
|
||||
return nil, fmt.Errorf("currency %s has %v chains available, one of these must be specified",
|
||||
cryptocurrency,
|
||||
|
||||
Reference in New Issue
Block a user