-
Notifications
You must be signed in to change notification settings - Fork 25
KucoinWebsocketClient does not handle batch (un)subscribe correctly #109
Description
It seems like KucoinWebsocketClient can only handle single topics but not batch topics (string with comma-separated topics). According to the API documentation, batch requests are possible, for instance for tickers.
But the code on the subscribe/unsubscribe methods does not account for that. Everything is considered to be single topic and appended to the topics list. This causes no issue with subscriptions, but it does when trying to unsubscribe for multiple topics at once, because then the comma-separated string is only found in the topics list if it is the same string that was used to subscribe.
Here is the relevant code:
async def subscribe(self, topic):
"""Subscribe to a channel
:param topic: required
:type topic: str
:returns: None
"""
req_msg = {
'type': 'subscribe',
'topic': topic,
'response': True
}
self._conn.topics.append(topic)
await self._conn.send_message(req_msg)
async def unsubscribe(self, topic):
"""Unsubscribe from a topic
:param topic: required
:type topic: str
:returns: None
"""
req_msg = {
'type': 'unsubscribe',
'topic': topic,
'response': True
}
self._conn.topics.remove(topic)
await self._conn.send_message(req_msg)
It lacks a check if the topic contains commas, which would require a split before appending to or removing from the list.