Skip to content

Exchanges: Migrate cool exchanges to multi-connection#2167

Open
gloriousCode wants to merge 31 commits intothrasher-corp:masterfrom
gloriousCode:dom-subs
Open

Exchanges: Migrate cool exchanges to multi-connection#2167
gloriousCode wants to merge 31 commits intothrasher-corp:masterfrom
gloriousCode:dom-subs

Conversation

@gloriousCode
Copy link
Collaborator

PR Description

Hello programmers, my name is @gloriousCode and I'm here to say, that this work migrates some exchanges to use multi-connection and subscription scaling functions, okay!

Updated the following exchanges to use multi-connection and sub scaling:

  • Bitfinex
  • Coinbase
  • Deribit
  • Gemini
  • Huobi
  • Kraken

Type of change

  • New feature (non-breaking change which adds functionality)

How has this been tested

  • Excuse me?
  • Ran tests
  • Tested each websocket via go run .

@gloriousCode gloriousCode self-assigned this Feb 12, 2026
@gloriousCode gloriousCode added the review me This pull request is ready for review label Feb 12, 2026
Copilot AI review requested due to automatic review settings February 12, 2026 02:55
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates several exchanges to a new multi-connection websocket manager, which is a significant and valuable refactoring. The implementation looks mostly solid, with consistent changes across the affected exchanges.

My main concern is the removal of several websocket subscription tests from kraken_test.go and huobi_test.go. These tests covered important scenarios that should still be validated with the new architecture. I've left a comment with more details.

I also found a minor opportunity for code deduplication in bitfinex_test.go.

@thrasher-
Copy link
Collaborator

@codex please review

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates several exchange websocket implementations to the multi-connection websocket manager, updating connectors/subscription handlers to be connection-aware and adjusting tests accordingly.

Changes:

  • Updated exchange websocket setup to use UseMultiConnectionManagement and per-connection ConnectionSetup (public/private connections, subscription scaling limits).
  • Refactored websocket connect/subscribe/unsubscribe/data-handler functions to accept (ctx, conn, payload) signatures.
  • Updated and reworked websocket tests/fixtures to match the new connection-aware APIs.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
exchanges/okx/okx_test.go Updates WS subscription setup in tests to align with connection-aware subscription store usage.
exchanges/kraken/kraken_wrapper.go Migrates Kraken WS setup to multi-connection manager and adds public/private connection setups.
exchanges/kraken/kraken_websocket.go Refactors Kraken WS connector/handler/subscription management for per-connection routing.
exchanges/kraken/kraken_test.go Updates Kraken websocket tests and adds a new mock WS instance helper.
exchanges/huobi/huobi_wrapper.go Adds supplementary WS endpoint and migrates Huobi WS setup to multi-connection manager.
exchanges/huobi/huobi_websocket.go Refactors Huobi WS connector/auth/handler/subscription management for per-connection routing.
exchanges/huobi/huobi_test.go Updates Huobi websocket fixture tests to match new handler signature.
exchanges/gemini/gemini_wrapper.go Migrates Gemini WS setup to multi-connection manager with separate v2 public and v1 auth endpoints.
exchanges/gemini/gemini_websocket.go Refactors Gemini WS connector/auth/subscription functions to be connection-aware.
exchanges/gemini/gemini_test.go Updates Gemini websocket tests to use the connection-aware handler signature and connection lifecycle.
exchanges/deribit/deribit_ws_endpoints.go Routes WS requests via Websocket.GetConnection() instead of a single global connection.
exchanges/deribit/deribit_wrapper.go Migrates Deribit WS setup to multi-connection manager and enables subscription scaling.
exchanges/deribit/deribit_websocket.go Refactors Deribit WS connector/auth/handler/subscription functions to be connection-aware.
exchanges/deribit/deribit_test.go Updates Deribit websocket fixture tests and connect path for the new manager.
exchanges/coinbase/coinbase_wrapper.go Migrates Coinbase WS setup to multi-connection manager and adapts handler signature.
exchanges/coinbase/coinbase_websocket.go Refactors Coinbase WS connector/subscription management and updates handler signature.
exchanges/coinbase/coinbase_test.go Updates Coinbase websocket tests and introduces helper functions for connection + subscription.
exchanges/bitfinex/bitfinex_wrapper.go Migrates Bitfinex WS setup to multi-connection manager with subscription scaling limits.
exchanges/bitfinex/bitfinex_websocket.go Refactors Bitfinex WS connector/handler/subscription logic to be connection-aware.
exchanges/bitfinex/bitfinex_test.go Updates Bitfinex websocket tests for the new connection-aware APIs.
exchange/websocket/manager.go Minor comment/formatting cleanup in multi-connection connect flow.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c26628631

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@gloriousCode gloriousCode added Artficial Inveigh and removed review me This pull request is ready for review labels Feb 12, 2026
Copy link
Collaborator

