From c49bfbfb66abbe4f52904cd9d8813d0335ea2c59 Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Mon, 21 Oct 2024 10:30:16 +0700 Subject: [PATCH] Walking skeleton v0.5 --- exchanges/huobi/huobi_websocket.go | 60 ++++++++++++------------------ 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/exchanges/huobi/huobi_websocket.go b/exchanges/huobi/huobi_websocket.go index 656430ceacd..e0640cf1158 100644 --- a/exchanges/huobi/huobi_websocket.go +++ b/exchanges/huobi/huobi_websocket.go @@ -25,6 +25,7 @@ import ( "github.com/thrasher-corp/gocryptotrader/exchanges/request" "github.com/thrasher-corp/gocryptotrader/exchanges/stream" "github.com/thrasher-corp/gocryptotrader/exchanges/subscription" + "github.com/thrasher-corp/gocryptotrader/exchanges/ticker" "github.com/thrasher-corp/gocryptotrader/exchanges/trade" "github.com/thrasher-corp/gocryptotrader/log" ) @@ -288,10 +289,12 @@ func (h *HUOBI) wsHandleActionMsgs(action string, respRaw []byte) error { } func (h *HUOBI) wsHandleChannelMsgs(s *subscription.Subscription, respRaw []byte) error { - if len(s.Pairs) != 0 { + if len(s.Pairs) != 1 { return subscription.ErrNotSinglePair } switch s.Channel { + case subscription.TickerChannel: + return h.wsHandleTickerMsg(s, respRaw) case subscription.OrderbookChannel: return h.wsHandleOrderbookMsg(s, respRaw) case subscription.CandlesChannel: @@ -350,42 +353,25 @@ func (h *HUOBI) wsHandleAllTradesMsg(s *subscription.Subscription, respRaw []byt return trade.AddTradesToBuffer(h.Name, trades...) } -/* - case strings.Contains(msg.Channel, "detail"), - strings.Contains(msg.Rep, "detail"): - var wsTicker WsTick - err := json.Unmarshal(respRaw, &wsTicker) - if err != nil { - return err - } - var data []string - if wsTicker.Channel != "" { - data = strings.Split(wsTicker.Channel, ".") - } - if wsTicker.Rep != "" { - data = strings.Split(wsTicker.Rep, ".") - } - - var p currency.Pair - var a asset.Item - p, a, err = h.GetRequestFormattedPairAndAssetType(data[1]) - if err != nil { - return err - } - - h.Websocket.DataHandler <- &ticker.Price{ - ExchangeName: h.Name, - Open: wsTicker.Tick.Open, - Close: wsTicker.Tick.Close, - Volume: wsTicker.Tick.Amount, - QuoteVolume: wsTicker.Tick.Volume, - High: wsTicker.Tick.High, - Low: wsTicker.Tick.Low, - LastUpdated: time.UnixMilli(wsTicker.Timestamp), - AssetType: a, - Pair: p, - } -*/ +func (h *HUOBI) wsHandleTickerMsg(s *subscription.Subscription, respRaw []byte) error { + var wsTicker WsTick + if err := json.Unmarshal(respRaw, &wsTicker); err != nil { + return err + } + h.Websocket.DataHandler <- &ticker.Price{ + ExchangeName: h.Name, + Open: wsTicker.Tick.Open, + Close: wsTicker.Tick.Close, + Volume: wsTicker.Tick.Amount, + QuoteVolume: wsTicker.Tick.Volume, + High: wsTicker.Tick.High, + Low: wsTicker.Tick.Low, + LastUpdated: time.UnixMilli(wsTicker.Timestamp), + AssetType: s.Asset, + Pair: s.Pairs[0], + } + return nil +} func (h *HUOBI) wsHandleOrderbookMsg(s *subscription.Subscription, respRaw []byte) error { var update WsDepth