sammchardy / python-kucoin

Kucoin REST and Websocket API python implementation
https://python-kucoin.readthedocs.io/en/latest/
MIT License
350 stars 148 forks source link

Websocket market/ticker only received once #116

Closed Tigzy closed 2 years ago

Tigzy commented 2 years ago

Hello, I have a problem for which I'm not sure this is a bug. I used the example to subscribe to a ticker, and I receive the proper data, however it's sent only once. I never receive any other message after the first one. Here's my code:

async def wsTickerWorker(self, loop, pair_name, callback):
        try:        
            ksm = await KucoinSocketManager.create(loop, self.client, callback)
            await ksm.subscribe('/market/ticker:' + pair_name)
        except Exception as e:
            self.app.exception("Unable to create socket manager")
            return

        while not self.stop_requested:
            await asyncio.sleep(1, loop=loop)

def run(self):
        try: 
            self.loop = self.get_or_create_eventloop()
            try:
                self.loop.run_until_complete(self.wsTickerWorker(self.loop, self.pair_name, self.callback))
            finally:
                self.loop.stop()

        except Exception as e:
            self.app.exception("Unable to start web socket")
            return None
Tigzy commented 2 years ago

Ok, I realized I'm receiving this error (silently ignored) : <class 'tuple'>: ("object bool can't be used in 'await' expression",) websockets, line 75 This is preventing reconnect

Tigzy commented 2 years ago

Found the issue, I was not having the "async" keyword for my callback.