v1.0.13
NEW FEATURE: Polygon.io Full integration - Added `polygon` to the common methods, allowing for data to be pulled from polygon.io. (`chart.polygon.<method>`) - Added the `PolygonChart` object, which allows for a plug and play solution with the Polygon API. - Check the docs for more details and examples! Enhancements: - Added `clear_markers` and `clear_horizontal_lines` to the common methods. - Added the `maximize` parameter to the `Chart` object, which maximizes the chart window when shown. - The Legend will now show Line values, and can be disabled using the `lines` parameter. - Added the `name` parameter to the `set` method of line, using the column within the dataframe as the value and using its name within the legend. - Added the `scale_candles_only` parameter to all Chart objects, which prevents the autoscaling of Lines. - new `screenshot` method, which returns a bytes object of the displayed chart. Fixes: - `chart.lines()` now returns a copy of the list rather than the original.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
project = 'lightweight-charts-python'
|
||||
copyright = '2023, louisnw'
|
||||
author = 'louisnw'
|
||||
release = '1.0.12'
|
||||
release = '1.0.13'
|
||||
|
||||
extensions = ["myst_parser"]
|
||||
|
||||
|
||||
@ -99,6 +99,16 @@ ___
|
||||
Removes a horizontal line at the given price.
|
||||
___
|
||||
|
||||
### `clear_markers`
|
||||
|
||||
Clears the markers displayed on the data.
|
||||
___
|
||||
|
||||
### `clear_horizontal_lines`
|
||||
|
||||
Clears the horizontal lines displayed on the data.
|
||||
___
|
||||
|
||||
### `price_scale`
|
||||
`mode: 'normal'/'logarithmic'/'percentage'/'index100'` | `align_labels: bool` | `border_visible: bool` | `border_color: str` | `text_color: str` | `entire_text_only: bool` | `ticks_visible: bool` | `scale_margin_top: float` | `scale_margin_bottom: float`
|
||||
|
||||
@ -169,7 +179,7 @@ Sets the title label for the chart.
|
||||
___
|
||||
|
||||
### `legend`
|
||||
`visible: bool` | `ohlc: bool` | `percent: bool` | `color: str` | `font_size: int` | `font_family: str`
|
||||
`visible: bool` | `ohlc: bool` | `percent: bool` | `lines: bool` | `color: str` | `font_size: int` | `font_family: str`
|
||||
|
||||
Configures the legend of the chart.
|
||||
___
|
||||
@ -201,7 +211,9 @@ ___
|
||||
Shows the hidden candles on the chart.
|
||||
___
|
||||
|
||||
|
||||
### `polygon`
|
||||
Used to access Polygon.io's API (see [here](https://lightweight-charts-python.readthedocs.io/en/latest/polygon.html))
|
||||
___
|
||||
|
||||
### `create_subchart`
|
||||
`volume_enabled: bool` | `position: 'left'/'right'/'top'/'bottom'`, `width: float` | `height: float` | `sync: bool/str` | `-> SubChart`
|
||||
@ -222,7 +234,7 @@ ___
|
||||
|
||||
|
||||
## Chart
|
||||
`volume_enabled: bool` | `width: int` | `height: int` | `x: int` | `y: int` | `on_top: bool` | `debug: bool` |
|
||||
`volume_enabled: bool` | `width: int` | `height: int` | `x: int` | `y: int` | `on_top: bool` | `maximize: bool` | `debug: bool` |
|
||||
`api: object` | `topbar: bool` | `searchbox: bool`
|
||||
|
||||
The main object used for the normal functionality of lightweight-charts-python, built on the pywebview library.
|
||||
@ -250,6 +262,27 @@ ___
|
||||
|
||||
Show the chart asynchronously. This should be utilised when using [Callbacks](#callbacks).
|
||||
|
||||
### `screenshot`
|
||||
`-> bytes`
|
||||
|
||||
Takes a screenshot of the chart, and returns a bytes object containing the image. For example:
|
||||
|
||||
```python
|
||||
if __name__ == '__main__':
|
||||
chart = Chart()
|
||||
df = pd.read_csv('ohlcv.csv')
|
||||
chart.set(df)
|
||||
chart.show()
|
||||
|
||||
img = chart.screenshot()
|
||||
with open('screenshot.png', 'wb') as f:
|
||||
f.write(img)
|
||||
```
|
||||
|
||||
```{important}
|
||||
This method must be called after the chart window is open.
|
||||
```
|
||||
|
||||
___
|
||||
|
||||
## Line
|
||||
@ -264,11 +297,21 @@ The `line` object should only be accessed from the [`create_line`](#create-line)
|
||||
___
|
||||
|
||||
### `set`
|
||||
`data: pd.DataFrame`
|
||||
`data: pd.DataFrame` `name: str`
|
||||
|
||||
Sets the data for the line.
|
||||
|
||||
This should be given as a DataFrame, with the columns: `time | value`
|
||||
When not using the `name` parameter, the columns should be named: `time | value`.
|
||||
|
||||
Otherwise, the method will use the column named after the string given in `name`. This name will also be used within the legend of the chart. For example:
|
||||
```python
|
||||
line = chart.create_line()
|
||||
|
||||
# DataFrame with columns: date | SMA 50
|
||||
df = pd.read_csv('sma50.csv')
|
||||
|
||||
line.set(df, name='SMA 50')
|
||||
```
|
||||
___
|
||||
|
||||
### `update`
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
```{toctree}
|
||||
:hidden:
|
||||
:caption: Contents
|
||||
:maxdepth: 3
|
||||
|
||||
docs
|
||||
polygon
|
||||
Github Repository <https://github.com/louisnw01/lightweight-charts-python>
|
||||
```
|
||||
|
||||
```{include} ../../README.md
|
||||
```
|
||||
|
||||
|
||||
135
docs/source/polygon.md
Normal file
135
docs/source/polygon.md
Normal file
@ -0,0 +1,135 @@
|
||||
# Polygon.io
|
||||
|
||||
[Polygon.io's](https://polygon.io) market data API is directly integrated within lightweight-charts-python, and is easy to use within the library.
|
||||
___
|
||||
## Requirements
|
||||
To use data from Polygon, there are certain libraries (not listed as requirements) that must be installed:
|
||||
* Static data requires the `requests` library.
|
||||
* Live data requires the `websockets` library.
|
||||
___
|
||||
## `polygon`
|
||||
`polygon` is a [Common Method](https://lightweight-charts-python.readthedocs.io/en/latest/docs.html#common-methods), and can be accessed from within any chart type.
|
||||
|
||||
`chart.polygon.<method>`
|
||||
|
||||
The `stock`, `option`, `index`, `forex`, and `crypto` methods of `chart.polygon` have common parameters:
|
||||
|
||||
* `timeframe`: The timeframe to be used (`'1min'`, `'5min'`, `'H'`, `'2D'`, `'5W'` etc.)
|
||||
* `start_date`: The start date given in the format `YYYY-MM-DD`.
|
||||
* `end_date`: The end date given in the same format. By default this is `'now'`, which uses the time now.
|
||||
* `limit`: The maximum number of base aggregates to be queried to create the aggregate results.
|
||||
* `live`: When set to `True`, a websocket connection will be used to update the chart or subchart in real-time.
|
||||
* These methods will also return a boolean representing whether the request was successful.
|
||||
|
||||
```{important}
|
||||
When using live data and the standard `show` method, the `block` parameter __must__ be set to `True` in order for the data to congregate on the chart (`chart.show(block=True)`).
|
||||
If `show_async` is used with live data, `block` can be either value.
|
||||
|
||||
```
|
||||
___
|
||||
|
||||
### Example:
|
||||
|
||||
```python
|
||||
from lightweight_charts import Chart
|
||||
|
||||
if __name__ == '__main__':
|
||||
chart = Chart()
|
||||
chart.polygon.api_key('<API-KEY>')
|
||||
chart.polygon.stock(
|
||||
symbol='AAPL',
|
||||
timeframe='5min',
|
||||
start_date='2023-06-09'
|
||||
)
|
||||
chart.show(block=True)
|
||||
```
|
||||
___
|
||||
|
||||
### `api_key`
|
||||
`key: str`
|
||||
|
||||
Sets the API key for the chart. Subsequent `SubChart` objects will inherit the API key given to the parent chart.
|
||||
___
|
||||
### `stock`
|
||||
`symbol: str` | `timeframe: str` | `start_date: str` | `end_date: str` | `limit: int` | `live: bool` | `-> bool`
|
||||
|
||||
Requests and displays stock data pulled from Polygon.io.
|
||||
___
|
||||
|
||||
### `option`
|
||||
`symbol: str` | `timeframe: str` | `start_date: str` | `expiration` | `right: 'C' | 'P'` | `strike: int | float` | `end_date: str` | `limit: int` | `live: bool` | `-> bool`
|
||||
|
||||
Requests and displays option data pulled from Polygon.io.
|
||||
|
||||
A formatted option ticker (SPY251219C00650000) can also be given to the `symbol` parameter, allowing for `expiration`, `right`, and `strike` to be left blank.
|
||||
___
|
||||
|
||||
### `index`
|
||||
`symbol: str` | `timeframe: str` | `start_date: str` | `end_date: str` | `limit: int` | `live: bool` | `-> bool`
|
||||
|
||||
Requests and displays index data pulled from Polygon.io.
|
||||
|
||||
___
|
||||
|
||||
### `forex`
|
||||
`fiat_pair: str` | `timeframe: str` | `start_date: str` | `end_date: str` | `limit: int` | `live: bool` | `-> bool`
|
||||
|
||||
Requests and displays a forex pair pulled from Polygon.io.
|
||||
|
||||
The two currencies should be separated by a '-' (`USD-CAD`, `GBP-JPY`, etc.).
|
||||
|
||||
___
|
||||
|
||||
### `crypto`
|
||||
`crypto_pair: str` | `timeframe: str` | `start_date: str` | `end_date: str` | `limit: int` | `live: bool` | `-> bool`
|
||||
|
||||
Requests and displays a crypto pair pulled from Polygon.io.
|
||||
|
||||
The two currencies should be separated by a '-' (`BTC-USD`, `ETH-BTC`, etc.).
|
||||
|
||||
___
|
||||
|
||||
### `log`
|
||||
`info: bool`
|
||||
|
||||
If `True`, informational log messages (connection, subscriptions etc.) will be displayed in the console.
|
||||
|
||||
Data errors will always be shown in the console.
|
||||
___
|
||||
|
||||
## PolygonChart
|
||||
|
||||
`api_key: str` | `live: bool` | `num_bars: int`
|
||||
|
||||
The `PolygonChart` provides an easy and complete way to use the Polygon.io API within lightweight-charts-python.
|
||||
|
||||
This object requires the `requests` library for static data, and the `websockets` library for live data.
|
||||
|
||||
All data is requested within the chart window through searching and selectors.
|
||||
|
||||
As well as the parameters from the CHART LINK object, PolygonChart also has the parameters:
|
||||
|
||||
* `api_key`: The user's Polygon.io API key.
|
||||
* `num_bars`: The target number of bars to be displayed on the chart
|
||||
* `limit`: The maximum number of base aggregates to be queried to create the aggregate results.
|
||||
* `end_date`: The end date of the time window.
|
||||
* `timeframe_options`: The selectors to be included within the timeframe selector.
|
||||
* `security_options`: The selectors to be included within the security selector.
|
||||
* `live`: If True, the chart will update in real-time.
|
||||
___
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from lightweight_charts import PolygonChart
|
||||
|
||||
if __name__ == '__main__':
|
||||
chart = PolygonChart(api_key='<API-KEY>',
|
||||
num_bars=200,
|
||||
limit=5000,
|
||||
live=True)
|
||||
chart.show(block=True)
|
||||
```
|
||||
|
||||

|
||||
|
||||
BIN
docs/source/polygonchart.png
Normal file
BIN
docs/source/polygonchart.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 124 KiB |
Reference in New Issue
Block a user