Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
fix panic on close, create handler interface
Browse files Browse the repository at this point in the history
  • Loading branch information
larscom committed Apr 7, 2024
1 parent 7faafa3 commit d2307f2
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 103 deletions.
13 changes: 13 additions & 0 deletions ws/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ func (a *accountEventHandler) UnsubscribeAll() error {
return nil
}

func (a *accountEventHandler) handleMessage(e WsEvent, bytes []byte) {
switch e {
case wsEventAuth:
a.handleAuthMessage(bytes)
case wsEventOrder:
a.handleOrderMessage(bytes)
case wsEventFill:
a.handleFillMessage(bytes)
default:
log.Debug().Str("event", e.Value).Msg("no handler for this account event (should not happen)")
}
}

func (a *accountEventHandler) handleOrderMessage(bytes []byte) {
var orderEvent *OrderEvent
if err := json.Unmarshal(bytes, &orderEvent); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion ws/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (b *bookEventHandler) UnsubscribeAll() error {
return nil
}

func (b *bookEventHandler) handleMessage(bytes []byte) {
func (b *bookEventHandler) handleMessage(_ WsEvent, bytes []byte) {
var bookEvent *BookEvent
if err := json.Unmarshal(bytes, &bookEvent); err != nil {
log.Err(err).Str("message", string(bytes)).Msg("Couldn't unmarshal message into BookEvent")
Expand Down
2 changes: 1 addition & 1 deletion ws/candles.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (c *candlesEventHandler) UnsubscribeAll() error {
return nil
}

func (c *candlesEventHandler) handleMessage(bytes []byte) {
func (c *candlesEventHandler) handleMessage(_ WsEvent, bytes []byte) {
var candleEvent *CandlesEvent
if err := json.Unmarshal(bytes, &candleEvent); err != nil {
log.Err(err).Str("message", string(bytes)).Msg("Couldn't unmarshal message into CandlesEvent")
Expand Down
2 changes: 1 addition & 1 deletion ws/ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (t *tickerEventHandler) UnsubscribeAll() error {
return nil
}

func (t *tickerEventHandler) handleMessage(bytes []byte) {
func (t *tickerEventHandler) handleMessage(_ WsEvent, bytes []byte) {
var tickerEvent *TickerEvent
if err := json.Unmarshal(bytes, &tickerEvent); err != nil {
log.Err(err).Str("message", string(bytes)).Msg("Couldn't unmarshal message into TickerEvent")
Expand Down
2 changes: 1 addition & 1 deletion ws/ticker24h.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (t *ticker24hEventHandler) UnsubscribeAll() error {
return nil
}

func (t *ticker24hEventHandler) handleMessage(bytes []byte) {
func (t *ticker24hEventHandler) handleMessage(_ WsEvent, bytes []byte) {
var ticker24hEvent *Ticker24hEvent
if err := json.Unmarshal(bytes, &ticker24hEvent); err != nil {
log.Err(err).Str("message", string(bytes)).Msg("Couldn't unmarshal message into Ticker24hEvent")
Expand Down
2 changes: 1 addition & 1 deletion ws/trades.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (t *tradesEventHandler) UnsubscribeAll() error {
return nil
}

func (t *tradesEventHandler) handleMessage(bytes []byte) {
func (t *tradesEventHandler) handleMessage(_ WsEvent, bytes []byte) {
var tradeEvent *TradesEvent
if err := json.Unmarshal(bytes, &tradeEvent); err != nil {
log.Err(err).Str("message", string(bytes)).Msg("Couldn't unmarshal message into TradesEvent")
Expand Down
Loading

0 comments on commit d2307f2

Please sign in to comment.