def current_price_of_bitcoin():
'''
Pre: coinmarketcap's api can be accessed. This will require an internet connection.
Returns: The price of Bitcoin in USD according to coinmarketcap.com
The variable will be a Decimal with eight decimal places.
'''
with localcontext() as context:
context.prec = 8
r = requests.get("https://api.coinmarketcap.com/v1/ticker/bitcoin/")
return Decimal(r.json()[0]["price_usd"])
评论列表
文章目录