diff --git a/exchanges/kraken/kraken_test.go b/exchanges/kraken/kraken_test.go index e00c9585836..34055219946 100644 --- a/exchanges/kraken/kraken_test.go +++ b/exchanges/kraken/kraken_test.go @@ -40,6 +40,8 @@ const ( canManipulateRealOrders = false ) +var btcusdPair = currency.NewPairWithDelimiter("XBT", "USD", "/") + // TestSetup setup func func TestMain(m *testing.M) { k.SetDefaults() @@ -1513,362 +1515,58 @@ func TestWsSubscriptionStatus(t *testing.T) { func TestWsTicker(t *testing.T) { t.Parallel() - pressXToJSON := []byte(`{ - "channelID": 1337, - "channelName": "ticker", - "event": "subscriptionStatus", - "pair": "XBT/EUR", - "status": "subscribed", - "subscription": { - "name": "ticker" - } - }`) + k.Websocket.AddSuccessfulSubscriptions(stream.ChannelSubscription{Asset: asset.Spot, Currency: btcusdPair, Channel: krakenWsTicker}) + pressXToJSON := []byte(`[2,{"a":["5525.40000",1,"1.000"],"b":["5525.10000",1,"1.000"],"c":["5525.10000","0.00398963"],"h":["5783.00000","5783.00000"],"l":["5505.00000","5505.00000"],"o":["5760.70000","5763.40000"],"p":["5631.44067","5653.78939"],"t":[11493,16267],"v":["2634.11501494","3591.17907851"]},"ticker","XBT/USD"]`) err := k.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } - pressXToJSON = []byte(`[ - 1337, - { - "a": [ - "5525.40000", - 1, - "1.000" - ], - "b": [ - "5525.10000", - 1, - "1.000" - ], - "c": [ - "5525.10000", - "0.00398963" - ], - "h": [ - "5783.00000", - "5783.00000" - ], - "l": [ - "5505.00000", - "5505.00000" - ], - "o": [ - "5760.70000", - "5763.40000" - ], - "p": [ - "5631.44067", - "5653.78939" - ], - "t": [ - 11493, - 16267 - ], - "v": [ - "2634.11501494", - "3591.17907851" - ] - }, - "ticker", - "XBT/USD" - ]`) - err = k.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } + assert.NoError(t, err, "handle WS Ticker should not error") } func TestWsOHLC(t *testing.T) { t.Parallel() - pressXToJSON := []byte(`{ - "channelID": 13337, - "channelName": "ohlc", - "event": "subscriptionStatus", - "pair": "XBT/EUR", - "status": "subscribed", - "subscription": { - "name": "ohlc" - } - }`) + k.Websocket.AddSuccessfulSubscriptions(stream.ChannelSubscription{stream.DefaultChannelKey{krakenWsOHLC + "-5", btcusdPair, asset.Spot}, krakenWsOHLC, btcusdPair, asset.Spot, nil}) + 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) - if err != nil { - t.Error(err) - } - pressXToJSON = []byte(`[ - 13337, - [ - "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) - if err != nil { - t.Error(err) - } + assert.NoError(t, err, "handle WS Candles should not error") } func TestWsTrade(t *testing.T) { t.Parallel() - pressXToJSON := []byte(`{ - "channelID": 133337, - "channelName": "trade", - "event": "subscriptionStatus", - "pair": "XBT/EUR", - "status": "subscribed", - "subscription": { - "name": "trade" - } - }`) + k.Websocket.AddSuccessfulSubscriptions(stream.ChannelSubscription{Asset: asset.Spot, Currency: btcusdPair, Channel: krakenWsTrade}) + pressXToJSON := []byte(`[2,[["5541.20000","0.15850568","1534614057.321597","s","l",""],["6060.00000","0.02455000","1534614057.324998","b","l",""]],"trade","XBT/USD"]`) err := k.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } - pressXToJSON = []byte(`[ - 133337, - [ - [ - "5541.20000", - "0.15850568", - "1534614057.321597", - "s", - "l", - "" - ], - [ - "6060.00000", - "0.02455000", - "1534614057.324998", - "b", - "l", - "" - ] - ], - "trade", - "XBT/USD" - ]`) - err = k.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } + assert.NoError(t, err, "handle WS Trades should not error") } func TestWsSpread(t *testing.T) { t.Parallel() - pressXToJSON := []byte(`{ - "channelID": 1333337, - "channelName": "spread", - "event": "subscriptionStatus", - "pair": "XBT/EUR", - "status": "subscribed", - "subscription": { - "name": "spread" - } - }`) + k.Websocket.AddSuccessfulSubscriptions(stream.ChannelSubscription{Asset: asset.Spot, Currency: btcusdPair, Channel: krakenWsSpread}) + pressXToJSON := []byte(`[2,["5698.40000","5700.00000","1542057299.545897","1.01234567","0.98765432"],"spread","XBT/USD"]`) err := k.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } - pressXToJSON = []byte(`[ - 1333337, - [ - "5698.40000", - "5700.00000", - "1542057299.545897", - "1.01234567", - "0.98765432" - ], - "spread", - "XBT/USD" - ]`) - err = k.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } + assert.NoError(t, err, "handle WS Spread should not error") } func TestWsOrdrbook(t *testing.T) { t.Parallel() - pressXToJSON := []byte(`{ - "channelID": 13333337, - "channelName": "book", - "event": "subscriptionStatus", - "pair": "XBT/USD", - "status": "subscribed", - "subscription": { - "name": "book" - } - }`) + k.Websocket.AddSuccessfulSubscriptions(stream.ChannelSubscription{ + Key: stream.DefaultChannelKey{krakenWsOrderbook + "-100", btcusdPair, asset.Spot}, + Channel: krakenWsOrderbook, + Currency: btcusdPair, + Asset: asset.Spot, + Params: map[string]any{ + ChannelOrderbookDepthKey: 100, + }, + }) + pressXToJSON := []byte(`[2,{"as":[["5541.30000","2.50700000","1534614248.123678"],["5541.80000","0.33000000","1534614098.345543"],["5542.70000","0.64700000","1534614244.654432"],["5544.30000","2.50700000","1534614248.123678"],["5545.80000","0.33000000","1534614098.345543"],["5546.70000","0.64700000","1534614244.654432"],["5547.70000","0.64700000","1534614244.654432"],["5548.30000","2.50700000","1534614248.123678"],["5549.80000","0.33000000","1534614098.345543"],["5550.70000","0.64700000","1534614244.654432"]],"bs":[["5541.20000","1.52900000","1534614248.765567"],["5539.90000","0.30000000","1534614241.769870"],["5539.50000","5.00000000","1534613831.243486"],["5538.20000","1.52900000","1534614248.765567"],["5537.90000","0.30000000","1534614241.769870"],["5536.50000","5.00000000","1534613831.243486"],["5535.20000","1.52900000","1534614248.765567"],["5534.90000","0.30000000","1534614241.769870"],["5533.50000","5.00000000","1534613831.243486"],["5532.50000","5.00000000","1534613831.243486"]]},"book-100","XBT/USD"]`) err := k.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } - pressXToJSON = []byte(`[ - 13333337, - { - "as": [ - [ - "5541.30000", - "2.50700000", - "1534614248.123678" - ], - [ - "5541.80000", - "0.33000000", - "1534614098.345543" - ], - [ - "5542.70000", - "0.64700000", - "1534614244.654432" - ], - [ - "5544.30000", - "2.50700000", - "1534614248.123678" - ], - [ - "5545.80000", - "0.33000000", - "1534614098.345543" - ], - [ - "5546.70000", - "0.64700000", - "1534614244.654432" - ], - [ - "5547.70000", - "0.64700000", - "1534614244.654432" - ], - [ - "5548.30000", - "2.50700000", - "1534614248.123678" - ], - [ - "5549.80000", - "0.33000000", - "1534614098.345543" - ], - [ - "5550.70000", - "0.64700000", - "1534614244.654432" - ] - ], - "bs": [ - [ - "5541.20000", - "1.52900000", - "1534614248.765567" - ], - [ - "5539.90000", - "0.30000000", - "1534614241.769870" - ], - [ - "5539.50000", - "5.00000000", - "1534613831.243486" - ], - [ - "5538.20000", - "1.52900000", - "1534614248.765567" - ], - [ - "5537.90000", - "0.30000000", - "1534614241.769870" - ], - [ - "5536.50000", - "5.00000000", - "1534613831.243486" - ], - [ - "5535.20000", - "1.52900000", - "1534614248.765567" - ], - [ - "5534.90000", - "0.30000000", - "1534614241.769870" - ], - [ - "5533.50000", - "5.00000000", - "1534613831.243486" - ], - [ - "5532.50000", - "5.00000000", - "1534613831.243486" - ] - ] - }, - "book-100", - "XBT/USD" - ]`) - err = k.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } - pressXToJSON = []byte(`[ - 13333337, - { - "a": [ - [ - "5541.30000", - "2.50700000", - "1534614248.456738" - ], - [ - "5542.50000", - "0.40100000", - "1534614248.456738" - ] - ], - "c": "4187525586" - }, - "book-10", - "XBT/USD" - ]`) + assert.NoError(t, err, "handle WS Orderbook full snapshot should not error") + + pressXToJSON = []byte(`[2,{"a":[["5541.30000","2.50700000","1534614248.456738"],["5542.50000","0.40100000","1534614248.456738"]],"c":"4187525586"},"book-100","XBT/USD"]`) err = k.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } - pressXToJSON = []byte(`[ - 13333337, - { - "b": [ - [ - "5541.30000", - "0.00000000", - "1534614335.345903" - ] - ], - "c": "4187525586" - }, - "book-10", - "XBT/USD" - ]`) + assert.NoError(t, err, "handle WS Orderbook partial update should not error") + + pressXToJSON = []byte(`[2,{"b":[["5541.30000","0.00000000","1534614335.345903"]],"c":"4187525586"},"book-100","XBT/USD"]`) err = k.wsHandleData(pressXToJSON) - if err != nil { - t.Error(err) - } + assert.NoError(t, err, "handle WS Orderbook partial update should not error") } func TestWsOwnTrades(t *testing.T) {