Created
July 22, 2017 14:44
-
-
Save georg90/2d2eb772f27a28d0ee76024e4f263d23 to your computer and use it in GitHub Desktop.
Python code to query cryptocompare for your current holding in USD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Author Georg Peters ([email protected]) | |
import requests | |
import json | |
import time | |
import os | |
url = 'https://min-api.cryptocompare.com/data/price' | |
result = 0 | |
coins = { | |
'ETH': '10', | |
'DGB': '10', | |
'XLM': '10', | |
'STRAT': '10', | |
'XRP': '10', | |
'QTUM': '10', | |
'GNT': '10', | |
'XEM': '10', | |
'RDD': '10', | |
'SC': '10', | |
'SNM': '10', | |
'IOT': '10' | |
} | |
print 'Coin', 'Count', 'Price', '$ Holdings' | |
for (coin, val) in coins.items(): | |
payload = (('fsym', coin), ('tsyms', 'USD')) | |
r = requests.get(url, params=payload) | |
sum= float(r.json()['USD']) * float(val) | |
print coin, val, r.json()['USD'], sum | |
result = result + sum | |
time.sleep( 1 ) # don't trouble the API | |
res = round(result,2) # USD value | |
print "Sum: ", res | |
# Update status to pimatic (pimatic.org) | |
url='http://192.168.0.100:8080/api/variables/crypto-status' | |
headers={'content-type': 'application/json'} | |
payload={'type': 'value', 'valueOrExpression': res} | |
requests.patch(url, data=None, headers=headers, auth=("user", "pass"), params=payload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment