:param instmt: Instrument :param message: Message """ print message def start(self, instmt): self.init_instmt_snapshot_table(instmt) Logger.info( self.__class__.__name__, 'instmt snapshot table: {}'.format(instmt.get_instmt_code())) return [ self.api_socket.connect( self.api_socket.get_link(), on_message_handler=partial(self.on_message_handler, instmt), on_open_handler=partial(self.on_open_handler, instmt), on_close_handler=partial(self.on_close_handler, instmt)) ] if __name__ == '__main__': import logging import websocket websocket.enableTrace(True) logging.basicConfig() Logger.init_log() exchange_name = 'Deribit' instmt_name = 'BTC' instmt_code = 'BTC-20DEC19-7250-C' instmt = Instrument(exchange_name, instmt_name, instmt_code) exch = ExchGwTradeDeribit([]) exch.start(instmt)
for handler in self.on_message_handlers: handler(m) def __on_open(self): Log.info(self.__class__.__name__, "Socket <%s> is opened." % self.id) self._connected = True if len(self.on_open_handlers) > 0: for handler in self.on_open_handlers: handler(self.ws) def __on_close(self, ws): Log.info(self.__class__.__name__, "Socket <%s> is closed." % self.id) self._connecting = False self._connected = False if len(self.on_close_handlers) > 0: for handler in self.on_close_handlers: handler(ws) def __on_error(self, ws, error): Log.info(self.__class__.__name__, "Socket <%s> error:\n %s" % (self.id, error)) if len(self.on_error_handlers) > 0: for handler in self.on_error_handlers: handler(ws, error) if __name__ == '__main__': Log.init_log() socket = WebsocketApiClient('test') socket.connect('ws://localhost', reconnect_interval=1) time.sleep(10)