mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-31 15:10:42 +00:00
exchange: upgrade UpdatePair method (#991)
* exchange: upgrade update pair * exchanges: Add enabled string matching and format handling if discrepency is found. * linter: fixes * bithumb: fix tests * BTSE: api change fix ordering * huobi: fix tests * gloriousnits: stage 1 * gloriousnits: stage 2 * currency: more nits * bitmex: add spot and process pairs before currency package call. * bitmex: finished correct orderbook matching and other implementations * linter: fix issue * currency: Fix linter * currency: segregate and protect pair store, update tests * currency/manager: clean code, rm log output * currency: Add store method and make sure formatting stays nil if not stored. * gct: check errors * engine/websocketroutineman: fix tests * bybit: fix duplication bug * huobi: fix test * btse: fix tests? * ob/buffer: fix tests * Update currency/manager.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * glorious: nits * glorious: nits strikes again. * exchange: add bypassConfigFormatUpgrades to stop formatting * GLORIOUS LINTER * Update exchanges/bithumb/bithumb_wrapper.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * glorious: nits * exchange: fix pair upgrade issue when duplications are in both avail and enabled pairs * linter: fix shadow dec * config: fix test * Update currency/pair_test.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
@@ -76,6 +76,7 @@ var (
|
||||
errShutdownNotAllowed = errors.New("shutting down this bot instance is not allowed via gRPC, please enable by command line flag --grpcshutdown or config.json field grpcAllowBotShutdown")
|
||||
errGRPCShutdownSignalIsNil = errors.New("cannot shutdown, gRPC shutdown channel is nil")
|
||||
errInvalidStrategy = errors.New("invalid strategy")
|
||||
errSpecificPairNotEnabled = errors.New("specified pair is not enabled")
|
||||
)
|
||||
|
||||
// RPCServer struct
|
||||
@@ -344,14 +345,21 @@ func (s *RPCServer) GetExchangeInfo(_ context.Context, r *gctrpc.GenericExchange
|
||||
resp.SupportedAssets = make(map[string]*gctrpc.PairsSupported)
|
||||
assets := exchCfg.CurrencyPairs.GetAssetTypes(false)
|
||||
for i := range assets {
|
||||
ps, err := exchCfg.CurrencyPairs.Get(assets[i])
|
||||
var enabled currency.Pairs
|
||||
enabled, err = exchCfg.CurrencyPairs.GetPairs(assets[i], true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var available currency.Pairs
|
||||
available, err = exchCfg.CurrencyPairs.GetPairs(assets[i], false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp.SupportedAssets[assets[i].String()] = &gctrpc.PairsSupported{
|
||||
EnabledPairs: ps.Enabled.Join(),
|
||||
AvailablePairs: ps.Available.Join(),
|
||||
EnabledPairs: enabled.Join(),
|
||||
AvailablePairs: available.Join(),
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
@@ -1970,14 +1978,21 @@ func (s *RPCServer) GetExchangePairs(_ context.Context, r *gctrpc.GetExchangePai
|
||||
continue
|
||||
}
|
||||
|
||||
ps, err := exchCfg.CurrencyPairs.Get(assetTypes[x])
|
||||
var enabled currency.Pairs
|
||||
enabled, err = exchCfg.CurrencyPairs.GetPairs(assetTypes[x], true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var available currency.Pairs
|
||||
available, err = exchCfg.CurrencyPairs.GetPairs(assetTypes[x], false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp.SupportedAssets[assetTypes[x].String()] = &gctrpc.PairsSupported{
|
||||
AvailablePairs: ps.Available.Join(),
|
||||
EnabledPairs: ps.Enabled.Join(),
|
||||
AvailablePairs: available.Join(),
|
||||
EnabledPairs: enabled.Join(),
|
||||
}
|
||||
}
|
||||
return &resp, nil
|
||||
@@ -2024,31 +2039,36 @@ func (s *RPCServer) SetExchangePair(_ context.Context, r *gctrpc.SetExchangePair
|
||||
}
|
||||
|
||||
if r.Enable {
|
||||
err = exchCfg.CurrencyPairs.EnablePair(a,
|
||||
p.Format(pairFmt.Delimiter, pairFmt.Uppercase))
|
||||
err = exchCfg.CurrencyPairs.EnablePair(a, p.Format(pairFmt))
|
||||
if err != nil {
|
||||
newErrors = append(newErrors, err)
|
||||
newErrors = append(newErrors, fmt.Errorf("%s %w", r.Pairs[i], err))
|
||||
continue
|
||||
}
|
||||
err = base.CurrencyPairs.EnablePair(a, p)
|
||||
if err != nil {
|
||||
newErrors = append(newErrors, err)
|
||||
newErrors = append(newErrors, fmt.Errorf("%s %w", r.Pairs[i], err))
|
||||
continue
|
||||
}
|
||||
pass = true
|
||||
continue
|
||||
}
|
||||
|
||||
err = exchCfg.CurrencyPairs.DisablePair(a,
|
||||
p.Format(pairFmt.Delimiter, pairFmt.Uppercase))
|
||||
err = exchCfg.CurrencyPairs.DisablePair(a, p.Format(pairFmt))
|
||||
if err != nil {
|
||||
newErrors = append(newErrors, err)
|
||||
continue
|
||||
if errors.Is(err, currency.ErrPairNotFound) {
|
||||
newErrors = append(newErrors, fmt.Errorf("%s %w", r.Pairs[i], errSpecificPairNotEnabled))
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = base.CurrencyPairs.DisablePair(a, p)
|
||||
if err != nil {
|
||||
newErrors = append(newErrors, err)
|
||||
continue
|
||||
if errors.Is(err, currency.ErrPairNotFound) {
|
||||
newErrors = append(newErrors, fmt.Errorf("%s %w", r.Pairs[i], errSpecificPairNotEnabled))
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
pass = true
|
||||
}
|
||||
@@ -2913,13 +2933,25 @@ func (s *RPCServer) SetAllExchangePairs(_ context.Context, r *gctrpc.SetExchange
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exchCfg.CurrencyPairs.StorePairs(assets[i], pairs, true)
|
||||
base.CurrencyPairs.StorePairs(assets[i], pairs, true)
|
||||
err = exchCfg.CurrencyPairs.StorePairs(assets[i], pairs, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = base.CurrencyPairs.StorePairs(assets[i], pairs, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for i := range assets {
|
||||
exchCfg.CurrencyPairs.StorePairs(assets[i], nil, true)
|
||||
base.CurrencyPairs.StorePairs(assets[i], nil, true)
|
||||
err = exchCfg.CurrencyPairs.StorePairs(assets[i], nil, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = base.CurrencyPairs.StorePairs(assets[i], nil, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user