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

@@ -67,21 +67,6 @@ func getTime() (start, end time.Time) {
return tn.Add(-offset), tn
}
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 TestUServerTime(t *testing.T) {
t.Parallel()
_, err := b.UServerTime(context.Background())

View File

@@ -7,7 +7,6 @@ import (
"sort"
"strconv"
"strings"
"sync"
"time"
"github.com/shopspring/decimal"
@@ -288,100 +287,6 @@ func (b *Binance) Setup(exch *config.Exchange) error {
})
}
// Start starts the Binance go routine
func (b *Binance) Start(ctx context.Context, wg *sync.WaitGroup) error {
if wg == nil {
return fmt.Errorf("%T %w", wg, common.ErrNilPointer)
}
wg.Add(1)
go func() {
b.Run(ctx)
wg.Done()
}()
return nil
}
// Run implements the Binance wrapper
func (b *Binance) Run(ctx context.Context) {
if b.Verbose {
log.Debugf(log.ExchangeSys,
"%s Websocket: %s. (url: %s).\n",
b.Name,
common.IsEnabled(b.Websocket.IsEnabled()),
b.Websocket.GetWebsocketURL())
b.PrintEnabledPairs()
}
forceUpdate := false
a := b.GetAssetTypes(true)
for x := range a {
if err := b.UpdateOrderExecutionLimits(ctx, a[x]); err != nil {
log.Errorf(log.ExchangeSys,
"%s failed to set exchange order execution limits. Err: %v",
b.Name,
err)
}
if a[x] == asset.USDTMarginedFutures && !b.BypassConfigFormatUpgrades {
format, err := b.GetPairFormat(asset.USDTMarginedFutures, false)
if err != nil {
log.Errorf(log.ExchangeSys, "%s failed to get enabled currencies. Err %s\n",
b.Name,
err)
return
}
var enabled, avail currency.Pairs
enabled, err = b.CurrencyPairs.GetPairs(asset.USDTMarginedFutures, true)
if err != nil {
log.Errorf(log.ExchangeSys, "%s failed to get enabled currencies. Err %s\n",
b.Name,
err)
return
}
avail, err = b.CurrencyPairs.GetPairs(asset.USDTMarginedFutures, false)
if err != nil {
log.Errorf(log.ExchangeSys, "%s failed to get available currencies. Err %s\n",
b.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.USDT.String(),
})
if err != nil {
log.Errorf(log.ExchangeSys, "%s failed to update currencies. Err %s\n",
b.Name,
err)
} else {
log.Warnf(log.ExchangeSys, exchange.ResetConfigPairsWarningMessage, b.Name, a[x], enabledPairs)
forceUpdate = true
err = b.UpdatePairs(enabledPairs, a[x], true, true)
if err != nil {
log.Errorf(log.ExchangeSys,
"%s failed to update currencies. Err: %s\n",
b.Name,
err)
}
}
}
}
}
if !b.GetEnabledFeatures().AutoPairUpdates && !forceUpdate {
return
}
if err := b.UpdateTradablePairs(ctx, forceUpdate); err != nil {
log.Errorf(log.ExchangeSys,
"%s failed to update tradable pairs. Err: %s",
b.Name,
err)
}
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (b *Binance) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
if !b.SupportsAsset(a) {