Skip to content

Instantly share code, notes, and snippets.

@mylons
Created December 13, 2017 15:34
Show Gist options
  • Select an option

  • Save mylons/e36361c5337cc182d1a8d9c9bd3c9c73 to your computer and use it in GitHub Desktop.

Select an option

Save mylons/e36361c5337cc182d1a8d9c9bd3c9c73 to your computer and use it in GitHub Desktop.
handsome code for a handsome man
from concurrent import futures
import requests
URLS = {'BTC': 'https://api.gdax.com/products/BTC-USD/ticker',
'ETH': 'https://api.gdax.com/products/ETH-USD/ticker',
'LTC': 'https://api.gdax.com/products/LTC-USD/ticker'}
def get_quote(toople):
coin, url = toople
resp = requests.get(url).json()
return coin, resp['price']
def all_quotes():
current_prices = {}
with futures.ProcessPoolExecutor() as pool:
for coin, price in pool.map(get_quote, URLS.items()):
current_prices[coin] = price
return current_prices
if __name__ == '__main__':
prices = all_quotes()
print(prices)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment