Created
December 13, 2017 15:34
-
-
Save mylons/e36361c5337cc182d1a8d9c9bd3c9c73 to your computer and use it in GitHub Desktop.
handsome code for a handsome man
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
| 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