New Feature: ChartAsync

- Added the ChartAsync class, allowing for more sophisticated Charts and SubCharts.
- Symbol searching, timeframe selectors, and more is now possible with this varation of Chart.

`QtChart` and `WxChart` have access to all the methods that `ChartAsync` has, however they utilize their own respective event loops rather than asyncio.

New Feature: `StreamlitChart`
- Chart window that can display static data within a Streamlit application.

Removed the `subscribe_click` method.
This commit is contained in:
louisnw
2023-05-29 21:31:13 +01:00
parent 39e40334d5
commit a58f1e306c
24 changed files with 19390 additions and 3143 deletions

BIN
examples/6_async/async.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

BIN
examples/6_async/async.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 504 KiB

56
examples/6_async/async.py Normal file
View File

@ -0,0 +1,56 @@
import asyncio
import pandas as pd
from lightweight_charts import ChartAsync
def get_bar_data(symbol, timeframe):
return pd.read_csv(f'bar_data/{symbol}_{timeframe}.csv')
class API:
def __init__(self):
self.chart = None # Changes after each callback.
self.symbol = 'TSLA'
self.timeframe = '5min'
async def on_search(self, searched_string): # Called when the user searches.
self.symbol = searched_string
new_data = await self.get_data()
if new_data.empty:
return
self.chart.set(new_data)
self.chart.corner_text(searched_string)
async def on_timeframe_selection(self, timeframe): # Called when the user changes the timeframe.
self.timeframe = timeframe
new_data = await self.get_data()
if new_data.empty:
return
self.chart.set(new_data)
async def get_data(self):
if self.symbol not in ('AAPL', 'GOOGL', 'TSLA'):
print(f'No data for "{self.symbol}"')
return pd.DataFrame()
data = get_bar_data(self.symbol, self.timeframe)
return data
async def main():
api = API()
chart = ChartAsync(api=api, debug=True)
chart.legend(True)
chart.create_switcher(api.on_timeframe_selection, '1min', '5min', '30min', default='5min')
chart.corner_text(api.symbol)
df = get_bar_data(api.symbol, api.timeframe)
chart.set(df)
await chart.show(block=True)
if __name__ == '__main__':
asyncio.run(main())

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 633 KiB

View File

@ -1,18 +0,0 @@
import pandas as pd
from lightweight_charts import Chart
def on_click(bar: dict):
print(f"Time: {bar['time']} | Close: {bar['close']}")
if __name__ == '__main__':
chart = Chart()
df = pd.read_csv('ohlcv.csv')
chart.set(df)
chart.subscribe_click(on_click)
chart.show(block=True)

File diff suppressed because it is too large Load Diff