Skip to main content

Customized dash/plotly chart for price candles.

Project description

Live demo

https://colab.research.google.com/drive/1GQ5Vuf07_8WYIYhDSsZxZc4f7fWaZPFP

What is it for?

Sometimes I need to plot something on top of candlestick prices in my Jupyter notebooks. The problem with matplotlib/mplfinance or plotly is that out of the box, they don't work well when the size of the data is more than 10k points. They can plot it, but the inconvenience is that zoom/pan becomes slow.

10k points is just a week of 1-minute candles. But sometimes I want to explore data for a year. The solution I see is to automatically slice and resample the DataFrame based on the current zoom/pan position. I haven't found a simpler way to do this than to write this small library.

If someone knows an easier way to achieve the same, then please let me know by creating an issue.

This library is far from perfect. There are known bugs that I don't have time to fix. But so far, it's better than nothing for me.

Features

Basically, I was trying to make it similar to the UX on TradingView, but not everything was easy to implement. So I implemented what I could/had time for:

  • Zoom by scrolling with the right side fixed by default.
  • Zoom at the cursor position via Ctrl + scroll.
  • Pan by scrolling via Shift + scroll.
  • Current cursor position coordinates.
  • Spike across all subplots (spike is a vertical line at the cursor position).
  • Period buttons to change the resampling period.

Installation

!pip install quote_chart

Once installed, you need to create an instance of a Dash app by calling the create_chart_app function and passing it at least one parameter - the function that will create a Plotly figure for the currently visible X range given by x0, x1 parameters. Here is a minimal working example:

from quote_chart import create_chart_app
import plotly.express as px

def create_figure(x0, x1):
    df = px.data.stocks()  # Sample data in plotly.express
    # Without indexing by date, it will not put dates on the x-axis.
    df.set_index('date', inplace=True)
    return px.line(df['GOOG'])  # Plot GOOG dummy price as a line.

app = create_chart_app(create_figure)
app.run_server()

Usage without installation

The library code is just in one file quote_chart.py, so you can just drop it into the same folder with your Jupyter notebook and import it via from quote_chart import create_chart_app. In this case, you will need to manually install dependencies:

!pip install dash plotly pandas 'numpy<2.0.0'

Examples

There are 3 examples:

  • example_min.ipynb - This is the minimal example of how to use quote_chart. This example doesn't showcase rescaling/period selection, which is the main feature. Available in Google Colab here.

  • example_random.ipynb - A better example of the use of quote_chart. It has period selection and resampling logic. But it has random data and doesn't have technical analysis charts in it. Available in Google Colab here.

  • example_BTCUSDT.ipynb - This is a real-world example with MACD and exponential moving average added to the chart. The only thing that I don't like in this example is that it gets data from Binance, and I'm not sure if it will work in the future. Available in Google Colab here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quote_chart-0.1.3.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

quote_chart-0.1.3-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file quote_chart-0.1.3.tar.gz.

File metadata

  • Download URL: quote_chart-0.1.3.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for quote_chart-0.1.3.tar.gz
Algorithm Hash digest
SHA256 02cf9feff84c0451fcc8bb5fe00efbd91640e9b0ea5e4c86dcc285c77a064e5a
MD5 e3b0c661442e4de905390b38b5505697
BLAKE2b-256 4e55eef2818865d09e44847eeee8760529811afd73cc75cdbaef5b15fe13b58f

See more details on using hashes here.

File details

Details for the file quote_chart-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: quote_chart-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for quote_chart-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 842c81fac13dfa07eb311db3c86320ba698c33dc15408d60e2089ec218b926c9
MD5 8cb90732813918ffc2c0f025f86a2f9d
BLAKE2b-256 533a5b54451fc8ddbcdf4820b176b645fb5235b8d4423e25bbc34a27c26901f1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page