Skip to content

Commit

Permalink
Walking skeleton v0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Oct 21, 2024
1 parent 0cdc431 commit c49bfbf
Showing 1 changed file with 23 additions and 37 deletions.
60 changes: 23 additions & 37 deletions exchanges/huobi/huobi_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c49bfbf

Please sign in to comment.