Created
June 22, 2018 20:05
-
-
Save messiest/27bc11289f418ea1f1606d88b14e22bd to your computer and use it in GitHub Desktop.
Get crypto prices
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 python3 | |
import ccxt | |
class Coin: | |
price_dict = ccxt.kraken().fetchTickers() | |
def __init__(self, abbr, name): | |
self.name = name | |
self.pair = "{}/USD".format(abbr) | |
def get_price(self): | |
return Coin.price_dict[self.pair]['last'] | |
def __repr__(self): | |
self.price = self.get_price() | |
s1 = "{}:".format(self.name) | |
s2 = "${:8,.2f}".format(self.price) | |
return s1.ljust(15, " ") + s2.rjust(5, " ") | |
if __name__ == "__main__": | |
coins = [ | |
Coin("BTC", "Bitcoin"), | |
Coin("ETH", "Ethereum"), | |
Coin("LTC", "Litecoin"), | |
] | |
print("\n" + "\n".join((str(coin) for coin in coins)) + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment