ccxws
ccxws copied to clipboard
Kucoin has hard limit of 100 subscriptions per socket
Problem
Kucoin client has a hard limit of 100 subscriptions per socket connection. When more than 100 subscriptions are made on a single socket, Kucoin will return an error:
509: exceed max subscription count limitation of 100 per session.
To work around this issue requires instantiating multiple clients and limiting subscriptions to 100 subscriptions per client. A simple example:
let clients = [];
for(let i = 0; i < markets.length; i++) {
if(i % 100 === 0) {
clients.unshift(new ccwxs.kucoin());
}
clients[0].subscribeTrades(markets[i]);
}
Developer Notes
-
The Bibox client is a custom EventEmitter that is designed to work around the limit of 20 subscriptions per socket. A similar approach could be taken for Kucoin of building a custom EventEmitter.
-
However, I would like to avoid custom clients as much as possible. Instead it would be best to combine functionality of BasicMultiClient where BasicMultiClient can assign N number of subscriptions per socket (with the default being 1).
-
Other thought... it would better code to move away from inheritance based clients and moving towards behavioral composition, though not through mixins -- This would probably be easier if the library was migrated to TypeScript as well.
Hi :) just a quick heads up here it's now 300
per session: https://docs.kucoin.com/#topic-subscription-limit
Don't know if it can be interesting for you but I made my own KuCoin Websocket lib for my company on Github and I handle that issue, so do not hesitate to tell me if it can be useful for you 🙏