- 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:
louisnw
2023-08-27 00:20:05 +01:00
parent 34ce3f7199
commit f72baf95ba
49 changed files with 43156 additions and 1895 deletions

View File

@ -0,0 +1,48 @@
# YFinance
```python
import datetime as dt
import yfinance as yf
from lightweight_charts import Chart
def get_bar_data(symbol, timeframe):
if timeframe in ('1m', '5m', '30m'):
days = 7 if timeframe == '1m' else 60
start_date = dt.datetime.now()-dt.timedelta(days=days)
else:
start_date = None
chart.spinner(True)
data = yf.download(symbol, start_date, interval=timeframe)
chart.spinner(False)
if data.empty:
return False
chart.set(data)
return True
def on_search(chart, searched_string):
if get_bar_data(searched_string, chart.topbar['timeframe'].value):
chart.topbar['symbol'].set(searched_string)
def on_timeframe_selection(chart):
get_bar_data(chart.topbar['symbol'].value, chart.topbar['timeframe'].value)
if __name__ == '__main__':
chart = Chart(toolbox=True, debug=True)
chart.legend(True)
chart.events.search += on_search
chart.topbar.textbox('symbol', 'n/a')
chart.topbar.switcher(
'timeframe',
('1m', '5m', '30m', '1d', '1wk'),
default='5m',
func=on_timeframe_selection
)
chart.show(block=True)
```