Learn practical skills, build real-world projects, and advance your career
from binance.client import Client
import glob
import pandas as pd
import pytz
import datetime
import urllib3
def scrap_binance_price(sym, interval, start_date):
    """
    sym: Ticker symbol of the asset - e.g: BTCUSDT
    interval: the interval range for candles - e.g. 1m 10m 4h
    unit: start date - can be the absolute start date (17 Aug, 2020) or a time period string - 5 months ago
    """
    api_key = 'LKa422RMjzx2tsXESIoSQ5qJzqi7LaC7iDFf9qdSrYjhJrZ6a8CcvOdniJWtfX13'
    api_secret = 'EvomPthpqwgTjeuqYFWBQM9HtE52Zeq6SuKrZSROqhd8g2tvbz086zVZqbbJGxsZ'

    client = Client(api_key, api_secret, {"verify": False, "timeout": 20})
    klines = client.get_historical_klines(sym, unit, interval)[:-1] # Removing last candle to eliminate unfixed candle price
    bnb_klines = client.get_historical_klines("BNBUSDT", interval, start_date)[:-1]

    data = pd.DataFrame()
    tradingdate = []
    openprice = []
    highprice = []
    lowprice = []
    closeprice = []
    bnbprice = []
    for i in range(len(klines)):
        time = datetime.datetime.utcfromtimestamp(klines[i][0] / 1000).strftime('%Y-%m-%d %H:%M:%S')
        tradingdate.append(time)
        openprice.append(float(klines[i][1]))
        highprice.append(float(klines[i][2]))
        lowprice.append(float(klines[i][3]))
        closeprice.append(float(klines[i][4]))
        bnbprice.append(float(bnb_klines[i][4]))
    data['datetime'] = tradingdate
    data['low'] = lowprice
    data['high'] = highprice
    data['open'] = openprice
    data['close'] = closeprice
    data['bnb_price'] = bnbprice
    data.reset_index(drop=True, inplace=True)
    return data
import jovian
jovian.commit(project="bitbotboom-liverenkobot-get-binance-price-data", environment=None, filename="/home/ec2-user/SageMaker/Renko Simulation/scrape_price_data.ipynb")
Renko Simulationa