tbapi.api.models.bar_series
1from __future__ import annotations 2from typing import TYPE_CHECKING 3from tbapi.common.decorators import tb_class, tb_interface 4from tbapi.common.converters import to_python_datetime, to_net_datetime 5from datetime import datetime 6from Tickblaze.Scripts.Api.Models import BarSeries as _BarSeries 7from typing import Any, overload 8from abc import ABC, abstractmethod 9from tbapi.api.series import Series 10from tbapi.api.models.bar import Bar 11if TYPE_CHECKING: 12 from tbapi.api.models.symbol import Symbol 13 from tbapi.core.models.contract_settings import ContractSettings 14 from tbapi.api.models.bar_period import BarPeriod 15 from tbapi.api.interfaces.iseries import ISeries 16 from tbapi.api.bases.bar_type import BarType 17 from tbapi.api.interfaces.iexchange_session import IExchangeSession 18 19@tb_class(_BarSeries) 20class BarSeries(Series): 21 """Represents a series of bars, with various calculated series such as Low, High, Open, Close, and others.""" 22 23 @staticmethod 24 def new(*args, **kwargs): 25 """Generic factory method for BarSeries. Use overloads for IDE type hints.""" 26 return BarSeries(*args, **kwargs) 27 28 @property 29 def symbol(self) -> Symbol: 30 """The symbol associated with the bar series.""" 31 from tbapi.api.models.symbol import Symbol 32 val = self._value.Symbol 33 return Symbol(_existing=val) 34 @symbol.setter 35 def symbol(self, val: Symbol): 36 tmp = self._value 37 tmp.Symbol = val._value 38 self._value = tmp 39 @property 40 def is_eth(self) -> bool: 41 """True if the bar series represents ETH hours (vs RTH)""" 42 val = self._value.IsETH 43 return val 44 @is_eth.setter 45 def is_eth(self, val: bool): 46 tmp = self._value 47 tmp.IsETH = val 48 self._value = tmp 49 @property 50 def contract_settings(self) -> ContractSettings: 51 """For futures symbols, details which kind of contract data this series represents (which specific contract if single contract, data merge rule otherwise)""" 52 from tbapi.core.models.contract_settings import ContractSettings 53 val = self._value.ContractSettings 54 return ContractSettings(_existing=val) 55 @contract_settings.setter 56 def contract_settings(self, val: ContractSettings): 57 tmp = self._value 58 tmp.ContractSettings = val._value 59 self._value = tmp 60 @property 61 def period(self) -> BarPeriod: 62 """The period of the bars in the series.""" 63 from tbapi.api.models.bar_period import BarPeriod 64 val = self._value.Period 65 return BarPeriod(_existing=val) 66 @period.setter 67 def period(self, val: BarPeriod): 68 tmp = self._value 69 tmp.Period = val._value 70 self._value = tmp 71 @property 72 def low(self) -> ISeries: 73 """The series of low prices for each bar.""" 74 val = self._value.Low 75 return val 76 @low.setter 77 def low(self, val: ISeries): 78 tmp = self._value 79 tmp.Low = val 80 self._value = tmp 81 @property 82 def time(self) -> ISeries: 83 """The series of time for each bar.""" 84 val = self._value.Time 85 return val 86 @time.setter 87 def time(self, val: ISeries): 88 tmp = self._value 89 tmp.Time = val 90 self._value = tmp 91 @property 92 def open(self) -> ISeries: 93 """The series of open prices for each bar.""" 94 val = self._value.Open 95 return val 96 @open.setter 97 def open(self, val: ISeries): 98 tmp = self._value 99 tmp.Open = val 100 self._value = tmp 101 @property 102 def high(self) -> ISeries: 103 """The series of high prices for each bar.""" 104 val = self._value.High 105 return val 106 @high.setter 107 def high(self, val: ISeries): 108 tmp = self._value 109 tmp.High = val 110 self._value = tmp 111 @property 112 def close(self) -> ISeries: 113 """The series of close prices for each bar.""" 114 val = self._value.Close 115 return val 116 @close.setter 117 def close(self, val: ISeries): 118 tmp = self._value 119 tmp.Close = val 120 self._value = tmp 121 @property 122 def volume(self) -> ISeries: 123 """The series of volumes for each bar.""" 124 val = self._value.Volume 125 return val 126 @volume.setter 127 def volume(self, val: ISeries): 128 tmp = self._value 129 tmp.Volume = val 130 self._value = tmp 131 @property 132 def median_price(self) -> ISeries: 133 """The series of median prices for each bar.""" 134 val = self._value.MedianPrice 135 return val 136 @median_price.setter 137 def median_price(self, val: ISeries): 138 tmp = self._value 139 tmp.MedianPrice = val 140 self._value = tmp 141 @property 142 def typical_price(self) -> ISeries: 143 """The series of typical prices for each bar.""" 144 val = self._value.TypicalPrice 145 return val 146 @typical_price.setter 147 def typical_price(self, val: ISeries): 148 tmp = self._value 149 tmp.TypicalPrice = val 150 self._value = tmp 151 @property 152 def bar_type(self) -> BarType: 153 """A shallow copy of the bar type script creating this series bars""" 154 from tbapi.api.bases.bar_type import BarType 155 val = self._value.BarType 156 return BarType(_existing=val) 157 @bar_type.setter 158 def bar_type(self, val: BarType): 159 tmp = self._value 160 tmp.BarType = val._value 161 self._value = tmp 162 @property 163 def start_time_utc(self) -> datetime: 164 """The start of the data series""" 165 val = self._value.StartTimeUtc 166 return to_python_datetime(val) 167 @start_time_utc.setter 168 def start_time_utc(self, val: datetime): 169 tmp = self._value 170 tmp.StartTimeUtc = to_net_datetime(val) 171 self._value = tmp 172 @property 173 def latest_bar_is_first_of_session(self) -> bool: 174 val = self._value.LatestBarIsFirstOfSession 175 return val 176 @latest_bar_is_first_of_session.setter 177 def latest_bar_is_first_of_session(self, val: bool): 178 tmp = self._value 179 tmp.LatestBarIsFirstOfSession = val 180 self._value = tmp 181 @property 182 def session(self) -> IExchangeSession: 183 from tbapi.api.interfaces.iexchange_session import IExchangeSession 184 val = self._value.Session 185 return IExchangeSession(_existing=val) 186 @session.setter 187 def session(self, val: IExchangeSession): 188 tmp = self._value 189 tmp.Session = val._value 190 self._value = tmp 191 192 def slice(self, date_time_utc: datetime) -> list[int]: 193 """Slices the series starting from a specific UTC date/time. The UTC date/time to slice from. A sequence of indexes starting from the given date/time.""" 194 result = self._value.Slice(to_net_datetime(date_time_utc)) 195 return result 196 197 198 199 def __getitem__(self, index: int) -> Bar: 200 result = self._value[index] 201 return Bar(_existing=result) 202 203 def __setitem__(self, index: int, value: Bar): 204 tmp = value 205 tmp = value._value 206 self._value[index] = tmp
27@tb_class(_BarSeries) 28class BarSeries(Series): 29 """Represents a series of bars, with various calculated series such as Low, High, Open, Close, and others.""" 30 31 @staticmethod 32 def new(*args, **kwargs): 33 """Generic factory method for BarSeries. Use overloads for IDE type hints.""" 34 return BarSeries(*args, **kwargs) 35 36 @property 37 def symbol(self) -> Symbol: 38 """The symbol associated with the bar series.""" 39 from tbapi.api.models.symbol import Symbol 40 val = self._value.Symbol 41 return Symbol(_existing=val) 42 @symbol.setter 43 def symbol(self, val: Symbol): 44 tmp = self._value 45 tmp.Symbol = val._value 46 self._value = tmp 47 @property 48 def is_eth(self) -> bool: 49 """True if the bar series represents ETH hours (vs RTH)""" 50 val = self._value.IsETH 51 return val 52 @is_eth.setter 53 def is_eth(self, val: bool): 54 tmp = self._value 55 tmp.IsETH = val 56 self._value = tmp 57 @property 58 def contract_settings(self) -> ContractSettings: 59 """For futures symbols, details which kind of contract data this series represents (which specific contract if single contract, data merge rule otherwise)""" 60 from tbapi.core.models.contract_settings import ContractSettings 61 val = self._value.ContractSettings 62 return ContractSettings(_existing=val) 63 @contract_settings.setter 64 def contract_settings(self, val: ContractSettings): 65 tmp = self._value 66 tmp.ContractSettings = val._value 67 self._value = tmp 68 @property 69 def period(self) -> BarPeriod: 70 """The period of the bars in the series.""" 71 from tbapi.api.models.bar_period import BarPeriod 72 val = self._value.Period 73 return BarPeriod(_existing=val) 74 @period.setter 75 def period(self, val: BarPeriod): 76 tmp = self._value 77 tmp.Period = val._value 78 self._value = tmp 79 @property 80 def low(self) -> ISeries: 81 """The series of low prices for each bar.""" 82 val = self._value.Low 83 return val 84 @low.setter 85 def low(self, val: ISeries): 86 tmp = self._value 87 tmp.Low = val 88 self._value = tmp 89 @property 90 def time(self) -> ISeries: 91 """The series of time for each bar.""" 92 val = self._value.Time 93 return val 94 @time.setter 95 def time(self, val: ISeries): 96 tmp = self._value 97 tmp.Time = val 98 self._value = tmp 99 @property 100 def open(self) -> ISeries: 101 """The series of open prices for each bar.""" 102 val = self._value.Open 103 return val 104 @open.setter 105 def open(self, val: ISeries): 106 tmp = self._value 107 tmp.Open = val 108 self._value = tmp 109 @property 110 def high(self) -> ISeries: 111 """The series of high prices for each bar.""" 112 val = self._value.High 113 return val 114 @high.setter 115 def high(self, val: ISeries): 116 tmp = self._value 117 tmp.High = val 118 self._value = tmp 119 @property 120 def close(self) -> ISeries: 121 """The series of close prices for each bar.""" 122 val = self._value.Close 123 return val 124 @close.setter 125 def close(self, val: ISeries): 126 tmp = self._value 127 tmp.Close = val 128 self._value = tmp 129 @property 130 def volume(self) -> ISeries: 131 """The series of volumes for each bar.""" 132 val = self._value.Volume 133 return val 134 @volume.setter 135 def volume(self, val: ISeries): 136 tmp = self._value 137 tmp.Volume = val 138 self._value = tmp 139 @property 140 def median_price(self) -> ISeries: 141 """The series of median prices for each bar.""" 142 val = self._value.MedianPrice 143 return val 144 @median_price.setter 145 def median_price(self, val: ISeries): 146 tmp = self._value 147 tmp.MedianPrice = val 148 self._value = tmp 149 @property 150 def typical_price(self) -> ISeries: 151 """The series of typical prices for each bar.""" 152 val = self._value.TypicalPrice 153 return val 154 @typical_price.setter 155 def typical_price(self, val: ISeries): 156 tmp = self._value 157 tmp.TypicalPrice = val 158 self._value = tmp 159 @property 160 def bar_type(self) -> BarType: 161 """A shallow copy of the bar type script creating this series bars""" 162 from tbapi.api.bases.bar_type import BarType 163 val = self._value.BarType 164 return BarType(_existing=val) 165 @bar_type.setter 166 def bar_type(self, val: BarType): 167 tmp = self._value 168 tmp.BarType = val._value 169 self._value = tmp 170 @property 171 def start_time_utc(self) -> datetime: 172 """The start of the data series""" 173 val = self._value.StartTimeUtc 174 return to_python_datetime(val) 175 @start_time_utc.setter 176 def start_time_utc(self, val: datetime): 177 tmp = self._value 178 tmp.StartTimeUtc = to_net_datetime(val) 179 self._value = tmp 180 @property 181 def latest_bar_is_first_of_session(self) -> bool: 182 val = self._value.LatestBarIsFirstOfSession 183 return val 184 @latest_bar_is_first_of_session.setter 185 def latest_bar_is_first_of_session(self, val: bool): 186 tmp = self._value 187 tmp.LatestBarIsFirstOfSession = val 188 self._value = tmp 189 @property 190 def session(self) -> IExchangeSession: 191 from tbapi.api.interfaces.iexchange_session import IExchangeSession 192 val = self._value.Session 193 return IExchangeSession(_existing=val) 194 @session.setter 195 def session(self, val: IExchangeSession): 196 tmp = self._value 197 tmp.Session = val._value 198 self._value = tmp 199 200 def slice(self, date_time_utc: datetime) -> list[int]: 201 """Slices the series starting from a specific UTC date/time. The UTC date/time to slice from. A sequence of indexes starting from the given date/time.""" 202 result = self._value.Slice(to_net_datetime(date_time_utc)) 203 return result 204 205 206 207 def __getitem__(self, index: int) -> Bar: 208 result = self._value[index] 209 return Bar(_existing=result) 210 211 def __setitem__(self, index: int, value: Bar): 212 tmp = value 213 tmp = value._value 214 self._value[index] = tmp
Represents a series of bars, with various calculated series such as Low, High, Open, Close, and others.
31 @staticmethod 32 def new(*args, **kwargs): 33 """Generic factory method for BarSeries. Use overloads for IDE type hints.""" 34 return BarSeries(*args, **kwargs)
Generic factory method for BarSeries. Use overloads for IDE type hints.
36 @property 37 def symbol(self) -> Symbol: 38 """The symbol associated with the bar series.""" 39 from tbapi.api.models.symbol import Symbol 40 val = self._value.Symbol 41 return Symbol(_existing=val)
The symbol associated with the bar series.
47 @property 48 def is_eth(self) -> bool: 49 """True if the bar series represents ETH hours (vs RTH)""" 50 val = self._value.IsETH 51 return val
True if the bar series represents ETH hours (vs RTH)
57 @property 58 def contract_settings(self) -> ContractSettings: 59 """For futures symbols, details which kind of contract data this series represents (which specific contract if single contract, data merge rule otherwise)""" 60 from tbapi.core.models.contract_settings import ContractSettings 61 val = self._value.ContractSettings 62 return ContractSettings(_existing=val)
For futures symbols, details which kind of contract data this series represents (which specific contract if single contract, data merge rule otherwise)
68 @property 69 def period(self) -> BarPeriod: 70 """The period of the bars in the series.""" 71 from tbapi.api.models.bar_period import BarPeriod 72 val = self._value.Period 73 return BarPeriod(_existing=val)
The period of the bars in the series.
79 @property 80 def low(self) -> ISeries: 81 """The series of low prices for each bar.""" 82 val = self._value.Low 83 return val
The series of low prices for each bar.
89 @property 90 def time(self) -> ISeries: 91 """The series of time for each bar.""" 92 val = self._value.Time 93 return val
The series of time for each bar.
99 @property 100 def open(self) -> ISeries: 101 """The series of open prices for each bar.""" 102 val = self._value.Open 103 return val
The series of open prices for each bar.
109 @property 110 def high(self) -> ISeries: 111 """The series of high prices for each bar.""" 112 val = self._value.High 113 return val
The series of high prices for each bar.
119 @property 120 def close(self) -> ISeries: 121 """The series of close prices for each bar.""" 122 val = self._value.Close 123 return val
The series of close prices for each bar.
129 @property 130 def volume(self) -> ISeries: 131 """The series of volumes for each bar.""" 132 val = self._value.Volume 133 return val
The series of volumes for each bar.
139 @property 140 def median_price(self) -> ISeries: 141 """The series of median prices for each bar.""" 142 val = self._value.MedianPrice 143 return val
The series of median prices for each bar.
149 @property 150 def typical_price(self) -> ISeries: 151 """The series of typical prices for each bar.""" 152 val = self._value.TypicalPrice 153 return val
The series of typical prices for each bar.
159 @property 160 def bar_type(self) -> BarType: 161 """A shallow copy of the bar type script creating this series bars""" 162 from tbapi.api.bases.bar_type import BarType 163 val = self._value.BarType 164 return BarType(_existing=val)
A shallow copy of the bar type script creating this series bars
170 @property 171 def start_time_utc(self) -> datetime: 172 """The start of the data series""" 173 val = self._value.StartTimeUtc 174 return to_python_datetime(val)
The start of the data series
200 def slice(self, date_time_utc: datetime) -> list[int]: 201 """Slices the series starting from a specific UTC date/time. The UTC date/time to slice from. A sequence of indexes starting from the given date/time.""" 202 result = self._value.Slice(to_net_datetime(date_time_utc)) 203 return result
Slices the series starting from a specific UTC date/time. The UTC date/time to slice from. A sequence of indexes starting from the given date/time.