Title: Fetching Bitcoin Price Post by: raybucks on October 09, 2023, 09:08:20 AM Could you provide a Python code snippet that illustrates how to fetch the current Bitcoin price from a popular cryptocurrency API, parse the response, and display it in a user-friendly format within a Python application?
Title: Re: Fetching Bitcoin Price Post by: bitmover on October 09, 2023, 11:05:31 AM Could you provide a Python code snippet that illustrates how to fetch the current Bitcoin price from a popular cryptocurrency API, parse the response, and display it in a user-friendly format within a Python application? You get the price from binance here Api https://api.binance.com/api/v3/avgPrice?symbol=BTCUSDT Response Code: {"mins":5,"price":"27533.26924995"} This is code to print the response Code: import requests Title: Re: Fetching Bitcoin Price Post by: seek3r on October 10, 2023, 12:22:17 PM You can also use the the API of Coingecko if you dont want to use a specific exchange.
For fetching the current btc price in USD you can use this url: https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd (https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd) You are good to go with the version of bitmover but here is a version where the API is used from coingecko: Code: import requests Implemented check if the request to the API was successful, otherwise they would be following output: Code: Sorry, but unable to fetch current price of Bitcoin from Coingecko. |