Skip to content

Commit

Permalink
Template patch testing
Browse files Browse the repository at this point in the history
  • Loading branch information
cranktakular committed Nov 5, 2024
1 parent 3f6976c commit 3eb15db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
9 changes: 5 additions & 4 deletions exchanges/coinbasepro/coinbasepro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
12 changes: 6 additions & 6 deletions exchanges/coinbasepro/coinbasepro_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down
21 changes: 15 additions & 6 deletions exchanges/subscription/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 107 in exchanges/subscription/template.go

View workflow job for this annotation

GitHub Actions / lint

commentedOutCode: may want to remove commented-out code (gocritic)
// // 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:
Expand 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
Expand Down

0 comments on commit 3eb15db

Please sign in to comment.