Skip to content
David Alzamendi Data Enthusiast

How to Build a Real-Time Bitcoin Dashboard in Power BI

In this notebook, you will extract information about the real-time Bitcoin price in Binance exchange and send it to a Power BI dataset.

You can download the notebook from this link. In upcoming posts, you can take a look at Azure Function instead of Jupyter Notebooks.

In this demo, you will extract the real-time Bitcoin Price using API from cryptocurrency exchange Binance.

Then you’ll take a look at Power BI Rest API with Jupyter Notebooks. Finally, you’ll publish the information into a Power BI dashboard.

End Goal: display real-time information in Power BI.

In [ ]:
#Import Libraries
import requests
import json
from IPython.display import HTML
from time import sleep
from urllib.request import urlopen
from datetime import datetime, timedelta

Get Information from the Binance Exchange using the API

Binance API can be found at https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md

In [3]:
BinanceResponse = requests.get('https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT').json()

BinanceConvert = json.dumps(BinanceResponse)
BinanceData = json.loads(BinanceConvert)

print(BinanceData)
{'symbol': 'BTCUSDT', 'price': '3959.72000000'}
Creating & Setting up the Power BI Push Url

Create a dataset with the following columns:

  1. Timestamp (Datetime)
  2. Price (Number)

Then, copy the dataset endpoint.

#Paste the report end point copied above
Power_BI_Endpoint = ''
#Repeat for ever
while True:
               
    # The timestamp needs to be formatted correctly
    now = datetime.strftime(datetime.now(), "%Y-%m-%dT%H:%M:%SZ")
    
    # Acquire data from the exchange
    BinanceResponse = requests.get('https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT').json()

    # Get values from Json response
    BinanceConvert = json.dumps(BinanceResponse)
    BinanceData = json.loads(BinanceConvert)
    Binanceprice=float(BinanceData['price'])
    
    #Format request Json body
    Rows = '[{{ "Timestamp": "{0}", "Price": "{1}" }}]'.format(now, Binanceprice)
   
    # make HTTP POST request to Power BI REST API
    import urllib.request as ur
    req = requests.post(Power_BI_Endpoint, Rows)
    # Wait 1 second
    sleep(1)

Creating Dashboard and streaming real-time information

  1. Create a Dashboard
  2. Add Tile

Check out my other posts

#Power BI

All 10 guides
Other

Preparing for 2024: Top 2 Strategic Focus Areas for Q4 2023

Are you ready to kickstart 2024? As Q4 2023 approaches and companies enter a code freeze, it's crucial to focus on strategic priorities. Explore why maximising ROI in tech investments and leveraging Large Language Models can be game-changers for your business. Learn actionable insights for adopting these key focus areas and staying competitive.

3 min read

Other

Azure Logic App to Send Custom Messages

With Logic Apps, you can create workflows that connect to various services and systems, allowing you to automate tasks and streamline your business operations. In this blog post, we will explore how you can use Azure Logic Apps to send custom messages (Email or SMS).

3 min read

4 comments

  1. Jinesh

    Very nice indeed, does this api has param for currency, i.e. NOT US

    Reply

    1. David Alzamendi Author

      Hi Jinesh,

      I reviewed the API documentation, and I couldn’t find this functionality at this stage.

      Regards,

      David

      Reply

Leave a comment

Your email address isn't published.