From 06ba8441b44115c2f34ccd20642ebb13ea20c739 Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Tue, 9 Jul 2024 15:26:19 +0700 Subject: [PATCH] Subscriptions: Respect subscription Pairs --- exchanges/subscription/template.go | 9 +++++++++ exchanges/subscription/template_test.go | 2 ++ exchanges/subscription/testdata/subscriptions.tmpl | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/exchanges/subscription/template.go b/exchanges/subscription/template.go index e223a18e6ed..bc722c1fa69 100644 --- a/exchanges/subscription/template.go +++ b/exchanges/subscription/template.go @@ -113,6 +113,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 { + return nil, err + } + subCtx.AssetPairs[a] = s.Pairs + } + } + buf := &bytes.Buffer{} if err := t.Execute(buf, subCtx); err != nil { return nil, err diff --git a/exchanges/subscription/template_test.go b/exchanges/subscription/template_test.go index 3c642cb8862..48856e2bd9d 100644 --- a/exchanges/subscription/template_test.go +++ b/exchanges/subscription/template_test.go @@ -35,6 +35,7 @@ func TestExpandTemplates(t *testing.T) { {Channel: "feature3", Asset: asset.All, Levels: 100}, {Channel: "feature1", QualifiedChannel: "just one sub already processed"}, {Channel: "feature5", Asset: asset.All}, + {Channel: "feature7", Asset: asset.Spot, Pairs: pairs[0:2]}, {Channel: "feature6", Asset: asset.Spot}, {Channel: "feature4", Authenticated: true}, } @@ -46,6 +47,7 @@ func TestExpandTemplates(t *testing.T) { {Channel: "feature2", QualifiedChannel: "future-feature2@15m", Asset: asset.Futures, Pairs: pairs, Interval: kline.FifteenMin}, {Channel: "feature1", QualifiedChannel: "just one sub already processed"}, {Channel: "feature5", QualifiedChannel: "spot-btcusdt-feature5", Asset: asset.Spot, Pairs: currency.Pairs{btcusdtPair}}, + {Channel: "feature7", QualifiedChannel: "spot-BTCUSDT,ETHUSDC-feature7", Asset: asset.Spot, Pairs: pairs[0:2]}, } for _, p := range pairs { exp = append(exp, List{ diff --git a/exchanges/subscription/testdata/subscriptions.tmpl b/exchanges/subscription/testdata/subscriptions.tmpl index b70ff2a13ef..81e5d4e6a24 100644 --- a/exchanges/subscription/testdata/subscriptions.tmpl +++ b/exchanges/subscription/testdata/subscriptions.tmpl @@ -37,4 +37,11 @@ {{- $.BatchSize -}} 3 {{- end }} {{- end -}} +{{- else if eq $.S.Channel "feature7" }} + {{/* Only pairs we expect */}} + {{- range $asset, $pairs := $.AssetPairs }} + {{- if eq $asset.String "spot" }} + {{ assetName $asset }}-{{ $pairs.Join -}} -feature7 + {{- end -}} + {{- end -}} {{- end -}}