Created
November 16, 2019 10:07
-
-
Save insaneyilin/ef87936589bbdbe619eb5e78d4d90f47 to your computer and use it in GitHub Desktop.
Python script to query the lastes BTC price.
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
| #!/usr/bin/env python3 | |
| import requests | |
| from datetime import datetime | |
| TICKER_API_URL = 'https://api.coinmarketcap.com/v1/ticker/' | |
| def get_latest_crypto_price(crypto='bitcoin'): | |
| return float(requests.get(TICKER_API_URL+crypto).json()[0]['price_usd']) | |
| if __name__ == '__main__': | |
| last_price = -1 | |
| while True: | |
| price = get_latest_crypto_price() | |
| now = datetime.now() | |
| now.strftime("%Y-%m-%d %H:%M:%S") | |
| if price != last_price: | |
| print(now, ', BTC price: {} USD'.format(price)) | |
| last_price = price |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment