Skip to content

Instantly share code, notes, and snippets.

@insaneyilin
Created November 16, 2019 10:07
Show Gist options
  • Save insaneyilin/ef87936589bbdbe619eb5e78d4d90f47 to your computer and use it in GitHub Desktop.
Save insaneyilin/ef87936589bbdbe619eb5e78d4d90f47 to your computer and use it in GitHub Desktop.
Python script to query the lastes BTC price.
#!/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