Sign up with your email address to be the first to know about new publications

Power BI and Bitcoin Price

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

You can download the notebook from this link. In the following posts, we will add Azure Function instead of Jupyter Notebooks.

In this demo, you will extract the Bitcoin Price using the API from cryptocurrency exchange Binance (1) Power BI Rest API with Jupyter Notebooks (2) to finally publish the information into a Power BI dashboard (3).

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 find in 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)

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 Dashboard
  2. Add Tile

 

 

 

2 Responses
  • Sandrix
    10 . 01 . 2019

    Good post! Very interesting for beginers.

    • David Alzamendi
      22 . 01 . 2019

      Thank you!

Leave a Reply to David Alzamendi Cancel reply

Your email address will not be published. Required fields are marked *