Skip to content

Conversation

@shazbert
Copy link
Collaborator

@shazbert shazbert commented Dec 3, 2025

  • Migrate kucoin to multi-connection for future subscription load balancing and added it subscription limit for connection.
  • Fix bug on futures orderbook where it was trying to fetch and update via a snapshot.
  • Modified the websocket connection methods across multiple exchanges to include an additional parameter for query values in the Dial function so that the internal URL is not overridden.

Fixes # (issue)

Type of change

Please delete options that are not relevant and add an x in [] as item is complete.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How has this been tested

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and
also consider improving test coverage whilst working on a certain feature or package.

  • go test ./... -race
  • golangci-lint run
  • Test X

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation and regenerated documentation via the documentation tool
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally and on Github Actions with my changes
  • Any dependent changes have been merged and published in downstream modules

- Modified the websocket connection methods across multiple exchanges to include an additional parameter for query values in the Dial function.
- This change ensures that the connection can be established with necessary tokens or parameters as required by the respective exchange APIs.
- Affected files include binance, binanceus, bitfinex, bithumb, bitmex, bitstamp, btcmarkets, btse, bybit, coinbase, coinut, deribit, gateio, gemini, hitbtc, huobi, kraken, kucoin, okx, and poloniex.
@shazbert shazbert self-assigned this Dec 3, 2025
@shazbert shazbert added the review me This pull request is ready for review label Dec 3, 2025
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 introduces a significant architectural improvement by refactoring the websocket connection logic to support query parameters, which is then applied across multiple exchanges. The main focus is the migration of the Kucoin exchange to use the new multi-connection websocket manager, which is a substantial and well-executed change. Additionally, it includes an important bug fix for the Kucoin futures orderbook handling, correctly using LoadSnapshot instead of Update for snapshot data. The code is cleaner and more robust. I've found one critical issue in the Kucoin websocket connection logic that needs to be addressed.

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 pull request migrates KuCoin to a multi-connection websocket architecture with subscription load balancing capabilities, fixes a critical bug in the futures orderbook handling, and updates the websocket Dial signature across all exchanges to support URL query parameters without overriding the internal URL.

  • Refactored KuCoin websocket to use multi-connection management with a 400 subscription per connection limit
  • Fixed futures orderbook depth channels (5/50) to use LoadSnapshot instead of incorrectly calling Update after fetching snapshots
  • Updated websocket Dial interface across 20+ exchanges to accept url.Values as a fourth parameter for query string handling

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated no comments.

Show a summary per file
File Description
exchange/websocket/connection.go Updated Connection interface Dial method to accept url.Values parameter and use EncodeURLValues for proper query string handling
exchange/websocket/manager_test.go Updated all test calls to Dial to include nil url.Values parameter
exchanges/kucoin/kucoin_wrapper.go Migrated to multi-connection setup with 400 max subscriptions per connection, removed buffer config
exchanges/kucoin/kucoin_websocket.go Refactored WsConnect to accept Connection parameter, added marketOrderbookDepth1Channel, fixed futures orderbook bug, updated Subscribe/Unsubscribe signatures
exchanges/kucoin/kucoin_types.go Renamed WsOrderbookLevel5Response to WsFuturesOrderbookLevelResponse for better clarity
exchanges/kucoin/kucoin_test.go Added ConnectionFixture mock, updated test calls to new signatures, added GreaterOrEqual assertion
exchanges/poloniex/poloniex_websocket.go Updated Dial call to include nil url.Values parameter
exchanges/poloniex/poloniex_test.go Updated Dial call to include nil url.Values parameter
exchanges/okx/okx_websocket.go Updated Dial calls to include nil url.Values parameter
exchanges/okx/okx_business_websocket.go Updated Dial call to include nil url.Values parameter
exchanges/kraken/kraken_websocket.go Updated Dial calls to include nil url.Values parameter
exchanges/huobi/huobi_websocket.go Updated Dial calls to include nil url.Values parameter
exchanges/hitbtc/hitbtc_websocket.go Updated Dial call to include nil url.Values parameter
exchanges/hitbtc/hitbtc_test.go Updated Dial call to include nil url.Values parameter
exchanges/gemini/gemini_websocket.go Updated Dial calls to include nil url.Values parameter
exchanges/gateio/gateio_websocket*.go Updated Dial calls across spot, futures, delivery futures, and options to include nil url.Values parameter
exchanges/deribit/deribit_websocket.go Updated Dial call to include nil url.Values parameter
exchanges/coinut/coinut_websocket.go Updated Dial call to include nil url.Values parameter
exchanges/coinut/coinut_test.go Updated Dial call to include nil url.Values parameter
exchanges/coinbase/coinbase_websocket.go Updated Dial call to include nil url.Values parameter
exchanges/coinbase/coinbase_test.go Updated Dial call to include nil url.Values parameter
exchanges/bybit/bybit_websocket.go Updated Dial call to include nil url.Values parameter
exchanges/bybit/bybit_test.go Updated FixtureConnection.Dial signature to include url.Values parameter
exchanges/btse/btse_websocket.go Updated Dial call to include nil url.Values parameter
exchanges/btcmarkets/btcmarkets_websocket.go Updated Dial call to include nil url.Values parameter
exchanges/bitstamp/bitstamp_websocket.go Updated Dial call to include nil url.Values parameter
exchanges/bitmex/bitmex_websocket.go Updated Dial call to include nil url.Values parameter
exchanges/bitmex/bitmex_test.go Updated Dial call to include nil url.Values parameter
exchanges/bithumb/bithumb_websocket.go Updated Dial call to include nil url.Values parameter
exchanges/bitfinex/bitfinex_websocket.go Updated Dial calls to include nil url.Values parameter
exchanges/binanceus/binanceus_websocket.go Updated Dial call to include nil url.Values parameter
exchanges/binance/binance_websocket.go Updated Dial call to include nil url.Values parameter
docs/ADD_NEW_EXCHANGE.md Updated example code to show new Dial signature with nil url.Values parameter
cmd/exchange_template/websocket.tmpl Updated template to show new Dial signature with nil url.Values parameter

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 introduces significant changes to the websocket handling, migrating KuCoin to a multi-connection setup and modifying the Dial function across multiple exchanges. This is a substantial refactoring that improves future scalability and fixes a bug in the futures orderbook handling. My review focuses on the correctness of these changes, particularly in the KuCoin implementation.

