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:
Adrian Gallagher
2024-09-13 10:43:20 +10:00
committed by GitHub
parent 22cb0eb9b9
commit b8e836d74f
32 changed files with 201 additions and 370 deletions

View File

@@ -903,7 +903,7 @@ func (bot *Engine) SetupExchanges() error {
bot.dryRunParamInteraction("exchanges")
exchangesOverride = strings.Split(bot.Settings.Exchanges, ",")
for x := range exchangesOverride {
if !common.StringDataCompareInsensitive(exchange.Exchanges, exchangesOverride[x]) {
if !common.StringSliceCompareInsensitive(exchange.Exchanges, exchangesOverride[x]) {
return fmt.Errorf("exchange %s not found", exchangesOverride[x])
}
}

View File

@@ -4,13 +4,13 @@ import (
"context"
"errors"
"os"
"slices"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/config"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/bitfinex"
@@ -372,11 +372,11 @@ func TestGetDefaultConfigurations(t *testing.T) {
t.Fatal(err)
}
if isCITest() && common.StringDataContains(blockedCIExchanges, name) {
if isCITest() && slices.Contains(blockedCIExchanges, name) {
t.Skipf("skipping %s due to CI test restrictions", name)
}
if common.StringDataContains(unsupportedDefaultConfigExchanges, name) {
if slices.Contains(unsupportedDefaultConfigExchanges, name) {
t.Skipf("skipping %s unsupported", name)
}

View File

@@ -753,7 +753,7 @@ func (bot *Engine) GetAllExchangeCryptocurrencyDepositAddresses() map[string]map
}
if len(availChains) > 0 {
// store the default non-chain specified address for a specified crypto
chainContainsItself := common.StringDataCompareInsensitive(availChains, cryptocurrency)
chainContainsItself := common.StringSliceCompareInsensitive(availChains, cryptocurrency)
if !chainContainsItself && !requiresChainSet {
depositAddr, err := exch.GetDepositAddress(context.TODO(), currency.NewCode(cryptocurrency), "", "")
if err != nil {

View File

@@ -13,12 +13,12 @@ import (
"net"
"os"
"path/filepath"
"slices"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/communications"
@@ -733,14 +733,14 @@ func TestGetExchangeNamesByCurrency(t *testing.T) {
result := e.GetExchangeNamesByCurrency(btsusd,
true,
assetType)
if !common.StringDataCompare(result, testExchange) {
if !slices.Contains(result, testExchange) {
t.Fatal("Unexpected result")
}
result = e.GetExchangeNamesByCurrency(btcjpy,
true,
assetType)
if !common.StringDataCompare(result, bf) {
if !slices.Contains(result, bf) {
t.Fatal("Unexpected result")
}
@@ -1176,7 +1176,7 @@ func TestGetExchangeNames(t *testing.T) {
if err := bot.UnloadExchange(testExchange); err != nil {
t.Fatal(err)
}
if e := bot.GetExchangeNames(true); common.StringDataCompare(e, testExchange) {
if e := bot.GetExchangeNames(true); slices.Contains(e, testExchange) {
t.Error("Bitstamp should be missing")
}
if e := bot.GetExchangeNames(false); len(e) != 0 {
@@ -1378,10 +1378,10 @@ func TestNewExchangeByNameWithDefaults(t *testing.T) {
name := exchange.Exchanges[x]
t.Run(name, func(t *testing.T) {
t.Parallel()
if isCITest() && common.StringDataContains(blockedCIExchanges, name) {
if isCITest() && slices.Contains(blockedCIExchanges, name) {
t.Skipf("skipping %s due to CI test restrictions", name)
}
if common.StringDataContains(unsupportedDefaultConfigExchanges, name) {
if slices.Contains(unsupportedDefaultConfigExchanges, name) {
t.Skipf("skipping %s unsupported", name)
}
exch, err := NewExchangeByNameWithDefaults(context.Background(), name)

View File

@@ -375,7 +375,7 @@ func (m *OrderManager) validate(exch exchange.IBotExchange, newOrder *order.Subm
}
if len(m.cfg.AllowedExchanges) > 0 &&
!common.StringDataCompareInsensitive(m.cfg.AllowedExchanges, newOrder.Exchange) {
!common.StringSliceCompareInsensitive(m.cfg.AllowedExchanges, newOrder.Exchange) {
return errors.New("order exchange not found in allowed list")
}