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 Nov 6, 2024
1 parent 32382f6 commit a3c3858
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 41 deletions.
67 changes: 28 additions & 39 deletions exchanges/huobi/huobi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion exchanges/huobi/huobi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions exchanges/huobi/huobi_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion exchanges/huobi/testdata/wsMyTrades.json
Original file line number Diff line number Diff line change
@@ -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"}}

0 comments on commit a3c3858

Please sign in to comment.