def get_prices(self, epic_id, interval, data_range): """ Returns past prices for the given epic - **epic_id**: market epic as string - **interval**: resolution of the time series: minute, hours, etc. - **data_range**: amount of datapoint to fetch - Returns **None** if an error occurs otherwise the json object returned by IG API """ url = "{}/{}/{}/{}/{}".format(self.apiBaseURL, IG_API_URL.PRICES.value, epic_id, interval, data_range) d = self.http_get(url) if d is not None and "allowance" in d: remaining_allowance = d["allowance"]["remainingAllowance"] reset_time = Utils.humanize_time( int(d["allowance"]["allowanceExpiry"])) if remaining_allowance < 100: logging.warn("Remaining API calls left: {}".format( str(remaining_allowance))) logging.warn("Time to API Key reset: {}".format( str(reset_time))) return d
def test_humanize_time(): assert Utils.humanize_time(3600) == "01:00:00" assert Utils.humanize_time(4800) == "01:20:00" assert Utils.humanize_time(4811) == "01:20:11"