From f7c80bf3a997f1b5101d4c247ab39a39ee2b775a Mon Sep 17 00:00:00 2001 From: David Brazda Date: Thu, 13 Jun 2024 13:57:42 +0200 Subject: [PATCH] horizontal session divider in helpers --- lightweight_charts/helpers.py | 8 ++++++-- setup.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lightweight_charts/helpers.py b/lightweight_charts/helpers.py index 247306a..6f6ccbb 100644 --- a/lightweight_charts/helpers.py +++ b/lightweight_charts/helpers.py @@ -72,7 +72,7 @@ class Panel: self.xloc = xloc -def chart(panes: list[Panel], sync=False, title='', size="m", xloc=None): +def chart(panes: list[Panel], sync=False, title='', size="m", xloc=None, session: str="9:30"): """ Function to fast render a chart with multiple panes. This function manipulates graphical output or interfaces with an external framework to display charts with synchronized @@ -93,6 +93,8 @@ def chart(panes: list[Panel], sync=False, title='', size="m", xloc=None): - 'm' for medium - 'xl' for extra large + * session (str): Draw session vertical divider at that time. Defaults to '9:30'. Can be any time in 24-hour format or xloc slice + * xloc (str): xloc advanced filtering of vbt.xloc accessor. Defaults to None. Applies to all panes. Might be overriden by pane-specific xloc. @@ -131,7 +133,7 @@ def chart(panes: list[Panel], sync=False, title='', size="m", xloc=None): middle2=[], histogram=[(order_imbalance_sma, "oisma")] ) - ch = chart([pane1, pane2], sync=True, title="Chart", size="l", xloc=slice("2024-02-12 09:30","2024-02-12 16:00")) + ch = chart([pane1, pane2], sync=True, title="Chart", size="l", xloc=slice("2024-02-12 09:30","2024-02-12 16:00"), session="9:30") ``` Notes: @@ -221,6 +223,8 @@ def chart(panes: list[Panel], sync=False, title='', size="m", xloc=None): active_chart.legend(True) active_chart.fit() + if session is not None and session: + active_chart.vertical_span(start_time=xloc_me(series, xloc).vbt.xloc[session].obj.index.to_list(), color="rgba(252, 219, 3, 0.4)") if not main_title_set: chartX.topbar.textbox("title",title) diff --git a/setup.py b/setup.py index 89132a9..b484fb8 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open('README.md', 'r', encoding='utf-8') as f: setup( name='lightweight_charts', - version='2.0.19', + version='2.1.0', packages=find_packages(), python_requires='>=3.8', install_requires=[