mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-03 07:26:45 +00:00
stream: force subscription store check as stop gap for wrapper side implementation (#1717)
* Add check for subscription store insertion and validation with tests * bybit: fix subscriptions * deribit: fix subscriptions * linter: fix * glorious/nits: add test for updateChannelSubscriptions RM GetChannelDifference method as its only used locally and Diff method can be accessed directly * glorious/nits: add to store in the loop; add correct formatting to template for edge case perps with settlement * spelling: fix * glorious/nit: silly billy * gk: nits * gk/nits: split PartitionByPresence into Contained and Missing * gk/nits: formatPerpetualPairWithSettlement -> formatChannelPair * stream/websocket: stop full websocket disconnect on Connect when encountering subscription specific error paths * stream/websocket: rm nil assignment * glorious: nits * gk: niterinos * Update exchanges/stream/websocket_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update exchanges/stream/websocket_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update exchanges/stream/websocket_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * thrasher: nits --------- Co-authored-by: shazbert <ryan.oharareid@thrasher.io> Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/subscription"
|
||||
"github.com/thrasher-corp/gocryptotrader/types"
|
||||
)
|
||||
|
||||
@@ -33,10 +34,11 @@ type Authenticate struct {
|
||||
|
||||
// SubscriptionArgument represents a subscription arguments.
|
||||
type SubscriptionArgument struct {
|
||||
auth bool `json:"-"`
|
||||
RequestID string `json:"req_id"`
|
||||
Operation string `json:"op"`
|
||||
Arguments []string `json:"args"`
|
||||
auth bool `json:"-"`
|
||||
RequestID string `json:"req_id"`
|
||||
Operation string `json:"op"`
|
||||
Arguments []string `json:"args"`
|
||||
associatedSubs subscription.List `json:"-"`
|
||||
}
|
||||
|
||||
// Fee holds fee information
|
||||
|
||||
@@ -167,30 +167,19 @@ func (by *Bybit) handleSubscriptions(operation string, subs subscription.List) (
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
chans := []string{}
|
||||
authChans := []string{}
|
||||
for _, s := range subs {
|
||||
if s.Authenticated {
|
||||
authChans = append(authChans, s.QualifiedChannel)
|
||||
} else {
|
||||
chans = append(chans, s.QualifiedChannel)
|
||||
|
||||
for _, list := range []subscription.List{subs.Public(), subs.Private()} {
|
||||
for _, b := range common.Batch(list, 10) {
|
||||
args = append(args, SubscriptionArgument{
|
||||
auth: b[0].Authenticated,
|
||||
Operation: operation,
|
||||
RequestID: strconv.FormatInt(by.Websocket.Conn.GenerateMessageID(false), 10),
|
||||
Arguments: b.QualifiedChannels(),
|
||||
associatedSubs: b,
|
||||
})
|
||||
}
|
||||
}
|
||||
for _, b := range common.Batch(chans, 10) {
|
||||
args = append(args, SubscriptionArgument{
|
||||
Operation: operation,
|
||||
RequestID: strconv.FormatInt(by.Websocket.Conn.GenerateMessageID(false), 10),
|
||||
Arguments: b,
|
||||
})
|
||||
}
|
||||
if len(authChans) != 0 {
|
||||
args = append(args, SubscriptionArgument{
|
||||
auth: true,
|
||||
Operation: operation,
|
||||
RequestID: strconv.FormatInt(by.Websocket.Conn.GenerateMessageID(false), 10),
|
||||
Arguments: authChans,
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -225,6 +214,22 @@ func (by *Bybit) handleSpotSubscription(operation string, channelsToSubscribe su
|
||||
if !resp.Success {
|
||||
return fmt.Errorf("%s with request ID %s msg: %s", resp.Operation, resp.RequestID, resp.RetMsg)
|
||||
}
|
||||
|
||||
var conn stream.Connection
|
||||
if payloads[a].auth {
|
||||
conn = by.Websocket.AuthConn
|
||||
} else {
|
||||
conn = by.Websocket.Conn
|
||||
}
|
||||
|
||||
if operation == "unsubscribe" {
|
||||
err = by.Websocket.RemoveSubscriptions(conn, payloads[a].associatedSubs...)
|
||||
} else {
|
||||
err = by.Websocket.AddSubscriptions(conn, payloads[a].associatedSubs...)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user