mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 15:11:03 +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:
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/subscription"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/trade"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
)
|
||||
@@ -360,24 +361,24 @@ func (b *BTSE) orderbookFilter(price, amount float64) bool {
|
||||
}
|
||||
|
||||
// GenerateDefaultSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions()
|
||||
func (b *BTSE) GenerateDefaultSubscriptions() ([]stream.ChannelSubscription, error) {
|
||||
func (b *BTSE) GenerateDefaultSubscriptions() ([]subscription.Subscription, error) {
|
||||
var channels = []string{"orderBookL2Api:%s_0", "tradeHistory:%s"}
|
||||
pairs, err := b.GetEnabledPairs(asset.Spot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var subscriptions []stream.ChannelSubscription
|
||||
var subscriptions []subscription.Subscription
|
||||
if b.Websocket.CanUseAuthenticatedEndpoints() {
|
||||
subscriptions = append(subscriptions, stream.ChannelSubscription{
|
||||
subscriptions = append(subscriptions, subscription.Subscription{
|
||||
Channel: "notificationApi",
|
||||
})
|
||||
}
|
||||
for i := range channels {
|
||||
for j := range pairs {
|
||||
subscriptions = append(subscriptions, stream.ChannelSubscription{
|
||||
Channel: fmt.Sprintf(channels[i], pairs[j]),
|
||||
Currency: pairs[j],
|
||||
Asset: asset.Spot,
|
||||
subscriptions = append(subscriptions, subscription.Subscription{
|
||||
Channel: fmt.Sprintf(channels[i], pairs[j]),
|
||||
Pair: pairs[j],
|
||||
Asset: asset.Spot,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -385,7 +386,7 @@ func (b *BTSE) GenerateDefaultSubscriptions() ([]stream.ChannelSubscription, err
|
||||
}
|
||||
|
||||
// Subscribe sends a websocket message to receive data from the channel
|
||||
func (b *BTSE) Subscribe(channelsToSubscribe []stream.ChannelSubscription) error {
|
||||
func (b *BTSE) Subscribe(channelsToSubscribe []subscription.Subscription) error {
|
||||
var sub wsSub
|
||||
sub.Operation = "subscribe"
|
||||
for i := range channelsToSubscribe {
|
||||
@@ -400,7 +401,7 @@ func (b *BTSE) Subscribe(channelsToSubscribe []stream.ChannelSubscription) error
|
||||
}
|
||||
|
||||
// Unsubscribe sends a websocket message to stop receiving data from the channel
|
||||
func (b *BTSE) Unsubscribe(channelsToUnsubscribe []stream.ChannelSubscription) error {
|
||||
func (b *BTSE) Unsubscribe(channelsToUnsubscribe []subscription.Subscription) error {
|
||||
var unSub wsSub
|
||||
unSub.Operation = "unsubscribe"
|
||||
for i := range channelsToUnsubscribe {
|
||||
|
||||
Reference in New Issue
Block a user