Skip to content

Commit

Permalink
Merge pull request #59 from MarcelBeining/master
Browse files Browse the repository at this point in the history
fixing send_ping never called (closes #56)
  • Loading branch information
sammchardy committed Apr 17, 2019
2 parents cb9744b + 1c27040 commit 02bdc7e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions kucoin/asyncio/websockets.py
Expand Up @@ -33,12 +33,12 @@ def __init__(self, loop, client: Client, coro, private: bool = False):
self._connect()

def _connect(self):
self._conn = asyncio.ensure_future(self._run())
self._conn = asyncio.ensure_future(self._run(), loop=self._loop)

async def _run(self):

keep_waiting: bool = True

self.lastPing = time.time()
# get the websocket details
self._ws_details = None
self._ws_details = self._client.get_ws_endpoint(self._private)
Expand All @@ -49,11 +49,13 @@ async def _run(self):

try:
while keep_waiting:
if time.time() - self.lastPing > self._get_ws_pingtimeout():
await self.send_ping()
try:
evt = await asyncio.wait_for(self._socket.recv(), timeout=self._get_ws_pingtimeout())
except asyncio.TimeoutError:
self._log.debug("no message in {} seconds".format(self._get_ws_pingtimeout()))
await self.send_ping()
pass
except asyncio.CancelledError:
self._log.debug("cancelled error")
await self._socket.ping()
Expand Down Expand Up @@ -121,6 +123,7 @@ async def send_ping(self):
'type': 'ping'
}
await self._socket.send(json.dumps(msg))
self.lastPing = time.time()

async def send_message(self, msg, retry_count=0):
if not self._socket:
Expand Down

0 comments on commit 02bdc7e

Please sign in to comment.