From 661eca38c4032345aae509df56456cc1718a6ec4 Mon Sep 17 00:00:00 2001 From: JP Date: Wed, 7 Feb 2018 20:56:08 +0100 Subject: [PATCH] more current coin price --- Cryptocoin.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Cryptocoin.py b/Cryptocoin.py index d553d86..39f8eb1 100644 --- a/Cryptocoin.py +++ b/Cryptocoin.py @@ -33,16 +33,20 @@ class Cryptocoin(object): return a, b def getCoinPrice(self, coinId, currencyId="USD", time="now"): - url = "https://min-api.cryptocompare.com/data/pricehistorical?tsyms=" + currencyId + "&fsym=" + coinId - if (time != "now"): - url += "&ts=" + str(time) + if (time == "now"): #for the most current price, don't use the history API + url = "https://min-api.cryptocompare.com/data/price?tsyms=" + currencyId + "&fsym=" + coinId + else: + url = "https://min-api.cryptocompare.com/data/pricehistorical?tsyms=" + currencyId + "&fsym=" + coinId + "&ts=" + str(time) response = requests.get(url) try: priceData = json.loads(response.content.decode('utf-8')) - return priceData[coinId][currencyId] + if (time == "now"): + return priceData[currencyId] + else: + return priceData[coinId][currencyId] except: return -1 @@ -53,8 +57,9 @@ class Cryptocoin(object): #Get the price history: history = [] - for j in range(0, N_DATAPOINTS): + for j in range(0, N_DATAPOINTS-1): history.append(self.getCoinPrice(coinId, "USD", int(time.time()) - (N_DATAPOINTS-j)*TIME_BETWEEN_DATAPOINTS)) + history.append(self.getCoinPrice(coinId, "USD")) #now #Check the growth. Do some linear regression growFactorLongTerm, dummy = self.basic_linear_regression(range(0, N_DATAPOINTS), history)