mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 07:26:48 +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:
@@ -47,17 +47,18 @@ type State uint8
|
||||
|
||||
// Subscription container for streaming subscriptions
|
||||
type Subscription struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Key any `json:"-"`
|
||||
Channel string `json:"channel,omitempty"`
|
||||
Pairs currency.Pairs `json:"pairs,omitempty"`
|
||||
Asset asset.Item `json:"asset,omitempty"`
|
||||
Params map[string]any `json:"params,omitempty"`
|
||||
Interval kline.Interval `json:"interval,omitempty"`
|
||||
Levels int `json:"levels,omitempty"`
|
||||
Authenticated bool `json:"authenticated,omitempty"`
|
||||
state State
|
||||
m sync.RWMutex
|
||||
Enabled bool `json:"enabled"`
|
||||
Key any `json:"-"`
|
||||
Channel string `json:"channel,omitempty"`
|
||||
Pairs currency.Pairs `json:"pairs,omitempty"`
|
||||
Asset asset.Item `json:"asset,omitempty"`
|
||||
Params map[string]any `json:"params,omitempty"`
|
||||
Interval kline.Interval `json:"interval,omitempty"`
|
||||
Levels int `json:"levels,omitempty"`
|
||||
Authenticated bool `json:"authenticated,omitempty"`
|
||||
QualifiedChannel string `json:"-"`
|
||||
state State
|
||||
m sync.RWMutex
|
||||
}
|
||||
|
||||
// String implements Stringer, and aims to informatively and uniquely identify a subscription for errors and information
|
||||
@@ -122,20 +123,22 @@ func (s *Subscription) EnsureKeyed() any {
|
||||
|
||||
// Clone returns a copy of a subscription
|
||||
// Key is set to nil, because most Key types contain a pointer to the subscription, and because the clone isn't added to the store yet
|
||||
// QualifiedChannel is not copied because it's expected that the contributing fields will be changed
|
||||
// Users should allow a default key to be assigned on AddSubscription or can SetKey as necessary
|
||||
func (s *Subscription) Clone() *Subscription {
|
||||
s.m.RLock()
|
||||
c := &Subscription{
|
||||
Key: nil,
|
||||
Enabled: s.Enabled,
|
||||
Channel: s.Channel,
|
||||
Asset: s.Asset,
|
||||
Params: s.Params,
|
||||
Interval: s.Interval,
|
||||
Levels: s.Levels,
|
||||
Authenticated: s.Authenticated,
|
||||
state: s.state,
|
||||
Pairs: s.Pairs,
|
||||
Key: nil,
|
||||
Enabled: s.Enabled,
|
||||
Channel: s.Channel,
|
||||
Asset: s.Asset,
|
||||
Params: s.Params,
|
||||
Interval: s.Interval,
|
||||
Levels: s.Levels,
|
||||
Authenticated: s.Authenticated,
|
||||
state: s.state,
|
||||
Pairs: s.Pairs,
|
||||
QualifiedChannel: s.QualifiedChannel,
|
||||
}
|
||||
s.Pairs = slices.Clone(s.Pairs)
|
||||
s.Params = maps.Clone(s.Params)
|
||||
|
||||
Reference in New Issue
Block a user