tbapi.api.interfaces.ichart
1from __future__ import annotations 2from typing import TYPE_CHECKING 3from tbapi.common.decorators import tb_interface 4from tbapi.common.converters import to_python_datetime, to_net_datetime 5from datetime import datetime 6from Tickblaze.Scripts.Api.Interfaces import IChart as _IChart 7from typing import Any, overload 8from abc import ABC, abstractmethod 9from tbapi.api.interfaces.isize import ISize 10if TYPE_CHECKING: 11 from tbapi.api.models.color import Color 12 13@tb_interface(_IChart) 14class IChart(ISize): 15 """Represents a chart that displays financial data.""" 16 17 @property 18 def bar_width(self) -> float: 19 """The width of the bar as a value between 0.0 and 1.0 which defines the fraction of available space each bar should occupy.""" 20 val = self._value.BarWidth 21 return val 22 @bar_width.setter 23 def bar_width(self, val: float): 24 tmp = self._value 25 tmp.BarWidth = val 26 self._value = tmp 27 @property 28 def datapoint_width(self) -> float: 29 """Gets the data-point width, which is the width of one data-point in pixels on the axis.""" 30 val = self._value.DatapointWidth 31 return val 32 @property 33 def background_color(self) -> Color: 34 """Gets the panel background color.""" 35 from tbapi.api.models.color import Color 36 val = self._value.BackgroundColor 37 return Color(_existing=val) 38 @property 39 def text_color(self) -> Color: 40 """Gets the panel text color.""" 41 from tbapi.api.models.color import Color 42 val = self._value.TextColor 43 return Color(_existing=val) 44 @property 45 def first_visible_bar_index(self) -> int: 46 """The index of the first visible bar on the chart.""" 47 val = self._value.FirstVisibleBarIndex 48 return val 49 @property 50 def last_visible_bar_index(self) -> int: 51 """The index of the last visible bar on the chart.""" 52 val = self._value.LastVisibleBarIndex 53 return val 54 55 @abstractmethod 56 def format_time(self, time: datetime) -> str: 57 """Formats the given datetime into a string representation. The datetime value to format. A string representing the formatted datetime.""" 58 result = self._value.FormatTime(to_net_datetime(time)) 59 return result 60 61 @abstractmethod 62 def get_xcoordinate_by_bar_index(self, bar_index: int) -> float: 63 """Gets the X coordinate by the given bar index. The index of the bar. The X coordinate corresponding to the specified bar index.""" 64 result = self._value.GetXCoordinateByBarIndex(bar_index) 65 return result 66 67 @abstractmethod 68 def get_xcoordinate_by_time(self, time: datetime) -> float: 69 """Gets the X coordinate by the specified time. The time to get the X coordinate for. The X coordinate corresponding to the specified time.""" 70 result = self._value.GetXCoordinateByTime(to_net_datetime(time)) 71 return result 72 73 @abstractmethod 74 def get_time_by_xcoordinate(self, x: float) -> datetime: 75 """Gets the time value by the specified X coordinate. The X coordinate to get the time value for. The time value corresponding to the specified X coordinate.""" 76 result = self._value.GetTimeByXCoordinate(x) 77 return to_python_datetime(result) 78 79 @abstractmethod 80 def get_bar_index_by_xcoordinate(self, x: float) -> int: 81 """Gets the bar index by the specified X coordinate. The X coordinate to get the bar index for. The bar index corresponding to the specified X coordinate.""" 82 result = self._value.GetBarIndexByXCoordinate(x) 83 return result 84 85 @abstractmethod 86 def get_bar_index_by_time(self, time: datetime) -> int: 87 """Gets the bar index by the specified time. The time to get the bar index for. The bar index corresponding to the specified time.""" 88 result = self._value.GetBarIndexByTime(to_net_datetime(time)) 89 return result 90
19@tb_interface(_IChart) 20class IChart(ISize): 21 """Represents a chart that displays financial data.""" 22 23 @property 24 def bar_width(self) -> float: 25 """The width of the bar as a value between 0.0 and 1.0 which defines the fraction of available space each bar should occupy.""" 26 val = self._value.BarWidth 27 return val 28 @bar_width.setter 29 def bar_width(self, val: float): 30 tmp = self._value 31 tmp.BarWidth = val 32 self._value = tmp 33 @property 34 def datapoint_width(self) -> float: 35 """Gets the data-point width, which is the width of one data-point in pixels on the axis.""" 36 val = self._value.DatapointWidth 37 return val 38 @property 39 def background_color(self) -> Color: 40 """Gets the panel background color.""" 41 from tbapi.api.models.color import Color 42 val = self._value.BackgroundColor 43 return Color(_existing=val) 44 @property 45 def text_color(self) -> Color: 46 """Gets the panel text color.""" 47 from tbapi.api.models.color import Color 48 val = self._value.TextColor 49 return Color(_existing=val) 50 @property 51 def first_visible_bar_index(self) -> int: 52 """The index of the first visible bar on the chart.""" 53 val = self._value.FirstVisibleBarIndex 54 return val 55 @property 56 def last_visible_bar_index(self) -> int: 57 """The index of the last visible bar on the chart.""" 58 val = self._value.LastVisibleBarIndex 59 return val 60 61 @abstractmethod 62 def format_time(self, time: datetime) -> str: 63 """Formats the given datetime into a string representation. The datetime value to format. A string representing the formatted datetime.""" 64 result = self._value.FormatTime(to_net_datetime(time)) 65 return result 66 67 @abstractmethod 68 def get_xcoordinate_by_bar_index(self, bar_index: int) -> float: 69 """Gets the X coordinate by the given bar index. The index of the bar. The X coordinate corresponding to the specified bar index.""" 70 result = self._value.GetXCoordinateByBarIndex(bar_index) 71 return result 72 73 @abstractmethod 74 def get_xcoordinate_by_time(self, time: datetime) -> float: 75 """Gets the X coordinate by the specified time. The time to get the X coordinate for. The X coordinate corresponding to the specified time.""" 76 result = self._value.GetXCoordinateByTime(to_net_datetime(time)) 77 return result 78 79 @abstractmethod 80 def get_time_by_xcoordinate(self, x: float) -> datetime: 81 """Gets the time value by the specified X coordinate. The X coordinate to get the time value for. The time value corresponding to the specified X coordinate.""" 82 result = self._value.GetTimeByXCoordinate(x) 83 return to_python_datetime(result) 84 85 @abstractmethod 86 def get_bar_index_by_xcoordinate(self, x: float) -> int: 87 """Gets the bar index by the specified X coordinate. The X coordinate to get the bar index for. The bar index corresponding to the specified X coordinate.""" 88 result = self._value.GetBarIndexByXCoordinate(x) 89 return result 90 91 @abstractmethod 92 def get_bar_index_by_time(self, time: datetime) -> int: 93 """Gets the bar index by the specified time. The time to get the bar index for. The bar index corresponding to the specified time.""" 94 result = self._value.GetBarIndexByTime(to_net_datetime(time)) 95 return result
Represents a chart that displays financial data.
23 @property 24 def bar_width(self) -> float: 25 """The width of the bar as a value between 0.0 and 1.0 which defines the fraction of available space each bar should occupy.""" 26 val = self._value.BarWidth 27 return val
The width of the bar as a value between 0.0 and 1.0 which defines the fraction of available space each bar should occupy.
33 @property 34 def datapoint_width(self) -> float: 35 """Gets the data-point width, which is the width of one data-point in pixels on the axis.""" 36 val = self._value.DatapointWidth 37 return val
Gets the data-point width, which is the width of one data-point in pixels on the axis.
38 @property 39 def background_color(self) -> Color: 40 """Gets the panel background color.""" 41 from tbapi.api.models.color import Color 42 val = self._value.BackgroundColor 43 return Color(_existing=val)
Gets the panel background color.
44 @property 45 def text_color(self) -> Color: 46 """Gets the panel text color.""" 47 from tbapi.api.models.color import Color 48 val = self._value.TextColor 49 return Color(_existing=val)
Gets the panel text color.
50 @property 51 def first_visible_bar_index(self) -> int: 52 """The index of the first visible bar on the chart.""" 53 val = self._value.FirstVisibleBarIndex 54 return val
The index of the first visible bar on the chart.
55 @property 56 def last_visible_bar_index(self) -> int: 57 """The index of the last visible bar on the chart.""" 58 val = self._value.LastVisibleBarIndex 59 return val
The index of the last visible bar on the chart.
61 @abstractmethod 62 def format_time(self, time: datetime) -> str: 63 """Formats the given datetime into a string representation. The datetime value to format. A string representing the formatted datetime.""" 64 result = self._value.FormatTime(to_net_datetime(time)) 65 return result
Formats the given datetime into a string representation. The datetime value to format. A string representing the formatted datetime.
67 @abstractmethod 68 def get_xcoordinate_by_bar_index(self, bar_index: int) -> float: 69 """Gets the X coordinate by the given bar index. The index of the bar. The X coordinate corresponding to the specified bar index.""" 70 result = self._value.GetXCoordinateByBarIndex(bar_index) 71 return result
Gets the X coordinate by the given bar index. The index of the bar. The X coordinate corresponding to the specified bar index.
73 @abstractmethod 74 def get_xcoordinate_by_time(self, time: datetime) -> float: 75 """Gets the X coordinate by the specified time. The time to get the X coordinate for. The X coordinate corresponding to the specified time.""" 76 result = self._value.GetXCoordinateByTime(to_net_datetime(time)) 77 return result
Gets the X coordinate by the specified time. The time to get the X coordinate for. The X coordinate corresponding to the specified time.
79 @abstractmethod 80 def get_time_by_xcoordinate(self, x: float) -> datetime: 81 """Gets the time value by the specified X coordinate. The X coordinate to get the time value for. The time value corresponding to the specified X coordinate.""" 82 result = self._value.GetTimeByXCoordinate(x) 83 return to_python_datetime(result)
Gets the time value by the specified X coordinate. The X coordinate to get the time value for. The time value corresponding to the specified X coordinate.
85 @abstractmethod 86 def get_bar_index_by_xcoordinate(self, x: float) -> int: 87 """Gets the bar index by the specified X coordinate. The X coordinate to get the bar index for. The bar index corresponding to the specified X coordinate.""" 88 result = self._value.GetBarIndexByXCoordinate(x) 89 return result
Gets the bar index by the specified X coordinate. The X coordinate to get the bar index for. The bar index corresponding to the specified X coordinate.
91 @abstractmethod 92 def get_bar_index_by_time(self, time: datetime) -> int: 93 """Gets the bar index by the specified time. The time to get the bar index for. The bar index corresponding to the specified time.""" 94 result = self._value.GetBarIndexByTime(to_net_datetime(time)) 95 return result
Gets the bar index by the specified time. The time to get the bar index for. The bar index corresponding to the specified time.