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