Skip to content

Commit

Permalink
Kraken: Test bad orderbook depth
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Sep 29, 2023
1 parent 05133e2 commit 99329a4
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions exchanges/kraken/kraken_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1340,20 +1340,33 @@ func TestWebsocketSubscribe(t *testing.T) {
func TestWsOrderbook(t *testing.T) {
setupWsTest(t)

c := []stream.ChannelSubscription{{
err := k.Subscribe([]stream.ChannelSubscription{{
Channel: krakenWsOrderbook,
Currency: currency.NewPairWithDelimiter("XBT", "USD", "/"),
Params: map[string]any{
ChannelOrderbookDepthKey: 25,
}}}

err := k.Subscribe(c)
}}})
assert.NoError(t, err, "Simple subscription should not error")
assert.Len(t, k.Websocket.GetSubscriptions(), 1, "Should add 1 Subscription")

err = k.Unsubscribe(c)
subs := k.Websocket.GetSubscriptions()
assert.Len(t, subs, 1, "Should have 1 subscription channel")
key, ok := subs[0].Key.(stream.DefaultChannelKey)
assert.True(t, ok, "Subscription key should be a DefaultChannelKey")
assert.Equal(t, "book-25", key.Channel, "Key Channel should be correct")

err = k.Unsubscribe(subs)
assert.NoError(t, err, "Unsubscribe should not error")
assert.Len(t, k.Websocket.GetSubscriptions(), 0, "Should have successfully removed all channels")

err = k.Subscribe([]stream.ChannelSubscription{{
Channel: krakenWsOrderbook,
Currency: currency.NewPairWithDelimiter("XBT", "USD", "/"),
Params: map[string]any{
ChannelOrderbookDepthKey: 42,
}}})
assert.ErrorIs(t, err, stream.ErrSubscriptionFailure, "Bad subscription should error")
assert.ErrorContains(t, err, "Subscription depth not supported", "Bad subscription should error about depth")
}

// TestWebsocketSubscribeAuth tests Auth's subscriptions
Expand Down

0 comments on commit 99329a4

Please sign in to comment.