MCPcopy Create free account
hub / github.com/ccxt/ccxt / ping_loop

Method ping_loop

python/ccxt/async_support/base/ws/client.py:333–353  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

331 self.ping_looper.cancel()
332
333 async def ping_loop(self):
334 if self.verbose:
335 self.log(iso8601(milliseconds()), 'ping loop')
336 while self.keepAlive and not self.closed():
337 now = milliseconds()
338 self.lastPong = now if self.lastPong is None else self.lastPong
339 if (self.lastPong + self.keepAlive * self.maxPingPongMisses) < now:
340 self.on_error(RequestTimeout('Connection to ' + self.url + ' timed out due to a ping-pong keepalive missing on time'))
341 # the following ping-clause is not necessary with aiohttp's built-in ws
342 # since it has a heartbeat option (see create_connection above)
343 # however some exchanges require a text-type ping message
344 # therefore we need this clause anyway
345 else:
346 if self.ping:
347 try:
348 await self.send(self.ping(self))
349 except Exception as e:
350 self.on_error(e)
351 else:
352 await self.connection.ping()
353 await sleep(self.keepAlive / 1000)

Callers 1

openMethod · 0.95

Calls 9

logMethod · 0.95
closedMethod · 0.95
on_errorMethod · 0.95
sendMethod · 0.95
RequestTimeoutClass · 0.90
millisecondsFunction · 0.85
iso8601Function · 0.70
sleepFunction · 0.50
pingMethod · 0.45

Tested by

no test coverage detected