self.pubserver.send_string( json.dumps({'type': 'book', 'data': response['params']['data']})) else: pass else: pass else: if self.state == ServiceState.started: self.logger.info('websocket is not open') await self.pub_msg() # except websockets.exceptions.ConnectionClosedError: # await self.pub_msg() except Exception as e: self.logger.exception(e) await asyncio.sleep(1) await self.pub_msg() async def run(self): if self.state == ServiceState.started: self.logger.error('tried to run service, but state is %s' % self.state) else: self.state = ServiceState.started await self.pub_msg() if __name__ == '__main__': service = DeribitMD('deribit-future-md', 'deribit-future-md') start_service(service, {})
elif response.get('table', '') in ('option/depth5', 'option/account', 'option/trade'): # self.logger.info(response['data']) self.pubserver.send_string(json.dumps(response)) else: if time.time() - lastheartbeat > 30: raise websockets.exceptions.ConnectionClosedError( 1003, 'Serverside heartbeat stopped') else: if self.state == ServiceState.started: await self.pub_msg() except websockets.exceptions.ConnectionClosedError: await self.pub_msg() except Exception as e: self.logger.exception(e) await self.pub_msg() async def run(self): if self.state == ServiceState.started: self.logger.error('tried to run service, but state is %s' % self.state) else: self.state = ServiceState.started await self.pub_msg() if __name__ == '__main__': service = OkexMD('okex-md', 'okex-md') start_service(service, {'port': 9100, 'ip': 'localhost'})