qtrade-exchange / qtrade-py-client

A simple requests based wrapper for the qTrade.io API
https://qtrade-exchange.github.io/qtrade-docs/?python--PyClient#public
MIT License
7 stars 4 forks source link

General Improvements #1

Closed icook closed 4 years ago

icook commented 4 years ago

Can be done as lazy loader

    @property
    def currency_obj(self):
        self._refresh_config()
        return self._currency_config

    def _refresh_config(self):
        """ Lazy load and reload every 180 seconds """
        if self._currency_config is None or (time.time() - self._currency_config_age) > 180:
            try:
                currency = self.qtrade.get("/internal/v1/relay/currency/{}".format(self.cfg.Currency))
            except APIException as e:
                if e.code == 500:
                    raise Exception("No remote currency configuration present")
                else:
                    raise
            self.log.info("Loaded currency config {}".format(currency))
            self._currency_config = currency
            self._currency_config_age = time.time()
            # TODO: Do some sanity checking on the returned config. Proceeding
            # with incomplete confis can cause issues