Skip to content

Commit

Permalink
fixup! GateIO: Abstract multi-asset connections
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Jan 29, 2025
1 parent 3213531 commit 09b4162
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions exchanges/gateio/gateio_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,7 @@ type WSResponse struct {
Event string `json:"event"`
Result json.RawMessage `json:"result"`
RequestID string `json:"request_id"`
assetType asset.Item
}

// WsTicker websocket ticker information.
Expand Down
39 changes: 23 additions & 16 deletions exchanges/gateio/gateio_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,46 +191,53 @@ func (g *Gateio) wsHandleData(ctx context.Context, respRaw []byte) error {
return err
}

channelParts := strings.Split(push.Channel, ".")
a, _ := asset.New(channelParts[0]) // Final return takes care of error
if channelParts := strings.Split(push.Channel, "."); len(channelParts) != 2 {
return fmt.Errorf("%w `channel` (`%s`)", errParsingWSField, push.Channel)
} else {
// Assign to push so that we can abstract CoinM/USDT as just Futures
if push.assetType, err = asset.New(channelParts[0]); err != nil {
return fmt.Errorf("%w `channel`; %w: `%s`", errParsingWSField, asset.ErrInvalidAsset, channelParts[0])
}
push.Channel = channelParts[1]
}

switch a {
switch push.assetType {
case asset.Spot:
return g.wsHandleSpotData(ctx, push, respRaw)
}
return fmt.Errorf("%w `channel`; %w: `%s`", errParsingWSField, asset.ErrInvalidAsset, push.Channel)
return fmt.Errorf("%w `channel`; %w: `%s`", errParsingWSField, asset.ErrNotSupported, push.assetType)
}

// wsHandleSpotData handles spot data
func (g *Gateio) wsHandleSpotData(ctx context.Context, push *WSResponse, respRaw []byte) error {
switch push.Channel { // TODO: Convert function params below to only use push.Result
case spotTickerChannel:
case tickerChannel:
return g.processTicker(push.Result, push.Time)
case spotTradesChannel:
case tradesChannel:
return g.processTrades(push.Result)
case spotCandlesticksChannel:
case candlesticksChannel:
return g.processCandlestick(push.Result)
case spotOrderbookTickerChannel:
case orderbookTickerChannel:
return g.processOrderbookTicker(push.Result, push.Time)
case spotOrderbookUpdateChannel:
case orderbookUpdateChannel:
return g.processOrderbookUpdate(push.Result, push.Time)
case spotOrderbookChannel:
case orderbookChannel:
return g.processOrderbookSnapshot(push.Result, push.Time)
case spotOrdersChannel:
case ordersChannel:
return g.processSpotOrders(respRaw)
case spotUserTradesChannel:
case userTradesChannel:
return g.processUserPersonalTrades(respRaw)
case spotBalancesChannel:
case balancesChannel:
return g.processSpotBalances(respRaw)
case marginBalancesChannel:
return g.processMarginBalances(respRaw)
case spotFundingBalanceChannel:
case fundingBalanceChannel:
return g.processFundingBalances(respRaw)
case crossMarginBalanceChannel:
return g.processCrossMarginBalance(respRaw)
case crossMarginLoanChannel:
return g.processCrossMarginLoans(respRaw)
case spotPongChannel:
case pongChannel:
default:
g.Websocket.DataHandler <- stream.UnhandledMessageWarning{
Message: g.Name + stream.UnhandledMessage + string(respRaw),
Expand Down Expand Up @@ -781,7 +788,7 @@ func channelName(s *subscription.Subscription) string {
// singleSymbolChannel returns if the channel should be fanned out into single symbol requests
func singleSymbolChannel(name string) bool {
switch name {
case spotCandlesticksChannel, spotOrderbookUpdateChannel, spotOrderbookChannel:
case candlesticksChannel, orderbookUpdateChannel, orderbookChannel:
return true
}
return false
Expand Down

0 comments on commit 09b4162

Please sign in to comment.