Skip to content

Commit

Permalink
Enhancements:
Browse files Browse the repository at this point in the history
- Added the `screen` parameter to `Chart`, allowing for monitor selection. This should be an index from 0 (0 = primary monitor, 1=  second monitor, etc.)
- `vertical_span` method, allowing for vertical lines/spans to be drawn across the chart.
- `set_visible_range` method, which will set the visible range of the chart based on two given dates.
- `resize` method, which resizes the chart to the given size.
- `sync` will now sync both charts, regardless of which one is scrolled/zoomed.
  • Loading branch information
louisnw01 committed Aug 31, 2023
1 parent 769fd8a commit a7c1dc8
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 69 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ lightweight-charts-python aims to provide a simple and pythonic way to access an
```
pip install lightweight-charts
```
* White screen? Having issues with pywebview? Click [here](https://github.com/louisnw01/lightweight-charts-python/issues?q=label%3A%22pywebview+issue%22+).
___

## Features
1. Streamlined for live data, with methods for updating directly from tick data.
2. Multi-pane charts using [Subcharts](https://lightweight-charts-python.readthedocs.io/en/latest/common_methods.html#create-subchart-subchart).
3. The [Toolbox](https://lightweight-charts-python.readthedocs.io/en/latest/toolbox.html), allowing for trendlines, rays and horizontal lines to be drawn directly onto charts.
4. [Callbacks](https://lightweight-charts-python.readthedocs.io/en/latest/callbacks.html) allowing for timeframe selectors (1min, 5min, 30min etc.), searching, hotkeys, and more.
5. [Tables](https://lightweight-charts-python.readthedocs.io/en/latest/tables.html) for watchlists, order entry, and trade management.
2. Multi-pane charts using [Subcharts](https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart.html#AbstractChart.create_subchart).
3. The [Toolbox](https://lightweight-charts-python.readthedocs.io/en/latest/reference/toolbox.html), allowing for trendlines, rays and horizontal lines to be drawn directly onto charts.
4. [Events](https://lightweight-charts-python.readthedocs.io/en/latest/tutorials/events.html) allowing for timeframe selectors (1min, 5min, 30min etc.), searching, hotkeys, and more.
5. [Tables](https://lightweight-charts-python.readthedocs.io/en/latest/reference/tables.html) for watchlists, order entry, and trade management.
6. Direct integration of market data through [Polygon.io's](https://polygon.io/?utm_source=affiliate&utm_campaign=pythonlwcharts) market data API.

__Supports:__ Jupyter Notebooks, PyQt5, PySide6, wxPython, Streamlit, and asyncio.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
project = 'lightweight-charts-python'
copyright = '2023, louisnw'
author = 'louisnw'
release = '1.0.17'
release = '1.0.17.1'

extensions = [
"myst_parser",
Expand Down
87 changes: 60 additions & 27 deletions docs/source/reference/abstract_chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ ___
```{py:function} lines() -> List[Line]
```{py:method} lines() -> List[Line]
Returns a list of all lines for the chart.
Expand All @@ -76,7 +76,7 @@ ___
```{py:function} trend_line(start_time: str | datetime, start_value: NUM, end_time: str | datetime, end_value: NUM, color: COLOR, width: int) -> Line
```{py:method} trend_line(start_time: str | datetime, start_value: NUM, end_time: str | datetime, end_value: NUM, color: COLOR, width: int) -> Line
Creates a trend line, drawn from the first point (`start_time`, `start_value`) to the last point (`end_time`, `end_value`).
Expand All @@ -85,7 +85,7 @@ ___
```{py:function} ray_line(start_time: str | datetime, value: NUM, color: COLOR, width: int) -> Line
```{py:method} ray_line(start_time: str | datetime, value: NUM, color: COLOR, width: int) -> Line
Creates a ray line, drawn from the first point (`start_time`, `value`) and onwards.
Expand All @@ -94,7 +94,39 @@ ___
```{py:function} marker(time: datetime, position: MARKER_POSITION, shape: MARKER_SHAPE, color: COLOR, text: str) -> str
```{py:method} vertical_span(start_time: TIME, end_time: TIME = None, color: COLOR = 'rgba(252, 219, 3, 0.2)')
Creates and returns a `VerticalSpan` object.
If `end_time` is not given, then a single vertical line will be placed at `start_time`.
This should be used after calling [`set`](#AbstractChart.set).
```
___
```{py:method} set_visible_range(self, start_time: TIME, end_time: TIME)
Sets the visible range of the chart.
```
___
```{py:method} resize(self, width: float = None, height: float = None)
Resizes the chart within the window.
Dimensions should be given as a float between or equal to 0 and 1.
Both `width` and `height` do not need to be provided if only one axis is to be changed.
```
___
```{py:method} marker(time: datetime, position: MARKER_POSITION, shape: MARKER_SHAPE, color: COLOR, text: str) -> str
Adds a marker to the chart, and returns its id.
Expand All @@ -107,7 +139,7 @@ ___
```{py:function} remove_marker(marker_id: str)
```{py:method} remove_marker(marker_id: str)
Removes the marker with the given id.
Expand All @@ -116,7 +148,7 @@ ___
```{py:function} horizontal_line(price: NUM, color: COLOR, width: int, style: LINE_STYLE, text: str, axis_label_visible: bool, func: callable= None) -> HorizontalLine
```{py:method} horizontal_line(price: NUM, color: COLOR, width: int, style: LINE_STYLE, text: str, axis_label_visible: bool, func: callable= None) -> HorizontalLine
Places a horizontal line at the given price, and returns a [`HorizontalLine`] object.
Expand All @@ -127,31 +159,31 @@ ___
```{py:function} remove_horizontal_line(price: NUM)
```{py:method} remove_horizontal_line(price: NUM)
Removes a horizontal line at the given price.
```
___
```{py:function} clear_markers()
```{py:method} clear_markers()
Clears the markers displayed on the data.
```
___
```{py:function} clear_horizontal_lines
```{py:method} clear_horizontal_lines()
Clears the horizontal lines displayed on the data.
```
___
```{py:function} precision(precision: int)
```{py:method} precision(precision: int)
Sets the precision of the chart based on the given number of decimal places.
Expand All @@ -160,47 +192,47 @@ ___
```{py:function} price_scale(mode: PRICE_SCALE_MODE, align_labels: bool, border_visible: bool, border_color: COLOR, text_color: COLOR, entire_text_only: bool, ticks_visible: bool, scale_margin_top: float, scale_margin_bottom: float)
```{py:method} price_scale(mode: PRICE_SCALE_MODE, align_labels: bool, border_visible: bool, border_color: COLOR, text_color: COLOR, entire_text_only: bool, ticks_visible: bool, scale_margin_top: float, scale_margin_bottom: float)
Price scale options for the chart.
```
___
```{py:function} time_scale(right_offset: int, min_bar_spacing: float, visible: bool, time_visible: bool, seconds_visible: bool, border_visible: bool, border_color: COLOR)
```{py:method} time_scale(right_offset: int, min_bar_spacing: float, visible: bool, time_visible: bool, seconds_visible: bool, border_visible: bool, border_color: COLOR)
Timescale options for the chart.
```
___
```{py:function} layout(background_color: COLOR, text_color: COLOR, font_size: int, font_family: str)
```{py:method} layout(background_color: COLOR, text_color: COLOR, font_size: int, font_family: str)
Global layout options for the chart.
```
___
```{py:function} grid(vert_enabled: bool, horz_enabled: bool, color: COLOR, style: LINE_STYLE)
```{py:method} grid(vert_enabled: bool, horz_enabled: bool, color: COLOR, style: LINE_STYLE)
Grid options for the chart.
```
___
```{py:function} candle_style(up_color: COLOR, down_color: COLOR, wick_enabled: bool, border_enabled: bool, border_up_color: COLOR, border_down_color: COLOR, wick_up_color: COLOR, wick_down_color: COLOR)
```{py:method} candle_style(up_color: COLOR, down_color: COLOR, wick_enabled: bool, border_enabled: bool, border_up_color: COLOR, border_down_color: COLOR, wick_up_color: COLOR, wick_down_color: COLOR)
Candle styling for each of the candle's parts (border, wick).
```
___
```{py:function} volume_config(scale_margin_top: float, scale_margin_bottom: float, up_color: COLOR, down_color: COLOR)
```{py:method} volume_config(scale_margin_top: float, scale_margin_bottom: float, up_color: COLOR, down_color: COLOR)
Volume config options.
Expand All @@ -211,31 +243,31 @@ ___
```{py:function} crosshair(mode, vert_visible: bool, vert_width: int, vert_color: COLOR, vert_style: LINE_STYLE, vert_label_background_color: COLOR, horz_visible: bool, horz_width: int, horz_color: COLOR, horz_style: LINE_STYLE, horz_label_background_color: COLOR)
```{py:method} crosshair(mode, vert_visible: bool, vert_width: int, vert_color: COLOR, vert_style: LINE_STYLE, vert_label_background_color: COLOR, horz_visible: bool, horz_width: int, horz_color: COLOR, horz_style: LINE_STYLE, horz_label_background_color: COLOR)
Crosshair formatting for its vertical and horizontal axes.
```
___
```{py:function} watermark(text: str, font_size: int, color: COLOR)
```{py:method} watermark(text: str, font_size: int, color: COLOR)
Overlays a watermark on top of the chart.
```
___
```{py:function} legend(visible: bool, ohlc: bool, percent: bool, lines: bool, color: COLOR, font_size: int, font_family: str)
```{py:method} legend(visible: bool, ohlc: bool, percent: bool, lines: bool, color: COLOR, font_size: int, font_family: str)
Configures the legend of the chart.
```
___
```{py:function} spinner(visible: bool)
```{py:method} spinner(visible: bool)
Shows a loading spinner on the chart, which can be used to visualise the loading of large datasets, API calls, etc.
Expand All @@ -246,39 +278,39 @@ ___
```{py:function} price_line(label_visible: bool, line_visible: bool, title: str)
```{py:method} price_line(label_visible: bool, line_visible: bool, title: str)
Configures the visibility of the last value price line and its label.
```
___
```{py:function} fit()
```{py:method} fit()
Attempts to fit all data displayed on the chart within the viewport (`fitContent()`).
```
___
```{py:function} show_data()
```{py:method} show_data()
Shows the hidden candles on the chart.
```
___
```{py:function} hide_data()
```{py:method} hide_data()
Hides the candles on the chart.
```
___
```{py:function} hotkey(modifier: 'ctrl' | 'alt' | 'shift' | 'meta', key: 'str' | 'int' | 'tuple', func: callable)
```{py:method} hotkey(modifier: 'ctrl' | 'alt' | 'shift' | 'meta', key: 'str' | 'int' | 'tuple', func: callable)
Adds a global hotkey to the chart window, which will execute the method or function given.
Expand All @@ -288,7 +320,7 @@ ___
```{py:function} create_table(width: NUM, height: NUM, headings: Tuple[str], widths: Tuple[float], alignments: Tuple[str], position: FLOAT, draggable: bool, func: callable) -> Table
```{py:method} create_table(width: NUM, height: NUM, headings: Tuple[str], widths: Tuple[float], alignments: Tuple[str], position: FLOAT, draggable: bool, func: callable) -> Table
Creates and returns a [`Table`](https://lightweight-charts-python.readthedocs.io/en/latest/tables.html) object.
Expand All @@ -297,7 +329,7 @@ ___
````{py:function} create_subchart(position: FLOAT, width: float, height: float, sync: bool | str, scale_candles_only: bool, toolbox: bool) -> AbstractChart
````{py:method} create_subchart(position: FLOAT, width: float, height: float, sync: bool | str, scale_candles_only: bool, toolbox: bool) -> AbstractChart
Creates and returns a Chart object, placing it adjacent to the previous Chart. This allows for the use of multiple chart panels within the same window.
Expand All @@ -316,6 +348,7 @@ Creates and returns a Chart object, placing it adjacent to the previous Chart. T
Charts are arranged horizontally from left to right. When the available space is no longer sufficient, the subsequent Chart will be positioned on a new row, starting from the left side.
[Subchart examples](../examples/subchart.md)
````
`````
Expand Down
4 changes: 3 additions & 1 deletion docs/source/reference/charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ They inherit from [AbstractChart](#AbstractChart).

___

`````{py:class} Chart(width: int, height: int, x: int, y: int, on_top: bool, maximize: bool, debug: bool, toolbox: bool, inner_width: float, inner_height: float, scale_candles_only: bool)
`````{py:class} Chart(width: int, height: int, x: int, y: int, screen: int, on_top: bool, maximize: bool, debug: bool, toolbox: bool, inner_width: float, inner_height: float, scale_candles_only: bool)
The main object used for the normal functionality of lightweight-charts-python, built on the pywebview library.
The `screen` parameter defines which monitor the chart window will open on, given as an index (primary monitor = 0).
```{important}
The `Chart` object should be defined within an `if __name__ == '__main__'` block.
```
Expand Down
6 changes: 3 additions & 3 deletions docs/source/reference/line.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ___
```{py:function} set(data: pd.DataFrame)
```{py:method} set(data: pd.DataFrame)
Sets the data for the line.
Expand All @@ -25,7 +25,7 @@ ___
```{py:function} update(series: pd.Series)
```{py:method} update(series: pd.Series)
Updates the data for the line.
Expand All @@ -36,7 +36,7 @@ This should be given as a Series object, with labels akin to the `line.set()` fu
___
```{py:function} line.delete()
```{py:method} line.delete()
Irreversibly deletes the line.
Expand Down
2 changes: 2 additions & 0 deletions docs/source/tutorials/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pip install lightweight-charts

Pywebview's installation can differ depending on OS. Please refer to their [documentation](https://pywebview.flowrl.com/guide/installation.html#installation).

When using Docker or WSL, you may need to update your language tags; see [this](https://github.com/louisnw01/lightweight-charts-python/issues/63#issuecomment-1670473651) issue.

___

## A simple static chart
Expand Down
Loading

0 comments on commit a7c1dc8

Please sign in to comment.