more current coin price
This commit is contained in:
+10
-5
@@ -33,16 +33,20 @@ class Cryptocoin(object):
|
|||||||
return a, b
|
return a, b
|
||||||
|
|
||||||
def getCoinPrice(self, coinId, currencyId="USD", time="now"):
|
def getCoinPrice(self, coinId, currencyId="USD", time="now"):
|
||||||
url = "https://min-api.cryptocompare.com/data/pricehistorical?tsyms=" + currencyId + "&fsym=" + coinId
|
|
||||||
|
|
||||||
if (time != "now"):
|
if (time == "now"): #for the most current price, don't use the history API
|
||||||
url += "&ts=" + str(time)
|
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)
|
response = requests.get(url)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
priceData = json.loads(response.content.decode('utf-8'))
|
priceData = json.loads(response.content.decode('utf-8'))
|
||||||
return priceData[coinId][currencyId]
|
if (time == "now"):
|
||||||
|
return priceData[currencyId]
|
||||||
|
else:
|
||||||
|
return priceData[coinId][currencyId]
|
||||||
except:
|
except:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
@@ -53,8 +57,9 @@ class Cryptocoin(object):
|
|||||||
|
|
||||||
#Get the price history:
|
#Get the price history:
|
||||||
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", int(time.time()) - (N_DATAPOINTS-j)*TIME_BETWEEN_DATAPOINTS))
|
||||||
|
history.append(self.getCoinPrice(coinId, "USD")) #now
|
||||||
|
|
||||||
#Check the growth. Do some linear regression
|
#Check the growth. Do some linear regression
|
||||||
growFactorLongTerm, dummy = self.basic_linear_regression(range(0, N_DATAPOINTS), history)
|
growFactorLongTerm, dummy = self.basic_linear_regression(range(0, N_DATAPOINTS), history)
|
||||||
|
|||||||
Reference in New Issue
Block a user