Last active
January 15, 2018 13:29
-
-
Save TheCherry/e0c09f10034be1f305adb5770557c0d6 to your computer and use it in GitHub Desktop.
Simple overview of all owned coins.
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/env python | |
# -*- coding: utf-8 -*- | |
import requests | |
import json | |
import time | |
## Check name by coinmarketcap URL | |
## example Oyster PRL: https://coinmarketcap.com/currencies/oyster-pearl/ | |
## Its then "oyster-pearl" | |
coins = [ | |
{ | |
"name": "bitcoin", | |
"amount": 0.1 | |
}, | |
{ | |
"name": "bitcoin-gold", | |
"amount": 0.1 | |
} | |
] | |
my_eur = 0.0 | |
my_btc = 0.0 | |
header = "{:20} - {:>11} - {:>14} - {:>11} - {:9}".format("Coin", "EUR-Price", "Amount", "BTC-Amount", "EUR-Amount") | |
print(header) | |
print("-"*len(header)) | |
def get_coinmarket(get): | |
resp = requests.get(get) | |
i = 0 | |
while(resp.status_code != 200): | |
if(i >= 10): | |
print("DOWN?: " + get) | |
if(i >= 50): | |
print("DOWN!") | |
return None | |
resp = requests.get(get) | |
i+=1 | |
time.sleep(0.05) | |
ret = resp.json() | |
return ret[0] | |
for coin in coins: | |
if(coin["amount"] > 0.0): | |
obj = get_coinmarket('https://api.coinmarketcap.com/v1/ticker/{}/?convert=EUR'.format(coin["name"])) | |
eur = float(obj["price_eur"])*coin["amount"] | |
btc = float(obj["price_btc"])*coin["amount"] | |
print("{:20} - {: 11.4f} - {: 14.8f} - {: 10.8f} - {: 8.2f}€".format(coin["name"], float(obj["price_eur"]), coin["amount"], btc, eur)) | |
my_eur += eur | |
my_btc += btc | |
print("{:50}{}".format("", "===========================")) | |
print("{:54}{: 10.8f} - {: 8.2f}€".format("", my_btc, my_eur)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example Output: https://sola.ai/posts/YmIxZTl?r=cherry_acf3f