Last active
May 1, 2018 16:16
-
-
Save iannase/cfc47d61ac8f81b9e27b116d6a31d6b8 to your computer and use it in GitHub Desktop.
Ticker / Name pairs
This file contains hidden or 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 | |
while True: | |
# base URLs | |
globalURL = "https://api.coinmarketcap.com/v1/global/" | |
tickerURL = "https://api.coinmarketcap.com/v1/ticker/?limit=0" | |
# making a call to all (creating a dictionary of ticker symbol / name pairs) | |
pairs = {} | |
request = requests.get(tickerURL) | |
data = request.json() | |
for x in data: | |
ticker = x['symbol'] | |
name = x['name'] | |
name = name.lower() | |
name = name.replace(' ', '-') | |
if ticker is not None and name is not None: | |
pairs[ticker] = name | |
# all of your currencies from bittrex (append the ticker symbols to an array like this instead of user input) | |
currencies = [] | |
currencies = input("What are the ticker symbols for all of your currencies? (separated by spaces): ").split() | |
for currency in currencies: | |
# check if we have the current currency in out dictionary, skip it if not | |
if currency not in pairs: | |
print(currency + " not found.") | |
continue | |
tickerURL = "https://api.coinmarketcap.com/v1/ticker/" | |
tickerURL += pairs[currency] + '/' # this gets the name from the dictionary by specifying the ticker symbol | |
request = requests.get(tickerURL) | |
data = request.json() | |
ticker = data[0]['symbol'] | |
price = data[0]['price_usd'] | |
print(ticker + ":\t\t$" + price) | |
print() | |
choice = input("Again? (y/n): ") | |
if choice == "n": | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
neat :)
Have to see how I can work this code into mine.
btw, it fails when entering in lower case.