mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-31 07:26:44 +00:00
exchanges/websocket: Implement subscription configuration (#1394)
* Websockets: Move Subscription to its own package This allows the small type to be imported from both `config` and from `stream` without an import cycle, so we don't have to repeat ourselves * Subs: Renamed Currency to Pair This was being mis-used through much of the code, and since we're already touching everything, we might as well fix it * Websockets: Add Subscription configuration * Binance: Add subscription configuration * Kucoin: Subscription configuration * Simplify GenerateDefaultSubs * Improve TestGenSubs coverage * Test Candle Sub generation * Support Candle intervals * Full responsibility for formatting Channel name on GenerateDefaultSubs OR consumer of Subscribe * Simplify generatePayloads as a result * Fix test coverage of asset types in processMarketSnapshot * Exchanges: Abstract ParallelChanOp * Tests: Generic ws mock instances * Kucoin: Fix intermittent conflict in test currs Use isolated test instance for `TestGetOpenInterest`. `TestGetOpenInterest` would occassionally change pairs before GenerateDefault Subs.
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/subscription"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/trade"
|
||||
)
|
||||
@@ -167,9 +168,9 @@ func (b *Bithumb) wsHandleData(respRaw []byte) error {
|
||||
}
|
||||
|
||||
// GenerateSubscriptions generates the default subscription set
|
||||
func (b *Bithumb) GenerateSubscriptions() ([]stream.ChannelSubscription, error) {
|
||||
func (b *Bithumb) GenerateSubscriptions() ([]subscription.Subscription, error) {
|
||||
var channels = []string{"ticker", "transaction", "orderbookdepth"}
|
||||
var subscriptions []stream.ChannelSubscription
|
||||
var subscriptions []subscription.Subscription
|
||||
pairs, err := b.GetEnabledPairs(asset.Spot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -182,10 +183,10 @@ func (b *Bithumb) GenerateSubscriptions() ([]stream.ChannelSubscription, error)
|
||||
|
||||
for x := range pairs {
|
||||
for y := range channels {
|
||||
subscriptions = append(subscriptions, stream.ChannelSubscription{
|
||||
Channel: channels[y],
|
||||
Currency: pairs[x].Format(pFmt),
|
||||
Asset: asset.Spot,
|
||||
subscriptions = append(subscriptions, subscription.Subscription{
|
||||
Channel: channels[y],
|
||||
Pair: pairs[x].Format(pFmt),
|
||||
Asset: asset.Spot,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -193,7 +194,7 @@ func (b *Bithumb) GenerateSubscriptions() ([]stream.ChannelSubscription, error)
|
||||
}
|
||||
|
||||
// Subscribe subscribes to a set of channels
|
||||
func (b *Bithumb) Subscribe(channelsToSubscribe []stream.ChannelSubscription) error {
|
||||
func (b *Bithumb) Subscribe(channelsToSubscribe []subscription.Subscription) error {
|
||||
subs := make(map[string]*WsSubscribe)
|
||||
for i := range channelsToSubscribe {
|
||||
s, ok := subs[channelsToSubscribe[i].Channel]
|
||||
@@ -203,7 +204,7 @@ func (b *Bithumb) Subscribe(channelsToSubscribe []stream.ChannelSubscription) er
|
||||
}
|
||||
subs[channelsToSubscribe[i].Channel] = s
|
||||
}
|
||||
s.Symbols = append(s.Symbols, channelsToSubscribe[i].Currency)
|
||||
s.Symbols = append(s.Symbols, channelsToSubscribe[i].Pair)
|
||||
}
|
||||
|
||||
tSub, ok := subs["ticker"]
|
||||
|
||||
Reference in New Issue
Block a user