Predict Bitcoin from Binance
Tags: #ccxt #bitcoin #trading
Author: Jeremy Ravenel

Input

Install package

1
!pip install ccxt --user
Copied!

Import libraries

1
import naas
2
import ccxt
3
import pandas as pd
4
from datetime import datetime
5
from naas_drivers import plotly, prediction
Copied!

Setup Binance

1
binance_api = ""
2
binance_secret = ""
Copied!

Variables

1
symbol = 'BTC/USDT'
2
limit = 200
3
timeframe = '1d'
Copied!

Model

Get data

1
binance = ccxt.binance({
2
'apiKey': binance_api,
3
'secret': binance_secret
4
})
5
6
data = binance.fetch_ohlcv(symbol=symbol,
7
limit=limit,
8
timeframe=timeframe)
Copied!

Mapping of the candlestick plot

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

Attribute the candlesticks variables

1
chart_candlestick = plotly.candlestick(df,
2
label_x="Date",
3
label_open="Open",
4
label_high="High",
5
label_low="Low",
6
label_close="Close"
7
)
Copied!
1
df[f"MA{20}"] = df.Close.rolling(
2
20
3
).mean()
4
df[f"MA{50}"] = df.Close.rolling(
5
50
6
).mean()
Copied!

Get the prediction for the stock plot

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

Output

Display bitcoin plot prediction by changing resolution

1
chart_stock.update_layout(
2
autosize=True,
3
width=1300,
4
height=800,
5
)
Copied!
Copy link
Edit on GitHub