mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-05 23:16:53 +00:00
Exchanges: Remove bespoke pair upgrade handling and abstract Start/Run (#1424)
* Exchanges: Remove Pair upgrade handling Now redundant behind #1401. These paths should never be met. Several legacy coin upgrade paths being deprecated as well: ZUSD and CNY Expecting any users with bad config from 3+ years ago would have to reset anyway. Also: At the time the intention of this was to upgrade the config format. However now, instead, it'd mostly serve to reset enabled pairs if there's a config mistake, which doesn't feel right. * Kraken: Fix typo in Kraken type struct * Exchanges: Abstract exchange Start() and Run() * Exchanges: Add test for abstracted Start * Exchanges: Move Start to Bootstrap * Simplify waitgroup usage * Add call to exchange.Bootstrap to allow overide or supplementation * Exchanges: Concurrent common bootstap actions * Gateio: Remove incorrect Run in test * GateIO: Fix pair dependencies in tests This ensures that the pairs are initialised no more than needed and kind-of just-in-time. Better pattern might be to use a function to get these pairs when we need them. * Exchanges: Complete UpdatePairs before ExecLims If we're going to update pairs, it needs to complete before we check for limits to avoid errors on old pairs * Exchanges: Remove Start and Run from tmpl Since they're replaced by bootstrap now and shouldn't need customisation normally * Alphapoint: Move Start to Bootstrap * GateIO: Fix linter shadow var
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -32,20 +31,6 @@ const testCurrency = "btcusd"
|
||||
|
||||
var g = &Gemini{}
|
||||
|
||||
func TestStart(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := g.Start(context.Background(), nil)
|
||||
if !errors.Is(err, common.ErrNilPointer) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, common.ErrNilPointer)
|
||||
}
|
||||
var testWg sync.WaitGroup
|
||||
err = g.Start(context.Background(), &testWg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testWg.Wait()
|
||||
}
|
||||
|
||||
func TestGetSymbols(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := g.GetSymbols(context.Background())
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
@@ -193,92 +192,6 @@ func (g *Gemini) Setup(exch *config.Exchange) error {
|
||||
})
|
||||
}
|
||||
|
||||
// Start starts the Gemini go routine
|
||||
func (g *Gemini) Start(ctx context.Context, wg *sync.WaitGroup) error {
|
||||
if wg == nil {
|
||||
return fmt.Errorf("%T %w", wg, common.ErrNilPointer)
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
g.Run(ctx)
|
||||
wg.Done()
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run implements the Gemini wrapper
|
||||
func (g *Gemini) Run(ctx context.Context) {
|
||||
if g.Verbose {
|
||||
g.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
forceUpdate := false
|
||||
if !g.BypassConfigFormatUpgrades {
|
||||
format, err := g.GetPairFormat(asset.Spot, false)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to get enabled currencies. Err %s\n",
|
||||
g.Name,
|
||||
err)
|
||||
return
|
||||
}
|
||||
|
||||
enabled, err := g.CurrencyPairs.GetPairs(asset.Spot, true)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to get enabled currencies. Err %s\n",
|
||||
g.Name,
|
||||
err)
|
||||
return
|
||||
}
|
||||
|
||||
avail, err := g.CurrencyPairs.GetPairs(asset.Spot, false)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to get available currencies. Err %s\n",
|
||||
g.Name,
|
||||
err)
|
||||
return
|
||||
}
|
||||
|
||||
if !common.StringDataContains(enabled.Strings(), format.Delimiter) ||
|
||||
!common.StringDataContains(avail.Strings(), format.Delimiter) {
|
||||
var enabledPairs currency.Pairs
|
||||
enabledPairs, err = currency.NewPairsFromStrings([]string{
|
||||
currency.BTC.String() + format.Delimiter + currency.USD.String()})
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update currencies. Err %s\n",
|
||||
g.Name,
|
||||
err)
|
||||
} else {
|
||||
log.Warnf(log.ExchangeSys, exchange.ResetConfigPairsWarningMessage, g.Name, asset.Spot, enabledPairs)
|
||||
forceUpdate = true
|
||||
|
||||
err = g.UpdatePairs(enabledPairs, asset.Spot, true, true)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update currencies. Err: %s\n",
|
||||
g.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := g.UpdateOrderExecutionLimits(ctx, asset.Spot); err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to set exchange order execution limits. Err: %v",
|
||||
g.Name,
|
||||
err)
|
||||
}
|
||||
if !g.GetEnabledFeatures().AutoPairUpdates && !forceUpdate {
|
||||
return
|
||||
}
|
||||
err := g.UpdateTradablePairs(ctx, forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s",
|
||||
g.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (g *Gemini) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
if !g.SupportsAsset(a) {
|
||||
|
||||
Reference in New Issue
Block a user