Skip to content

Instantly share code, notes, and snippets.

@iannase
Last active May 1, 2018 16:16
Show Gist options
  • Save iannase/cfc47d61ac8f81b9e27b116d6a31d6b8 to your computer and use it in GitHub Desktop.
Save iannase/cfc47d61ac8f81b9e27b116d6a31d6b8 to your computer and use it in GitHub Desktop.
Ticker / Name pairs
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
@tiboine
Copy link

tiboine commented May 1, 2018

neat :)
Have to see how I can work this code into mine.
btw, it fails when entering in lower case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment