From a3c3858912d8365762899313f4811b15b03e941c Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Wed, 6 Nov 2024 14:13:54 +0700 Subject: [PATCH] fixup! Huobi: Add V2 websocket support --- exchanges/huobi/huobi_test.go | 67 ++++++++++-------------- exchanges/huobi/huobi_types.go | 2 +- exchanges/huobi/huobi_websocket.go | 1 + exchanges/huobi/testdata/wsMyTrades.json | 2 +- 4 files changed, 31 insertions(+), 41 deletions(-) diff --git a/exchanges/huobi/huobi_test.go b/exchanges/huobi/huobi_test.go index 9c6bf5a5405..0bf404013b2 100644 --- a/exchanges/huobi/huobi_test.go +++ b/exchanges/huobi/huobi_test.go @@ -1473,47 +1473,36 @@ func TestWsMyTrades(t *testing.T) { testexch.FixtureToDataHandler(t, "testdata/wsMyTrades.json", h.wsHandleData) close(h.Websocket.DataHandler) require.Len(t, h.Websocket.DataHandler, 1, "Should see correct number of records") - exp := []*order.Detail{ - { - Exchange: h.Name, - Pair: btcusdtPair, - Side: order.Buy, - Status: order.Rejected, - ClientOrderID: "test1", - AssetType: asset.Spot, - LastUpdated: time.Unix(1583853365586*1000, 0), - }, - { - Exchange: h.Name, - Pair: btcusdtPair, - Side: order.Buy, - Status: order.Cancelled, - ClientOrderID: "test2", - AssetType: asset.Spot, - LastUpdated: time.Unix(1583853365586*1000, 0), - }, - { - Exchange: h.Name, - Pair: btcusdtPair, - Side: order.Sell, - Status: order.New, - ClientOrderID: "test3", - AssetType: asset.Spot, - Price: 77, - Amount: 2, - Type: order.Limit, - OrderID: "27163533", - LastUpdated: time.Unix(1583853365586*1000, 0), + m := <-h.Websocket.DataHandler + exp := &order.Detail{ + Exchange: h.Name, + Pair: btcusdtPair, + Side: order.Buy, + Status: order.PartiallyFilled, + ClientOrderID: "a001", + OrderID: "99998888", + AssetType: asset.Spot, + Date: time.Unix(1583853365586000, 0), + LastUpdated: time.Unix(1583853365996000, 0), + Price: 10000, + Amount: 1, + Trades: []order.TradeHistory{ + { + Price: 9999.99, + Amount: 0.96, + Fee: 19.88, + Exchange: h.Name, + TID: "919219323232", + Side: order.Buy, + IsMaker: false, + Timestamp: time.Unix(1583853365996000, 0), + }, }, } - for _, e := range exp { - m := <-h.Websocket.DataHandler - require.IsType(t, &order.Detail{}, m, "Must get the correct type from DataHandler") - d, _ := m.(*order.Detail) - require.NotNil(t, d) - assert.Equal(t, e, d, "Order Detail should match") - } - t.Error("Test positive and negative fees") + require.IsType(t, &order.Detail{}, m, "Must get the correct type from DataHandler") + d, _ := m.(*order.Detail) + require.NotNil(t, d) + assert.Equal(t, exp, d, "Order Detail should match") } func TestStringToOrderStatus(t *testing.T) { diff --git a/exchanges/huobi/huobi_types.go b/exchanges/huobi/huobi_types.go index 9164f197bf3..2e1c7a2cfeb 100644 --- a/exchanges/huobi/huobi_types.go +++ b/exchanges/huobi/huobi_types.go @@ -958,7 +958,7 @@ type WsTradeUpdate struct { TradePrice float64 `json:"tradePrice,string"` TradeVolume float64 `json:"tradeVolume,string"` Side order.Side `json:"orderSide"` - OrderType string `json:"type"` + OrderType string `json:"orderType"` IsTaker bool `json:"aggressor"` TradeID int64 `json:"tradeId"` TradeTime int64 `json:"tradeTime"` diff --git a/exchanges/huobi/huobi_websocket.go b/exchanges/huobi/huobi_websocket.go index b9be4e6a287..ab90b2ca67e 100644 --- a/exchanges/huobi/huobi_websocket.go +++ b/exchanges/huobi/huobi_websocket.go @@ -427,6 +427,7 @@ func (h *HUOBI) wsHandleMyTradesMsg(s *subscription.Subscription, respRaw []byte AssetType: s.Asset, Pair: s.Pairs[0], Date: time.Unix(t.OrderCreateTime*1000, 0), + LastUpdated: time.Unix(t.TradeTime*1000, 0), OrderID: strconv.FormatInt(t.OrderID, 10), } var err error diff --git a/exchanges/huobi/testdata/wsMyTrades.json b/exchanges/huobi/testdata/wsMyTrades.json index 7866638730f..4bb712679ba 100644 --- a/exchanges/huobi/testdata/wsMyTrades.json +++ b/exchanges/huobi/testdata/wsMyTrades.json @@ -1 +1 @@ -{"ch":"trade.clearing#btcusdt#1","data":{"eventType":"trade","symbol":"btcusdt","orderId":99998888,"tradePrice":"9999.99","tradeVolume":"0.96","orderSide":"buy","aggressor":true,"tradeId":919219323232,"tradeTime":998787897878,"transactFee":"19.88","feeDeduct ":"0","feeDeductType":"","feeCurrency":"btc","accountId":9912791,"source":"spot-api","orderPrice":"10000","orderSize":"1","clientOrderId":"a001","orderCreateTime":998787897878,"orderStatus":"partial-filled"}} +{"ch":"trade.clearing#btcusdt#1","data":{"eventType":"trade","symbol":"btcusdt","orderId":99998888,"tradePrice":"9999.99","tradeVolume":"0.96","orderSide":"buy","aggressor":true,"tradeId":919219323232,"tradeTime":1583853365996,"transactFee":"19.88","feeDeduct ":"0","feeDeductType":"","feeCurrency":"btc","accountId":9912791,"source":"spot-api","orderPrice":"10000","orderSize":"1","clientOrderId":"a001","orderCreateTime":1583853365586,"orderStatus":"partial-filled"}}