Skip to content

Instantly share code, notes, and snippets.

@georg90
Created July 22, 2017 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georg90/2d2eb772f27a28d0ee76024e4f263d23 to your computer and use it in GitHub Desktop.
Save georg90/2d2eb772f27a28d0ee76024e4f263d23 to your computer and use it in GitHub Desktop.
Python code to query cryptocompare for your current holding in USD
#!/usr/bin/python
# Author Georg Peters (georg90@github.com)
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