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:
Gareth Kirwan
2024-01-31 09:29:36 +01:00
committed by GitHub
parent 682737f368
commit d7818ea956
64 changed files with 379 additions and 2176 deletions

View File

@@ -5,13 +5,11 @@ import (
"encoding/json"
"errors"
"fmt"
"sync"
"testing"
"time"
"github.com/gofrs/uuid"
"github.com/stretchr/testify/assert"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/key"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
@@ -41,20 +39,6 @@ var (
spotTradablePair, usdcMarginedTradablePair, usdtMarginedTradablePair, inverseTradablePair, optionsTradablePair currency.Pair
)
func TestStart(t *testing.T) {
t.Parallel()
err := b.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 = b.Start(context.Background(), &testWg)
if err != nil {
t.Fatal(err)
}
testWg.Wait()
}
func TestGetInstrumentInfo(t *testing.T) {
t.Parallel()
_, err := b.GetInstrumentInfo(context.Background(), "spot", "", "", "", "", 0)

View File

@@ -6,7 +6,6 @@ import (
"fmt"
"sort"
"strings"
"sync"
"time"
"github.com/shopspring/decimal"
@@ -286,42 +285,6 @@ func (by *Bybit) AuthenticateWebsocket(ctx context.Context) error {
return by.WsAuth(ctx)
}
// Start starts the Bybit go routine
func (by *Bybit) Start(ctx context.Context, wg *sync.WaitGroup) error {
if wg == nil {
return fmt.Errorf("%T %w", wg, common.ErrNilPointer)
}
wg.Add(1)
go func() {
by.Run(ctx)
wg.Done()
}()
return nil
}
// Run implements the Bybit wrapper
func (by *Bybit) Run(ctx context.Context) {
if by.Verbose {
log.Debugf(log.ExchangeSys,
"%s Websocket: %s.",
by.Name,
common.IsEnabled(by.Websocket.IsEnabled()))
by.PrintEnabledPairs()
}
if !by.GetEnabledFeatures().AutoPairUpdates {
return
}
err := by.UpdateTradablePairs(ctx, false)
if err != nil {
log.Errorf(log.ExchangeSys,
"%s failed to update tradable pairs. Err: %s",
by.Name,
err)
}
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (by *Bybit) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
var pair currency.Pair