Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/CCXT/CCXT_Predict_Bitcoin_from_Binance.ipynb
2973 views
Kernel: Python 3

CCXT.png

CCXT - Predict Bitcoin from Binance

Give Feedback | Bug report

Tags: #ccxt #bitcoin #trading #investors #ai #analytics #plotly

Last update: 2023-04-12 (Created: 2021-02-28)

Description: This notebook uses the CCXT library to predict Bitcoin prices on the Binance exchange.

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, )