mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
subscriptions: Add templating support and integrate with Binance (#1568)
* Subscriptions: Add List.AssetPairs * Subscriptions: Add Template and QualifiedChannel These fields separate the concept of what the channel is from the qualified resource name * Subscriptions: Add List.SetStates() * Subscriptions: Add List.QualifiedChannels * Subscriptions: Rename testsubs.EqualLists * Binance: Switch to ExpandTemplates * Binance: Update ConfigTest format * Subscriptions: Test Coverage improvements * Subscriptions: Reenterant List.ExpandTemplates * Subscriptions: Move templates from subscriptions to exchanges * Binance: Inline subscription template and improvements
This commit is contained in:
38
cmd/documentation/exchanges_templates/subscription.tmpl
Normal file
38
cmd/documentation/exchanges_templates/subscription.tmpl
Normal file
@@ -0,0 +1,38 @@
|
||||
{{define "exchanges subscription" -}}
|
||||
{{template "header" .}}
|
||||
# Exchange Subscriptions
|
||||
|
||||
Exchange Subscriptions are streams of data delivered via websocket.
|
||||
|
||||
GoCryptoTrader engine will subscribe automatically to configured channels.
|
||||
A subset of exchanges currently support user configured channels, with the remaining using hardcoded defaults.
|
||||
See configuration Features.Subscriptions for whether an exchange is configurable.
|
||||
|
||||
## Templating
|
||||
|
||||
Exchange Contributors should implement `GetSubscriptionTemplate` to return a text/template Template.
|
||||
|
||||
Exchanges are free to implement template caching, a map or a mono-template, inline or file templates.
|
||||
|
||||
The template is provided with a single context structure:
|
||||
```go
|
||||
S *subscription.Subscription
|
||||
AssetPairs map[asset.Item]currency.Pairs
|
||||
AssetSeparator string
|
||||
PairSeparator string
|
||||
```
|
||||
|
||||
Subscriptions may fan out many channels for assets and pairs, to support exchanges which require individual subscriptions.
|
||||
To allow the template to communicate how to handle its output it should use the provided separators:
|
||||
- AssetSeparator should be added at the end of each section related to assets
|
||||
- PairSeparator should be added at the end of each pair
|
||||
|
||||
We use separators like this because it allows mono-templates to decide at runtime whether to fan out.
|
||||
|
||||
See exchanges/subscription/testdata/subscriptions.tmpl for an example mono-template showcasing various features
|
||||
|
||||
Templates do not need to worry about joining around separators; Trailing separators will be stripped automatically.
|
||||
|
||||
{{template "contributions"}}
|
||||
{{template "donations" .}}
|
||||
{{end}}
|
||||
Reference in New Issue
Block a user