Links

Predict Bitcoin from Binance

Tags: #ccxt #bitcoin #trading #investors #ai #analytics #plotly
Author: Jeremy Ravenel​

Input

Install package

!pip install ccxt --user

Import libraries

import naas
import ccxt
import pandas as pd
from datetime import datetime
from naas_drivers import plotly, prediction

Setup Binance

👉 How to create API ?​
binance_api = ""
binance_secret = ""

Variables

symbol = 'BTC/USDT'
limit = 200
timeframe = '1d'

Model

Get data

binance = ccxt.binance({
'apiKey': binance_api,
'secret': binance_secret
})
​
data = binance.fetch_ohlcv(symbol=symbol,
limit=limit,
timeframe=timeframe)

Mapping of the candlestick plot

df = pd.DataFrame(data, columns=["Date","Open","High","Low","Close","Volume"])
df['Date'] = [datetime.fromtimestamp(float(time)/1000) for time in df['Date']]

Attribute the candlesticks variables

chart_candlestick = plotly.candlestick(df,
label_x="Date",
label_open="Open",
label_high="High",
label_low="Low",
label_close="Close"
)
df[f"MA{20}"] = df.Close.rolling(
20
).mean()
df[f"MA{50}"] = df.Close.rolling(
50
).mean()

Get the prediction for the stock plot

pr = prediction.get(dataset=df)
chart_stock = plotly.stock(pr, kind="linechart")

Output

Display bitcoin plot prediction by changing resolution

chart_stock.update_layout(
autosize=True,
width=1300,
height=800,
)