Skip to content

Instantly share code, notes, and snippets.

@dnlcrl
Last active August 29, 2017 09:51
Show Gist options
  • Save dnlcrl/99d98977749c4df8ab0ec0294588acac to your computer and use it in GitHub Desktop.
Save dnlcrl/99d98977749c4df8ab0ec0294588acac to your computer and use it in GitHub Desktop.
get total amount of dollars for all your crypto coins
#!/usr/bin/env python
import sys
import urllib2
import json
endpoint = "https://api.coinmarketcap.com/v1/ticker/"
args = 'bitcoin 1 litecoin 1 ethereum 1'.split(' ')
def main(coins):
total = 0
for c, amount in coins:
num_amount = float(amount)
price = float(json.load(urllib2.urlopen(endpoint + c))[0]['price_usd'])
total += price * num_amount
print '%.2f' % total, '$'
if __name__ == '__main__':
if len(sys.argv) > 1:
args = sys.argv[1:]
coins = zip(args[::2], args[1::2])
main(coins)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment