Skip to content

Commit

Permalink
fixup! Huobi: Add V2 websocket support
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Oct 30, 2024
1 parent 637e27a commit c299c40
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
45 changes: 28 additions & 17 deletions exchanges/huobi/huobi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
"github.com/thrasher-corp/gocryptotrader/exchanges/subscription"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
Expand Down Expand Up @@ -1294,25 +1295,35 @@ func TestQueryWithdrawQuota(t *testing.T) {
}
}

func TestWsKline(t *testing.T) {
func TestWsHandleData(t *testing.T) {
t.Parallel()
}

func TestWsCandles(t *testing.T) {
h := new(HUOBI) //nolint:govet // Intentional shadow to avoid future copy/paste mistakes
require.NoError(t, testexch.Setup(h), "Setup Instance must not error")
err := h.Websocket.AddSubscriptions(h.Websocket.Conn, &subscription.Subscription{Key: "market.btcusdt.kline.1min", Asset: asset.Spot, Pairs: currency.Pairs{btcusdtPair}, Channel: subscription.CandlesChannel})
require.NoError(t, err, "AddSubscriptions must not error")
pressXToJSON := []byte(`{
"ch": "market.btcusdt.kline.1min",
"ts": 1489474082831,
"tick": {
"id": 1489464480,
"amount": 0.0,
"count": 0,
"open": 7962.62,
"close": 7962.62,
"low": 7962.62,
"high": 7962.62,
"vol": 0.0
}
}`)
err = h.wsHandleData(pressXToJSON)
require.NoError(t, err)
testexch.FixtureToDataHandler(t, "testdata/wsCandles.json", h.wsHandleData)
close(h.Websocket.DataHandler)
require.Len(t, h.Websocket.DataHandler, 1, "Should see correct number of Candles")
cAny := <-h.Websocket.DataHandler
c, ok := cAny.(stream.KlineData)
require.True(t, ok, "Must get the correct type from DataHandler")
assert.NotEmpty(t, c.Timestamp, "Timestamp should not be empty")
exp := stream.KlineData{
Timestamp: time.UnixMilli(1489474082831),
Pair: btcusdtPair,
AssetType: asset.Spot,
Exchange: h.Name,
OpenPrice: 7962.62,
ClosePrice: 8014.56,
HighPrice: 14962.77,
LowPrice: 5110.14,
Volume: 4.4,
Interval: "0s",
}
assert.Equal(t, exp, c)
}

func TestWsKlineArray(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions exchanges/huobi/testdata/wsCandles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ch":"market.btcusdt.kline.1min","ts":1489474082831,"tick":{"id":1489464480,"amount":0,"count":0,"open":7962.62,"close":8014.56,"low":5110.14,"high":14962.77,"vol":4.4}}

0 comments on commit c299c40

Please sign in to comment.