Polygon:
- Added async methods to polygon. - The `requests` library is no longer required, with `urllib` being used instead. - Added the `get_bar_data` function, which returns a dataframe of aggregate data from polygon. - Opened up the `subscribe` and `unsubscribe` functions Enhancements: - Tables will now scroll when the rows exceed table height. Bugs: - Fixed a bug preventing async functions being used with horizontal line event. - Fixed a bug causing the legend to show duplicate lines if the line was created after the legend. - Fixed a bug causing the line hide icon to persist within the legend after deletion (#75) - Fixed a bug causing the search box to be unfocused when the chart is loaded.
This commit is contained in:
@ -1,14 +1,11 @@
|
||||
# Polygon.io
|
||||
|
||||
[Polygon.io's](https://polygon.io/?utm_source=affiliate&utm_campaign=pythonlwcharts) 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/common_methods.html), and can be accessed from within any chart type.
|
||||
|
||||
````{py:class} PolygonAPI
|
||||
This class should be accessed from the `polygon` attribute, which is contained within all chart types.
|
||||
|
||||
`chart.polygon.<method>`
|
||||
|
||||
@ -21,14 +18,15 @@ The `stock`, `option`, `index`, `forex`, and `crypto` methods of `chart.polygon`
|
||||
* `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.
|
||||
|
||||
The `websockets` library is required when using live data.
|
||||
|
||||
```{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:
|
||||
For Example:
|
||||
|
||||
```python
|
||||
from lightweight_charts import Chart
|
||||
@ -43,67 +41,90 @@ if __name__ == '__main__':
|
||||
)
|
||||
chart.show(block=True)
|
||||
```
|
||||
|
||||
___
|
||||
|
||||
### `api_key`
|
||||
`key: str`
|
||||
|
||||
```{py:method} 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`
|
||||
|
||||
|
||||
|
||||
```{py:method} 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.
|
||||
|
||||
`async_stock` can also be used.
|
||||
```
|
||||
___
|
||||
|
||||
### `option`
|
||||
`symbol: str` | `timeframe: str` | `start_date: str` | `expiration` | `right: 'C' | 'P'` | `strike: int | float` | `end_date: str` | `limit: int` | `live: bool` | `-> bool`
|
||||
|
||||
|
||||
```{py:method} option(symbol: str, timeframe: str, expiration: str, right: 'C' | 'P', strike: NUM, 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.
|
||||
|
||||
`async_option` can also be used.
|
||||
|
||||
```
|
||||
___
|
||||
|
||||
### `index`
|
||||
`symbol: str` | `timeframe: str` | `start_date: str` | `end_date: str` | `limit: int` | `live: bool` | `-> bool`
|
||||
|
||||
|
||||
```{py:method} 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.
|
||||
|
||||
`async_index` can also be used.
|
||||
```
|
||||
___
|
||||
|
||||
### `forex`
|
||||
`fiat_pair: str` | `timeframe: str` | `start_date: str` | `end_date: str` | `limit: int` | `live: bool` | `-> bool`
|
||||
|
||||
|
||||
```{py:method} 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.).
|
||||
|
||||
`async_forex` can also be used.
|
||||
```
|
||||
___
|
||||
|
||||
### `crypto`
|
||||
`crypto_pair: str` | `timeframe: str` | `start_date: str` | `end_date: str` | `limit: int` | `live: bool` | `-> bool`
|
||||
|
||||
|
||||
```{py:method} 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.).
|
||||
|
||||
`async_crypto` can also be used.
|
||||
```
|
||||
___
|
||||
|
||||
### `log`
|
||||
`info: bool`
|
||||
|
||||
|
||||
```{py:method} 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`
|
||||
|
||||
````{py:class} PolygonChart(api_key: str, num_bars: int, limit: int, end_date: str, timeframe_options: tuple, security_options: tuple, live: bool)
|
||||
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.
|
||||
This object requires the `websockets` library for live data.
|
||||
|
||||
All data is requested within the chart window through searching and selectors.
|
||||
|
||||
@ -118,18 +139,45 @@ As well as the parameters from the [Chart](https://lightweight-charts-python.rea
|
||||
* `live`: If True, the chart will update in real-time.
|
||||
___
|
||||
|
||||
### Example:
|
||||
For Example:
|
||||
|
||||
```python
|
||||
from lightweight_charts import PolygonChart
|
||||
|
||||
if __name__ == '__main__':
|
||||
chart = PolygonChart(api_key='<API-KEY>',
|
||||
num_bars=200,
|
||||
limit=5000,
|
||||
live=True)
|
||||
chart = PolygonChart(
|
||||
api_key='<API-KEY>',
|
||||
num_bars=200,
|
||||
limit=5000,
|
||||
live=True
|
||||
)
|
||||
chart.show(block=True)
|
||||
```
|
||||
|
||||

|
||||
|
||||
````
|
||||
|
||||
```{py:function} polygon.get_bar_data(ticker: str, timeframe: str, start_date: str, end_date: str, limit: int = 5_000) -> pd.DataFrame
|
||||
Module function which returns a formatted Dataframe of the requested aggregate data.
|
||||
|
||||
`ticker` should be prefixed for the appropriate security type (eg. `I:NDX`)
|
||||
|
||||
```
|
||||
|
||||
```{py:function} polygon.subscribe(ticker: str, sec_type: SEC_TYPE, func: callable, args: tuple, precision=2)
|
||||
:async:
|
||||
|
||||
Subscribes the given callable to live data from polygon. emitting a dictionary (and any given arguments) to the function.
|
||||
|
||||
```
|
||||
|
||||
```{py:function} polygon.unsubscribe(func: callable)
|
||||
:async:
|
||||
|
||||
Unsubscribes the given function from live data.
|
||||
|
||||
The ticker will only be unsubscribed if there are no additional functions that are currently subscribed.
|
||||
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user