Skip to content

Commit

Permalink
Kraken: Rename channelName var throughout
Browse files Browse the repository at this point in the history
Avoid shadowing func of same name
  • Loading branch information
gbjk committed Aug 14, 2024
1 parent 40b5611 commit 8b5c377
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions exchanges/kraken/kraken_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (k *Kraken) wsHandleData(respRaw []byte) error {
}

// For all types of channel second to last field is the channel Name
channelName, ok := msg[len(msg)-2].(string)
c, ok := msg[len(msg)-2].(string)
if !ok {
return common.GetTypeAssertError("string", msg[len(msg)-2], "channelName")
}
Expand All @@ -208,7 +208,7 @@ func (k *Kraken) wsHandleData(respRaw []byte) error {
return err
}
}
return k.wsReadDataResponse(channelName, pair, msg)
return k.wsReadDataResponse(c, pair, msg)
}

event, err := jsonparser.GetString(respRaw, "event")
Expand Down Expand Up @@ -256,8 +256,8 @@ func (k *Kraken) wsPingHandler(conn stream.Connection) {
}

// wsReadDataResponse classifies the WS response and sends to appropriate handler
func (k *Kraken) wsReadDataResponse(channelName string, pair currency.Pair, response []any) error {
switch channelName {
func (k *Kraken) wsReadDataResponse(c string, pair currency.Pair, response []any) error {
switch c {
case krakenWsTicker:
return k.wsProcessTickers(response, pair)
case krakenWsSpread:
Expand All @@ -270,14 +270,14 @@ func (k *Kraken) wsReadDataResponse(channelName string, pair currency.Pair, resp
return k.wsProcessOpenOrders(response[0])
}

channelType := strings.TrimRight(channelName, "-0123456789")
channelType := strings.TrimRight(c, "-0123456789")
switch channelType {
case krakenWsOHLC:
return k.wsProcessCandles(channelName, response, pair)
return k.wsProcessCandles(c, response, pair)
case krakenWsOrderbook:
return k.wsProcessOrderBook(channelName, response, pair)
return k.wsProcessOrderBook(c, response, pair)
default:
return fmt.Errorf("received unidentified data for subscription %s: %+v", channelName, response)
return fmt.Errorf("received unidentified data for subscription %s: %+v", c, response)
}
}

Expand Down Expand Up @@ -580,9 +580,9 @@ func (k *Kraken) wsProcessTrades(response []any, pair currency.Pair) error {
}

// wsProcessOrderBook handles both partial and full orderbook updates
func (k *Kraken) wsProcessOrderBook(channelName string, response []any, pair currency.Pair) error {
func (k *Kraken) wsProcessOrderBook(c string, response []any, pair currency.Pair) error {
key := &subscription.Subscription{
Channel: channelName,
Channel: c,
Asset: asset.Spot,
Pairs: currency.Pairs{pair},
}
Expand All @@ -591,7 +591,7 @@ func (k *Kraken) wsProcessOrderBook(channelName string, response []any, pair cur
}
s := k.Websocket.GetSubscription(key)
if s == nil {
return fmt.Errorf("%w: %s %s %s", subscription.ErrNotFound, asset.Spot, channelName, pair)
return fmt.Errorf("%w: %s %s %s", subscription.ErrNotFound, asset.Spot, c, pair)
}
if s.State() == subscription.UnsubscribingState {
// We only care if it's currently unsubscribing
Expand Down Expand Up @@ -923,7 +923,7 @@ func trim(s string) string {
}

// wsProcessCandles converts candle data and sends it to the data handler
func (k *Kraken) wsProcessCandles(channelName string, response []any, pair currency.Pair) error {
func (k *Kraken) wsProcessCandles(c string, response []any, pair currency.Pair) error {
// 8 string quoted floats followed by 1 integer for trade count
dataStr, ok := response[1].([]any)
if !ok || len(dataStr) != 9 {
Expand All @@ -944,7 +944,7 @@ func (k *Kraken) wsProcessCandles(channelName string, response []any, pair curre
}

// Faster than getting it through the subscription
parts := strings.Split(channelName, "-")
parts := strings.Split(c, "-")
if len(parts) != 2 {
return errBadChannelSuffix
}
Expand Down Expand Up @@ -1187,7 +1187,7 @@ func (k *Kraken) wsProcessSubStatus(resp []byte) {
if err != nil {
return
}
channelName, err := jsonparser.GetUnsafeString(resp, "channelName")
c, err := jsonparser.GetUnsafeString(resp, "channelName")
if err != nil {
return
}
Expand All @@ -1200,7 +1200,7 @@ func (k *Kraken) wsProcessSubStatus(resp []byte) {
}
key := &subscription.Subscription{
// We don't use asset because it's either Empty or Spot, but not both
Channel: channelName,
Channel: c,
Pairs: currency.Pairs{pair},
}

Expand Down

0 comments on commit 8b5c377

Please sign in to comment.