more current coin price
This commit is contained in:
+10
-5
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user