Overall, the changes are well-implemented. The move to a multi-connection manager for KuCoin is a great step forward. I've identified a potential compilation error due to a missing field in a struct, which should be addressed. The rest of the changes, including the bug fix for the futures orderbook and the widespread update to the Dial method, look solid.

@thrasher-
Copy link
Collaborator

@codex please review

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.

ℹ️ 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".

Copy link
Collaborator

@gloriousCode gloriousCode left a comment

Choose a reason for hiding this comment

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

Looks good!

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.

Great that you added a support for Kucoin. I've left few comments on the changes of kucoin files.

Copy link
Collaborator

@gloriousCode gloriousCode left a comment

Choose a reason for hiding this comment

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

I dont really have much to add. Once what Sam has raised is addressed I think this is good to go

@shazbert shazbert added reconstructing Based on PR feedback, this is currently being reworked and is not to be merged and removed review me This pull request is ready for review labels Jan 12, 2026
@shazbert
Copy link
Collaborator Author

have to investigate some subscribing issues

@codecov
Copy link

codecov bot commented Jan 13, 2026

Codecov Report

❌ Patch coverage is 51.00000% with 49 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.03%. Comparing base (96b71ce) to head (462ada4).

Files with missing lines Patch % Lines
exchanges/kucoin/kucoin_websocket.go 53.65% 18 Missing and 1 partial ⚠️
exchange/websocket/connection.go 70.00% 2 Missing and 1 partial ⚠️
exchanges/kucoin/kucoin_wrapper.go 85.00% 0 Missing and 3 partials ⚠️
exchanges/gemini/gemini_websocket.go 0.00% 2 Missing ⚠️
exchanges/huobi/huobi_websocket.go 0.00% 0 Missing and 2 partials ⚠️
exchanges/okx/okx_websocket.go 0.00% 2 Missing ⚠️
exchanges/poloniex/poloniex_websocket.go 0.00% 2 Missing ⚠️
exchanges/binanceus/binanceus_websocket.go 0.00% 1 Missing ⚠️
exchanges/bitfinex/bitfinex_websocket.go 50.00% 1 Missing ⚠️
exchanges/bithumb/bithumb_websocket.go 0.00% 1 Missing ⚠️
... and 13 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2119      +/-   ##
==========================================
- Coverage   42.06%   42.03%   -0.03%     
==========================================
  Files         446      446              
  Lines      142919   142891      -28     
==========================================
- Hits        60120    60066      -54     
- Misses      75650    75680      +30     
+ Partials     7149     7145       -4     
Files with missing lines Coverage Δ
exchanges/binance/binance_websocket.go 59.05% <100.00%> (+0.31%) ⬆️
exchanges/bitstamp/bitstamp_websocket.go 68.06% <100.00%> (ø)
exchanges/bybit/bybit_websocket.go 77.86% <100.00%> (ø)
exchanges/kucoin/kucoin_types.go 66.66% <ø> (ø)
exchanges/binanceus/binanceus_websocket.go 46.95% <0.00%> (ø)
exchanges/bitfinex/bitfinex_websocket.go 41.25% <50.00%> (ø)
exchanges/bithumb/bithumb_websocket.go 54.40% <0.00%> (ø)
exchanges/bitmex/bitmex_websocket.go 49.19% <0.00%> (ø)
exchanges/btcmarkets/btcmarkets_websocket.go 53.84% <0.00%> (ø)
exchanges/btse/btse_websocket.go 52.09% <0.00%> (ø)
... and 17 more

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shazbert
Copy link
Collaborator Author

have to investigate some subscribing issues

Not getting issues anymore. 🚀

@shazbert shazbert added review me This pull request is ready for review and removed reconstructing Based on PR feedback, this is currently being reworked and is not to be merged labels Jan 19, 2026
@shazbert shazbert requested a review from gloriousCode January 19, 2026 04:06
Copy link
Collaborator

@gloriousCode gloriousCode left a comment

Choose a reason for hiding this comment

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

tackeroo mr shazoo

@gloriousCode gloriousCode added the gcrc GloriousCode Review Complete label Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gcrc GloriousCode Review Complete review me This pull request is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants