Skip to content

Commit

Permalink
Kraken: Molify linter
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Sep 29, 2023
1 parent ee1a6d3 commit 7c715d3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
25 changes: 21 additions & 4 deletions exchanges/kraken/kraken_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ func TestWebsocketSubscribe(t *testing.T) {
err = k.Unsubscribe([]stream.ChannelSubscription{{Channel: krakenWsTicker, Currency: currency.NewPairWithDelimiter("DWARF", "WIZARD", "/"), Key: 1337}})
assert.ErrorIs(t, err, stream.ErrUnsubscribeFailure, "Simple failing Unsubscribe should error")
assert.ErrorContains(t, err, "Currency pair not supported DWARF/WIZARD", "Simple failing Unsubscribe should error")
assert.Len(t, k.Websocket.GetSubscriptions(), 3, "Should not have have removed any channels")
assert.Len(t, k.Websocket.GetSubscriptions(), 3, "Should not have removed any channels")

err = k.Unsubscribe([]stream.ChannelSubscription{
subs[1],
Expand Down Expand Up @@ -1527,7 +1527,16 @@ func TestWsTicker(t *testing.T) {

func TestWsOHLC(t *testing.T) {
t.Parallel()
k.Websocket.AddSuccessfulSubscriptions(stream.ChannelSubscription{stream.DefaultChannelKey{krakenWsOHLC + "-5", btcusdPair, asset.Spot}, krakenWsOHLC, btcusdPair, asset.Spot, nil})
k.Websocket.AddSuccessfulSubscriptions(stream.ChannelSubscription{
Key: stream.DefaultChannelKey{
Channel: krakenWsOHLC + "-5",
Currency: btcusdPair,
Asset: asset.Spot,
},
Channel: krakenWsOHLC,
Currency: btcusdPair,
Asset: asset.Spot,
})
pressXToJSON := []byte(`[2,["1542057314.748456","1542057360.435743","3586.70000","3586.70000","3586.60000","3586.60000","3586.68894","0.03373000",2],"ohlc-5","XBT/USD"]`)
err := k.wsHandleData(pressXToJSON)
assert.NoError(t, err, "handle WS Candles should not error")
Expand All @@ -1552,7 +1561,11 @@ func TestWsSpread(t *testing.T) {
func TestWsOrdrbook(t *testing.T) {
t.Parallel()
k.Websocket.AddSuccessfulSubscriptions(stream.ChannelSubscription{
Key: stream.DefaultChannelKey{krakenWsOrderbook + "-100", btcusdPair, asset.Spot},
Key: stream.DefaultChannelKey{
Channel: krakenWsOrderbook + "-100",
Currency: btcusdPair,
Asset: asset.Spot,
},
Channel: krakenWsOrderbook,
Currency: btcusdPair,
Asset: asset.Spot,
Expand Down Expand Up @@ -2036,7 +2049,11 @@ func TestWsOrderbookMax10Depth(t *testing.T) {
p, err := currency.NewPairFromString(c)
assert.NoErrorf(t, err, "NewPairFromString %s should not error", c)
k.Websocket.AddSuccessfulSubscriptions(stream.ChannelSubscription{
Key: stream.DefaultChannelKey{krakenWsOrderbook + "-10", p, asset.Spot},
Key: stream.DefaultChannelKey{
Channel: krakenWsOrderbook + "-10",
Currency: p,
Asset: asset.Spot,
},
Channel: krakenWsOrderbook,
Currency: p,
Asset: asset.Spot,
Expand Down
4 changes: 2 additions & 2 deletions exchanges/kraken/kraken_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,15 @@ type WithdrawStatusResponse struct {
Status string `json:"status"`
}

// WebsocketSubscribeReq
// WebsocketSubscribeRequest contains request data for Subscribing to channels
type WebsocketSubscribeRequest struct {
Event string `json:"event"` // "subscribe"
RequestID int64 `json:"reqid,omitempty"`
Pairs []string `json:"pair,omitempty"`
Subscription WebsocketSubscriptionData `json:"subscription,omitempty"`
}

// WebsocketUnsubscribeRequest handles WS unsubscribe events
// WebsocketUnsubscribeRequest contains request data for Unsubscribing from channels
type WebsocketUnsubscribeRequest struct {
Event string `json:"event"` // "unsubscribe"
RequestID int64 `json:"reqid,omitempty"`
Expand Down
10 changes: 5 additions & 5 deletions exchanges/kraken/kraken_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ func (k *Kraken) wsHandleData(respRaw []byte) error {
}
}

c := k.Websocket.GetSubscription(stream.DefaultChannelKey{channelName, wsPair, asset.Spot})
c := k.Websocket.GetSubscription(stream.DefaultChannelKey{Channel: channelName, Currency: wsPair, Asset: asset.Spot})
if c == nil {
return fmt.Errorf("Could not find subscription channel: %s %s %s", asset.Spot, channelName, wsPair)
return fmt.Errorf("could not find subscription channel: %s %s %s", asset.Spot, channelName, wsPair)
}

if err := k.wsReadDataResponse(c, dataResponse); err != nil {
Expand Down Expand Up @@ -1257,11 +1257,11 @@ func (k *Kraken) unsubscribeFromChan(c *stream.ChannelSubscription) error {
}

if c.Channel == krakenWsOrderbook {
if depth, err := depthFromChan(c); err != nil {
depth, err := depthFromChan(c)
if err != nil {
return fmt.Errorf("%w Channel: %s Pair: %s Error: %w", stream.ErrSubscriptionFailure, c.Channel, c.Currency, err)
} else {
r.Subscription.Depth = depth
}
r.Subscription.Depth = depth
}

if common.StringDataContains(authenticatedChannels, c.Channel) {
Expand Down

0 comments on commit 7c715d3

Please sign in to comment.