From 3eb15db75c91a2414585b16f2d3a57b13162c61b Mon Sep 17 00:00:00 2001 From: Samuel Reid <43227667+cranktakular@users.noreply.github.com> Date: Tue, 5 Nov 2024 12:03:07 +1100 Subject: [PATCH] Template patch testing --- exchanges/coinbasepro/coinbasepro_test.go | 9 ++++---- .../coinbasepro/coinbasepro_websocket.go | 12 +++++------ exchanges/subscription/template.go | 21 +++++++++++++------ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/exchanges/coinbasepro/coinbasepro_test.go b/exchanges/coinbasepro/coinbasepro_test.go index 71ff5a09ab3..7bbe985e1e2 100644 --- a/exchanges/coinbasepro/coinbasepro_test.go +++ b/exchanges/coinbasepro/coinbasepro_test.go @@ -1526,10 +1526,11 @@ func TestCancelPendingFuturesSweep(t *testing.T) { func TestWsAuth(t *testing.T) { t.Parallel() p := currency.Pairs{testPair} - for _, a := range c.GetAssetTypes(true) { - require.NoError(t, c.CurrencyPairs.StorePairs(a, p, false)) - require.NoError(t, c.CurrencyPairs.StorePairs(a, p, true)) - } + // This for loop will prevent an error if the template.go file isn't patched + // for _, a := range c.GetAssetTypes(true) { + // require.NoError(t, c.CurrencyPairs.StorePairs(a, p, false)) + // require.NoError(t, c.CurrencyPairs.StorePairs(a, p, true)) + // } if c.Websocket.IsEnabled() && !c.API.AuthenticatedWebsocketSupport || !sharedtestvalues.AreAPICredentialsSet(c) { t.Skip(stream.ErrWebsocketNotEnabled.Error()) } diff --git a/exchanges/coinbasepro/coinbasepro_websocket.go b/exchanges/coinbasepro/coinbasepro_websocket.go index 8c22a8270e7..e711f00bc37 100644 --- a/exchanges/coinbasepro/coinbasepro_websocket.go +++ b/exchanges/coinbasepro/coinbasepro_websocket.go @@ -54,11 +54,11 @@ var defaultSubscriptions = subscription.List{ // Subscriptions to status return an "authentication failure" error, despite the endpoint not being authenticated // and other authenticated channels working fine. {Enabled: false, Channel: "status"}, - {Enabled: true, Asset: asset.Spot, Channel: subscription.TickerChannel}, - {Enabled: true, Asset: asset.Spot, Channel: subscription.CandlesChannel}, - {Enabled: true, Asset: asset.Spot, Channel: subscription.AllTradesChannel}, - {Enabled: true, Asset: asset.Spot, Channel: subscription.OrderbookChannel}, - {Enabled: true, Channel: subscription.MyAccountChannel, Authenticated: true}, + {Enabled: false, Asset: asset.Spot, Channel: subscription.TickerChannel}, + {Enabled: false, Asset: asset.Spot, Channel: subscription.CandlesChannel}, + {Enabled: false, Asset: asset.Spot, Channel: subscription.AllTradesChannel}, + {Enabled: false, Asset: asset.Spot, Channel: subscription.OrderbookChannel}, + {Enabled: true, Asset: asset.All, Channel: subscription.MyAccountChannel, Authenticated: true}, {Enabled: false, Asset: asset.Spot, Channel: "ticker_batch"}, /* Not Implemented: {Enabled: false, Asset: asset.Spot, Channel: "futures_balance_summary", Authenticated: true}, @@ -523,7 +523,7 @@ func base64URLEncode(b []byte) string { func (c *CoinbasePro) checkSubscriptions() { for _, s := range c.Config.Features.Subscriptions { switch s.Channel { - case "heartbeat", "level2_batch", "matches": + case "level2_batch", "matches": c.Config.Features.Subscriptions = defaultSubscriptions.Clone() c.Features.Subscriptions = c.Config.Features.Subscriptions.Enabled() return diff --git a/exchanges/subscription/template.go b/exchanges/subscription/template.go index ae994f7919d..f10b4f30291 100644 --- a/exchanges/subscription/template.go +++ b/exchanges/subscription/template.go @@ -104,12 +104,12 @@ func expandTemplate(e iExchange, s *Subscription, ap assetPairs, assets asset.It subs := List{} - if len(s.Pairs) != 0 { - // We deliberately do not check Availability of sub Pairs because users have edge cases to subscribe to non-existent pairs - for a := range ap { - ap[a] = s.Pairs - } - } + // if len(s.Pairs) != 0 { + // // We deliberately do not check Availability of sub Pairs because users have edge cases to subscribe to non-existent pairs + // for a := range ap { + // ap[a] = s.Pairs + // } + // } switch s.Asset { case asset.All: @@ -125,6 +125,15 @@ func expandTemplate(e iExchange, s *Subscription, ap assetPairs, assets asset.It } } + if len(s.Pairs) != 0 { + for a, pairs := range subCtx.AssetPairs { + if err := pairs.ContainsAll(s.Pairs, true); err != nil { //nolint:govet // Shadow, or gocritic will complain sloppyReassign + return nil, err + } + subCtx.AssetPairs[a] = s.Pairs + } + } + buf := &bytes.Buffer{} if err := t.Execute(buf, subCtx); err != nil { //nolint:govet // Shadow, or gocritic will complain sloppyReassign return nil, err