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:
BIN
examples/6_async/async.gif
Normal file
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
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
56
examples/6_async/async.py
Normal 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())
|
||||
2084
examples/6_async/bar_data/AAPL_1min.csv
Normal file
2084
examples/6_async/bar_data/AAPL_1min.csv
Normal file
File diff suppressed because it is too large
Load Diff
2371
examples/6_async/bar_data/AAPL_30min.csv
Normal file
2371
examples/6_async/bar_data/AAPL_30min.csv
Normal file
File diff suppressed because it is too large
Load Diff
1780
examples/6_async/bar_data/AAPL_5min.csv
Normal file
1780
examples/6_async/bar_data/AAPL_5min.csv
Normal file
File diff suppressed because it is too large
Load Diff
2085
examples/6_async/bar_data/GOOGL_1min.csv
Normal file
2085
examples/6_async/bar_data/GOOGL_1min.csv
Normal file
File diff suppressed because it is too large
Load Diff
2371
examples/6_async/bar_data/GOOGL_30min.csv
Normal file
2371
examples/6_async/bar_data/GOOGL_30min.csv
Normal file
File diff suppressed because it is too large
Load Diff
1780
examples/6_async/bar_data/GOOGL_5min.csv
Normal file
1780
examples/6_async/bar_data/GOOGL_5min.csv
Normal file
File diff suppressed because it is too large
Load Diff
2087
examples/6_async/bar_data/TSLA_1min.csv
Normal file
2087
examples/6_async/bar_data/TSLA_1min.csv
Normal file
File diff suppressed because it is too large
Load Diff
2371
examples/6_async/bar_data/TSLA_30min.csv
Normal file
2371
examples/6_async/bar_data/TSLA_30min.csv
Normal file
File diff suppressed because it is too large
Load Diff
1802
examples/6_async/bar_data/TSLA_5min.csv
Normal file
1802
examples/6_async/bar_data/TSLA_5min.csv
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 633 KiB |
@ -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
Reference in New Issue
Block a user