@samuael samuael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work migrating the implementation to multisocket. The WebSocket Connect methods are/should be now well tested and correctly integrated with the wrapper.

@thrasher- thrasher- added review me This pull request is ready for review and removed wow! Artficial Inveigh labels Feb 12, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 6 comments.

Copy link
Collaborator

@samuael samuael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added another round or review comments.

Copy link
Collaborator

@shazbert shazbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive! 🚀 Just some minor things. looking good 💃

Comment on lines +924 to +926
if conn == nil {
return fmt.Errorf("%w: nil connection for %s id %d", websocket.ErrSubscriptionFailure, channelName, int64(id))
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Conn on every handle should always be supplied from the reader so you can rm this and let it panic. But whatevs. You do you my dude.

Copy link
Collaborator Author

@gloriousCode gloriousCode Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 I think it was inspired by all the other additional uses of it eg gateio. I have removed every instance except in manager.go

Handler: e.wsHandleData,
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
ResponseMaxLimit: exch.WebsocketResponseMaxLimit,
URL: publicBitfinexWebsocketEndpoint,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to use e.API.Endpoints.GetURL(exchange.WebsocketSpot) so that the config can override this and for the auth below.

Copy link
Collaborator Author

@gloriousCode gloriousCode Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use gateio as an inspiration since you use it so much and I'm mislead by your implementation. This will not stand!

(I will update all implementations)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the standard is GetURL is used for URL and is also the MessageFilter, I've rolled that out too, but let me know if that makes you mad and/or sad, especially gateio. The only exceptional circumstance is Bybit since we have 2 assets using the same connection

@thrasher- thrasher- requested review from gbjk and removed request for gbjk February 25, 2026 05:26
Copy link
Collaborator

@shazbert shazbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Connector: e.WsConnectSpot,
Authenticate: e.authenticateSpot,
MessageFilter: asset.Spot,
MessageFilter: wsSpotURL,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what is the main reason for swapping from a static key value to something potentially dynamic? I don't mind the design choice just curious. We could even drop message filter altogether and just match against the conn url.

Copy link
Collaborator Author

@gloriousCode gloriousCode Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just trying to follow your standard and make more consistent. Happy to revert! MessageFilter drop can be something in another PR with a proper look
As said earlier, there is another exchange that uses the same URL twice for a different asset, so connURL there doesnt work

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷 I dunno, it works. I am not fussed, if we change the URL by RPC then things could get cooked. So would need to ensure that the underlying system gets some loving on that, if we even have that support? I haven't checked. Will defer reversion until @thrasher- has a looksy. 🕺

Copy link
Collaborator Author

@gloriousCode gloriousCode Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was mostly in response to your other nit here. To use the GetURL, wasn't going to have a static URL be the MessageFilter and the dynamic URL as the URL. That would have been weird. Will look at this later. Just trying to do what you're after. So let me know what you want for it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review me This pull request is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants