Last active
May 18, 2018 10:12
-
-
Save miljkovicivan/241e6f84d147db65e523c3aac972138b to your computer and use it in GitHub Desktop.
IOTA price
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
import requests | |
import json | |
TOTAL = ... # total amount of IOTA | |
BUY_PRICE = ... # buy price in BTC | |
def print_stats(): | |
iota_response = requests.get('https://api.bitfinex.com/v2/ticker/tIOTBTC') | |
if iota_response.status_code == 200: | |
bid_index = 0 | |
iota_rate = json.loads(iota_response.content)[bid_index] | |
percentage_profit = 100 * iota_rate / BUY_PRICE - 100 | |
print('Profit: %.2f' % (percentage_profit) + '%') | |
print(f'Total: %.8f BTC' % (TOTAL * iota_rate)) | |
usd_response = requests.get('https://api.bitfinex.com/v2/ticker/tIOTUSD') | |
if usd_response.status_code != 200: | |
print(usd_response.content) | |
return | |
iota_rate_usd = json.loads(usd_response.content)[bid_index] | |
print('Total: $%.2f' % (TOTAL * iota_rate_usd)) | |
else: | |
print(iota_response.content) | |
print_stats() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment