Skip to content

Commit

Permalink
Subscriptions: Respect subscription Pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Jul 9, 2024
1 parent 74a4107 commit 06ba844
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions exchanges/subscription/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

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

View workflow job for this annotation

GitHub Actions / lint

shadow: declaration of "err" shadows declaration at line 90 (govet)
return nil, err
}
subCtx.AssetPairs[a] = s.Pairs
}
}

buf := &bytes.Buffer{}
if err := t.Execute(buf, subCtx); err != nil {

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

View workflow job for this annotation

GitHub Actions / lint

shadow: declaration of "err" shadows declaration at line 90 (govet)
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions exchanges/subscription/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
Expand All @@ -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{
Expand Down
7 changes: 7 additions & 0 deletions exchanges/subscription/testdata/subscriptions.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

0 comments on commit 06ba844

Please sign in to comment.