tbapi.api.models.symbol
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 Symbol as _Symbol 7from typing import Any, overload 8from abc import ABC, abstractmethod 9from tbapi.api.interfaces.isymbol import ISymbol 10from tbapi.core.enums.instrument_type import InstrumentType 11from tbapi.core.enums.exchange import Exchange 12from tbapi.api.enums.rounding_mode import RoundingMode 13from Tickblaze.Core.Enums import InstrumentType as _InstrumentType 14from Tickblaze.Core.Enums import Exchange as _Exchange 15from Tickblaze.Scripts.Api.Enums import RoundingMode as _RoundingMode 16if TYPE_CHECKING: 17 from tbapi.api.interfaces.iexchange_calendar import IExchangeCalendar 18 19@tb_class(_Symbol) 20class Symbol(ISymbol): 21 22 @staticmethod 23 def new(*args, **kwargs): 24 """Generic factory method for Symbol. Use overloads for IDE type hints.""" 25 return Symbol(*args, **kwargs) 26 27 @property 28 def code(self) -> str: 29 val = self._value.Code 30 return val 31 @property 32 def description(self) -> str: 33 val = self._value.Description 34 return val 35 @property 36 def tick_size(self) -> float: 37 val = self._value.TickSize 38 return val 39 @tick_size.setter 40 def tick_size(self, val: float): 41 tmp = self._value 42 tmp.TickSize = val 43 self._value = tmp 44 @property 45 def tick_value(self) -> float: 46 val = self._value.TickValue 47 return val 48 @tick_value.setter 49 def tick_value(self, val: float): 50 tmp = self._value 51 tmp.TickValue = val 52 self._value = tmp 53 @property 54 def decimals(self) -> int: 55 val = self._value.Decimals 56 return val 57 @decimals.setter 58 def decimals(self, val: int): 59 tmp = self._value 60 tmp.Decimals = val 61 self._value = tmp 62 @property 63 def currency_code(self) -> str: 64 val = self._value.CurrencyCode 65 return val 66 @currency_code.setter 67 def currency_code(self, val: str): 68 tmp = self._value 69 tmp.CurrencyCode = val 70 self._value = tmp 71 @property 72 def exchange_calendar(self) -> IExchangeCalendar: 73 from tbapi.api.interfaces.iexchange_calendar import IExchangeCalendar 74 val = self._value.ExchangeCalendar 75 return IExchangeCalendar(_existing=val) 76 @exchange_calendar.setter 77 def exchange_calendar(self, val: IExchangeCalendar): 78 tmp = self._value 79 tmp.ExchangeCalendar = val._value 80 self._value = tmp 81 @property 82 def ticks_per_point(self) -> float: 83 val = self._value.TicksPerPoint 84 return val 85 @property 86 def point_size(self) -> float: 87 val = self._value.PointSize 88 return val 89 @property 90 def point_value(self) -> float: 91 val = self._value.PointValue 92 return val 93 @property 94 def minimum_volume(self) -> float: 95 val = self._value.MinimumVolume 96 return val 97 @minimum_volume.setter 98 def minimum_volume(self, val: float): 99 tmp = self._value 100 tmp.MinimumVolume = val 101 self._value = tmp 102 @property 103 def type(self) -> InstrumentType: 104 val = int(self._value.Type) 105 return InstrumentType(val) 106 @type.setter 107 def type(self, val: InstrumentType): 108 tmp = self._value 109 tmp.Type = _InstrumentType(val.value if hasattr(val, "value") else int(val)) 110 self._value = tmp 111 @property 112 def exchange(self) -> Exchange: 113 val = int(self._value.Exchange) 114 return Exchange(val) 115 @exchange.setter 116 def exchange(self, val: Exchange): 117 tmp = self._value 118 tmp.Exchange = _Exchange(val.value if hasattr(val, "value") else int(val)) 119 self._value = tmp 120 121 def round_to_tick(self, value: float) -> float: 122 result = self._value.RoundToTick(value) 123 return result 124 125 def format_price(self, price: float) -> str: 126 result = self._value.FormatPrice(price) 127 return result 128 129 def normalize_volume(self, volume: float, rounding_mode: RoundingMode) -> float: 130 result = self._value.NormalizeVolume(volume, _RoundingMode(rounding_mode.value if hasattr(rounding_mode, 'value') else int(rounding_mode))) 131 return result 132
27@tb_class(_Symbol) 28class Symbol(ISymbol): 29 30 @staticmethod 31 def new(*args, **kwargs): 32 """Generic factory method for Symbol. Use overloads for IDE type hints.""" 33 return Symbol(*args, **kwargs) 34 35 @property 36 def code(self) -> str: 37 val = self._value.Code 38 return val 39 @property 40 def description(self) -> str: 41 val = self._value.Description 42 return val 43 @property 44 def tick_size(self) -> float: 45 val = self._value.TickSize 46 return val 47 @tick_size.setter 48 def tick_size(self, val: float): 49 tmp = self._value 50 tmp.TickSize = val 51 self._value = tmp 52 @property 53 def tick_value(self) -> float: 54 val = self._value.TickValue 55 return val 56 @tick_value.setter 57 def tick_value(self, val: float): 58 tmp = self._value 59 tmp.TickValue = val 60 self._value = tmp 61 @property 62 def decimals(self) -> int: 63 val = self._value.Decimals 64 return val 65 @decimals.setter 66 def decimals(self, val: int): 67 tmp = self._value 68 tmp.Decimals = val 69 self._value = tmp 70 @property 71 def currency_code(self) -> str: 72 val = self._value.CurrencyCode 73 return val 74 @currency_code.setter 75 def currency_code(self, val: str): 76 tmp = self._value 77 tmp.CurrencyCode = val 78 self._value = tmp 79 @property 80 def exchange_calendar(self) -> IExchangeCalendar: 81 from tbapi.api.interfaces.iexchange_calendar import IExchangeCalendar 82 val = self._value.ExchangeCalendar 83 return IExchangeCalendar(_existing=val) 84 @exchange_calendar.setter 85 def exchange_calendar(self, val: IExchangeCalendar): 86 tmp = self._value 87 tmp.ExchangeCalendar = val._value 88 self._value = tmp 89 @property 90 def ticks_per_point(self) -> float: 91 val = self._value.TicksPerPoint 92 return val 93 @property 94 def point_size(self) -> float: 95 val = self._value.PointSize 96 return val 97 @property 98 def point_value(self) -> float: 99 val = self._value.PointValue 100 return val 101 @property 102 def minimum_volume(self) -> float: 103 val = self._value.MinimumVolume 104 return val 105 @minimum_volume.setter 106 def minimum_volume(self, val: float): 107 tmp = self._value 108 tmp.MinimumVolume = val 109 self._value = tmp 110 @property 111 def type(self) -> InstrumentType: 112 val = int(self._value.Type) 113 return InstrumentType(val) 114 @type.setter 115 def type(self, val: InstrumentType): 116 tmp = self._value 117 tmp.Type = _InstrumentType(val.value if hasattr(val, "value") else int(val)) 118 self._value = tmp 119 @property 120 def exchange(self) -> Exchange: 121 val = int(self._value.Exchange) 122 return Exchange(val) 123 @exchange.setter 124 def exchange(self, val: Exchange): 125 tmp = self._value 126 tmp.Exchange = _Exchange(val.value if hasattr(val, "value") else int(val)) 127 self._value = tmp 128 129 def round_to_tick(self, value: float) -> float: 130 result = self._value.RoundToTick(value) 131 return result 132 133 def format_price(self, price: float) -> str: 134 result = self._value.FormatPrice(price) 135 return result 136 137 def normalize_volume(self, volume: float, rounding_mode: RoundingMode) -> float: 138 result = self._value.NormalizeVolume(volume, _RoundingMode(rounding_mode.value if hasattr(rounding_mode, 'value') else int(rounding_mode))) 139 return result
Defines properties and methods related to a symbol, including tick size, point size, and volume normalization.
30 @staticmethod 31 def new(*args, **kwargs): 32 """Generic factory method for Symbol. Use overloads for IDE type hints.""" 33 return Symbol(*args, **kwargs)
Generic factory method for Symbol. Use overloads for IDE type hints.
79 @property 80 def exchange_calendar(self) -> IExchangeCalendar: 81 from tbapi.api.interfaces.iexchange_calendar import IExchangeCalendar 82 val = self._value.ExchangeCalendar 83 return IExchangeCalendar(_existing=val)
The exchange calendar for the symbol.
89 @property 90 def ticks_per_point(self) -> float: 91 val = self._value.TicksPerPoint 92 return val
The number of ticks per point for the symbol.
101 @property 102 def minimum_volume(self) -> float: 103 val = self._value.MinimumVolume 104 return val
The minimum volume for the symbol.
110 @property 111 def type(self) -> InstrumentType: 112 val = int(self._value.Type) 113 return InstrumentType(val)
The type of the instrument
119 @property 120 def exchange(self) -> Exchange: 121 val = int(self._value.Exchange) 122 return Exchange(val)
The exchange the symbol trades on
129 def round_to_tick(self, value: float) -> float: 130 result = self._value.RoundToTick(value) 131 return result
Rounds a value to the nearest tick. The value to round. The value rounded to the nearest tick.
133 def format_price(self, price: float) -> str: 134 result = self._value.FormatPrice(price) 135 return result
Formats a price as a string for the symbol. The price to format. The formatted price as a string.
137 def normalize_volume(self, volume: float, rounding_mode: RoundingMode) -> float: 138 result = self._value.NormalizeVolume(volume, _RoundingMode(rounding_mode.value if hasattr(rounding_mode, 'value') else int(rounding_mode))) 139 return result
Normalizes a volume to the symbol's tradable volume, applying the specified rounding mode. The volume to normalize. The rounding mode to apply. The normalized volume.