-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stream: force subscription store check as stop gap for wrapper side implementation #1717
base: master
Are you sure you want to change the base?
Changes from 1 commit
3e7fe77
457cba1
dc72434
5ce010d
6ec3204
fadf919
759e225
fcf1d23
7147815
7401285
102bfc1
1e3eeda
9d7f116
ba022ec
06380e0
aca87c3
6c6fb30
fed2ed6
db9bb58
d630bf2
196263c
5f855fe
68461c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -123,6 +123,8 @@ var ( | |||||
} | ||||||
) | ||||||
|
||||||
var errSubscriptionFailureDetected = errors.New("subscription failure detected") | ||||||
|
||||||
// WsConnect starts a new connection with the websocket API | ||||||
func (d *Deribit) WsConnect() error { | ||||||
if !d.Websocket.IsEnabled() || !d.IsEnabled() { | ||||||
|
@@ -779,6 +781,7 @@ func (d *Deribit) GetSubscriptionTemplate(_ *subscription.Subscription) (*templa | |||||
"channelName": channelName, | ||||||
"interval": channelInterval, | ||||||
"isSymbolChannel": isSymbolChannel, | ||||||
"fmt": formatPerpetualPairWithSettlement, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Don't think we can call this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It calls it against every pair, are you asking me to only call it against futures? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. But I think it's misleading that it's not really format for every pair, even if it's called for all of them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
}). | ||||||
Parse(subTplText) | ||||||
} | ||||||
|
@@ -805,18 +808,19 @@ func (d *Deribit) handleSubscription(method string, subs subscription.List) erro | |||||
if err != nil || len(subs) == 0 { | ||||||
return err | ||||||
} | ||||||
|
||||||
r := WsSubscriptionInput{ | ||||||
JSONRPCVersion: rpcVersion, | ||||||
ID: d.Websocket.Conn.GenerateMessageID(false), | ||||||
Method: method, | ||||||
Params: map[string][]string{ | ||||||
"channels": subs.QualifiedChannels(), | ||||||
}, | ||||||
Params: map[string][]string{"channels": subs.QualifiedChannels()}, | ||||||
} | ||||||
|
||||||
data, err := d.Websocket.Conn.SendMessageReturnResponse(context.TODO(), request.Unset, r.ID, r) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
var response wsSubscriptionResponse | ||||||
err = json.Unmarshal(data, &response) | ||||||
if err != nil { | ||||||
|
@@ -827,23 +831,23 @@ func (d *Deribit) handleSubscription(method string, subs subscription.List) erro | |||||
subAck[c] = true | ||||||
} | ||||||
if len(subAck) != len(subs) { | ||||||
err = common.ErrUnknownError | ||||||
err = errSubscriptionFailureDetected | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, this would be covering ... any subs that come back that we didn't expect, which won't be reported in the for range below? |
||||||
} | ||||||
for _, s := range subs { | ||||||
if _, ok := subAck[s.QualifiedChannel]; ok { | ||||||
err = common.AppendError(err, d.Websocket.AddSuccessfulSubscriptions(d.Websocket.Conn, s)) | ||||||
if strings.Contains(method, "subscribe") { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't tested yet, but "unsubscribe" contains the string "subscribe" and so both would likely fall in here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
err = common.AppendError(err, d.Websocket.AddSuccessfulSubscriptions(d.Websocket.Conn, s)) | ||||||
} else { | ||||||
err = common.AppendError(err, d.Websocket.RemoveSubscriptions(d.Websocket.Conn, s)) | ||||||
} | ||||||
} else { | ||||||
err = common.AppendError(err, errors.New(s.String())) | ||||||
err = common.AppendError(err, errors.New(s.String()+"failed to"+method)) | ||||||
gbjk marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
} | ||||||
if err != nil { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return err | ||||||
} | ||||||
|
||||||
if method == "unsubscribe" { | ||||||
return d.Websocket.RemoveSubscriptions(d.Websocket.Conn, subs...) | ||||||
} | ||||||
return d.Websocket.AddSubscriptions(d.Websocket.Conn, subs...) | ||||||
return nil | ||||||
} | ||||||
|
||||||
func getValidatedCurrencyCode(pair currency.Pair) string { | ||||||
|
@@ -906,11 +910,18 @@ func isSymbolChannel(s *subscription.Subscription) bool { | |||||
return false | ||||||
} | ||||||
|
||||||
func formatPerpetualPairWithSettlement(pair currency.Pair) string { | ||||||
if str := pair.Quote.String(); strings.Contains(str, "PERPETUAL") && strings.Contains(str, "-") { | ||||||
pair.Delimiter = "_" | ||||||
} | ||||||
return pair.String() | ||||||
} | ||||||
|
||||||
const subTplText = ` | ||||||
{{- if isSymbolChannel $.S -}} | ||||||
{{- range $asset, $pairs := $.AssetPairs }} | ||||||
{{- range $p := $pairs }} | ||||||
{{- channelName $.S -}} . {{- $p }} | ||||||
{{- channelName $.S -}} . {{- fmt $p }} | ||||||
{{- with $i := interval $.S -}} . {{- $i }}{{ end }} | ||||||
{{- $.PairSeparator }} | ||||||
{{- end }} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like it's
stream.ErrSubscriptionFailure
in disguise 🤠