示例#1
0
    def handle_response(self, ts, resp):
        """
        Passes a response message to the corresponding event handler, and also
        takes care of handling errors raised by the _raise_error handler.
        :param ts: timestamp, declares when data was received by the client
        :param resp: dict, containing info or error keys, among others
        :return:
        """
        log.info("handle_response: Handling response %s", resp)
        event = resp['event']
        try:
            self._event_handlers[event](ts, **resp)
        # Handle Non-Critical Errors
        except (InvalidChannelError, InvalidPairError, InvalidBookLengthError,
                InvalidBookPrecisionError) as e:
            log.exception(e)
            print(e)
        except (NotSubscribedError, AlreadySubscribedError) as e:
            log.exception(e)
            print(e)
        except GenericSubscriptionError as e:
            log.exception(e)
            print(e)

        # Handle Critical Errors
        except InvalidEventError as e:
            log.critical("handle_response(): %s; %s", e, resp)
            log.exception(e)
            raise SystemError(e)
        except KeyError:
            # unsupported event!
            raise UnknownEventError("handle_response(): %s" % resp)
示例#2
0
    def _handle_auth(self, ts, chan_id, data):
        keys = {
            'hts': self._handle_auth_trades,
            'te': self._handle_auth_trades,
            'tu': self._handle_auth_trades,
            'ps': self._handle_auth_positions,
            'pn': self._handle_auth_positions,
            'pu': self._handle_auth_positions,
            'pc': self._handle_auth_positions,
            'os': self._handle_auth_orders,
            'on': self._handle_auth_orders,
            'ou': self._handle_auth_orders,
            'oc': self._handle_auth_orders,
            'hos': self._handle_auth_orders,
            'ws': self._handle_auth_wallet,
            'wu': self._handle_auth_wallet,
            'bs': self._handle_auth_balance,
            'bu': self._handle_auth_balance,
            'mis': self._handle_auth_margin_info,
            'miu': self._handle_auth_margin_info,
            'fis': self._handle_auth_funding_info,
            'fiu': self._handle_auth_funding_info,
            'fos': self._handle_auth_offers,
            'fon': self._handle_auth_offers,
            'fou': self._handle_auth_offers,
            'foc': self._handle_auth_offers,
            'hfos': self._handle_auth_offers,
            'fcs': self._handle_auth_credits,
            'fcn': self._handle_auth_credits,
            'fcu': self._handle_auth_credits,
            'fcc': self._handle_auth_credits,
            'hfcs': self._handle_auth_credits,
            'fls': self._handle_auth_loans,
            'fln': self._handle_auth_loans,
            'flu': self._handle_auth_loans,
            'flc': self._handle_auth_loans,
            'hfls': self._handle_auth_loans,
            'hfts': self._handle_auth_funding_trades,
            'fte': self._handle_auth_funding_trades,
            'ftu': self._handle_auth_funding_trades
        }

        event, *data = data

        try:
            keys[event](event, data)
        except KeyError:
            log.exception('%s; %s', chan_id, data)
            raise UnknownEventError('The Passed event in data[0] is not '
                                    'associated with any data handler!')
        except Exception:
            log.exception("_handle_auth: %s - %s, %s", chan_id, event, data)
            raise