async def run(self): ''' shared_market_data = { "taker_fee": exchange_variables["taker_fee"], -> done "CRO_holding_backup": exchange_variables["CRO_holding_backup"], -> done "balance_USDT": 0, -> done "balance_BTC": 0, -> done "balance_CRO": 0, -> done "price_BTC_sell_to_USDT": 0, -> done "price_CRO_buy_for_BTC": 0, -> done "fee_BTC_sell_in_USDT": 0, "price_CRO_buy_for_USDT": 0, -> done "last_CRO_price_in_USDT": 0, -> done "last_CRO_price_in_BTC": 0, -> done "fee_BTC_sell_in_CRO": 0, "price_BTC_buy_for_USDT": 0, -> done "fee_BTC_buy_in_BTC": 0, "fee_BTC_buy_in_CRO": 0, } ''' event_dispatcher = EventDispatcher() event_dispatcher.register_channel_handling_method("user.balance", self.handle_channel_event_user_balance) event_dispatcher.register_response_handling_method("public/get-instruments", self.handle_response_get_instruments) async with CryptoClient( client_type=CryptoClient.USER, debug=self.debug, logger=self.logger, api_key=self.crypto_com_client.crypto_com_api_key, api_secret=self.crypto_com_client.crypto_com_secret_key, channels=[ "user.balance" ] ) as client: periodic_call_get_instruments = PeriodicAsync(5, lambda: self.get_instruments(client)) await periodic_call_get_instruments.start() try: while True: event_or_response = None try: event_or_response = await client.next_event_or_response() event_dispatcher.dispatch(event_or_response) except Exception as e: if event_or_response: message = "Exception during handling user api event or response: {}".format(repr(e)) self.logger.exception(message) self.logger.error("Event or response that failed: {}".format(event_or_response)) else: message = "Exception during parsing user api event or response: {}".format(repr(e)) self.logger.exception(message) # TODO: Send pushover notification here with message continue finally: self.logger.info("Cleanup before closing worker...") await periodic_call_get_instruments.stop()
async def run(self): event_dispatcher = EventDispatcher() event_dispatcher.register_channel_handling_method( "ticker.BTC_USDT", self.handle_channel_event_ticker_BTC_USDT) event_dispatcher.register_channel_handling_method( "ticker.CRO_USDT", self.handle_channel_event_ticker_CRO_USDT) event_dispatcher.register_channel_handling_method( "ticker.CRO_BTC", self.handle_channel_event_ticker_CRO_BTC) async with CryptoClient(client_type=CryptoClient.MARKET, debug=self.debug, logger=self.logger, channels=[ "ticker.BTC_USDT", "ticker.CRO_USDT", "ticker.CRO_BTC", ]) as client: try: while True: event_or_response = None try: event_or_response = await client.next_event_or_response( ) event_dispatcher.dispatch(event_or_response) except Exception as e: if event_or_response: message = "Exception during handling market data event or response: {}".format( repr(e)) self.logger.exception(message) self.logger.error( "Event or response that failed: {}".format( event_or_response)) else: message = "Exception during parsing market data event or response: {}".format( repr(e)) self.logger.exception(message) # TODO: Send pushover notification here with message continue finally: self.logger.info("Cleanup before closing worker...")