tbapi.api.bases.script
1from __future__ import annotations 2from typing import TYPE_CHECKING 3import clr 4from tbapi.common.decorators import tb_class, tb_interface 5from tbapi.common.converters import to_python_datetime, to_net_datetime 6from datetime import datetime 7from Tickblaze.Scripts.Api.Bases import Script as _Script 8from typing import Any, overload 9from abc import ABC, abstractmethod 10from tbapi.api.interfaces.iscript import IScript 11from tbapi.api.interfaces.imetadata import IMetadata 12from tbapi.api.parameters import Parameters 13from tbapi.api.optimization_parameters import OptimizationParameters 14if TYPE_CHECKING: 15 from tbapi.api.models.metadata import Metadata 16 from tbapi.api.adapters.ialert_adapter import IAlertAdapter 17 18@tb_interface(_Script) 19class Script(IScript, IMetadata): 20 21 @staticmethod 22 def new(*args, **kwargs): 23 """Generic factory method for Script. Use overloads for IDE type hints.""" 24 return Script(*args, **kwargs) 25 26 @property 27 def name(self) -> str: 28 val = self._value.Name 29 return val 30 @name.setter 31 def name(self, val: str): 32 tmp = self._value 33 tmp.Name = val 34 self._value = tmp 35 @property 36 def short_name(self) -> str: 37 val = self._value.ShortName 38 return val 39 @short_name.setter 40 def short_name(self, val: str): 41 tmp = self._value 42 tmp.ShortName = val 43 self._value = tmp 44 @property 45 def description(self) -> str: 46 val = self._value.Description 47 return val 48 @description.setter 49 def description(self, val: str): 50 tmp = self._value 51 tmp.Description = val 52 self._value = tmp 53 @property 54 def metadata(self) -> Metadata: 55 from tbapi.api.models.metadata import Metadata 56 val = self._value.Metadata 57 return Metadata(_existing=val) 58 @property 59 def parameters(self) -> Parameters: 60 from tbapi.api.parameters import Parameters 61 val = self._value.Parameters 62 return Parameters(_existing=val) 63 @property 64 def is_initialized(self) -> bool: 65 val = self._value.IsInitialized 66 return val 67 @is_initialized.setter 68 def is_initialized(self, val: bool): 69 tmp = self._value 70 tmp.IsInitialized = val 71 self._value = tmp 72 @property 73 def product_code_aliases(self) -> list[str]: 74 val = self._value.ProductCodeAliases 75 return val 76 77 def create_chart_toolbar_menu_item(self) -> Any: 78 """Creates a control that will be displayed in the chart's toolbar.""" 79 result = self._value.CreateChartToolbarMenuItem() 80 return result 81 82 def register_exception(self, message: str) -> None: 83 """Registers an exception Exception message""" 84 result = self._value.RegisterException(message) 85 return result 86 87 def dispose(self) -> None: 88 result = self._value.Dispose() 89 return result 90 91 92 @clr.clrmethod(Parameters, [Parameters]) 93 def get_parameters(self, parameters: Parameters) -> Parameters: 94 ... 95 96 @clr.clrmethod(Parameters, [Parameters, OptimizationParameters]) 97 def get_optimization_parameters(self, parameters: Parameters, parameter_values: OptimizationParameters) -> Parameters: 98 ... 99 100 @clr.clrmethod(None, [None]) 101 def initialize(self) -> None: 102 """A method call when the script is being initialized.""" 103 ... 104 105 @clr.clrmethod(None, [None]) 106 def on_destroy(self) -> None: 107 """A method call when the script is being destroyed.""" 108 ...
26@tb_interface(_Script) 27class Script(IScript, IMetadata): 28 29 @staticmethod 30 def new(*args, **kwargs): 31 """Generic factory method for Script. Use overloads for IDE type hints.""" 32 return Script(*args, **kwargs) 33 34 @property 35 def name(self) -> str: 36 val = self._value.Name 37 return val 38 @name.setter 39 def name(self, val: str): 40 tmp = self._value 41 tmp.Name = val 42 self._value = tmp 43 @property 44 def short_name(self) -> str: 45 val = self._value.ShortName 46 return val 47 @short_name.setter 48 def short_name(self, val: str): 49 tmp = self._value 50 tmp.ShortName = val 51 self._value = tmp 52 @property 53 def description(self) -> str: 54 val = self._value.Description 55 return val 56 @description.setter 57 def description(self, val: str): 58 tmp = self._value 59 tmp.Description = val 60 self._value = tmp 61 @property 62 def metadata(self) -> Metadata: 63 from tbapi.api.models.metadata import Metadata 64 val = self._value.Metadata 65 return Metadata(_existing=val) 66 @property 67 def parameters(self) -> Parameters: 68 from tbapi.api.parameters import Parameters 69 val = self._value.Parameters 70 return Parameters(_existing=val) 71 @property 72 def is_initialized(self) -> bool: 73 val = self._value.IsInitialized 74 return val 75 @is_initialized.setter 76 def is_initialized(self, val: bool): 77 tmp = self._value 78 tmp.IsInitialized = val 79 self._value = tmp 80 @property 81 def product_code_aliases(self) -> list[str]: 82 val = self._value.ProductCodeAliases 83 return val 84 85 def create_chart_toolbar_menu_item(self) -> Any: 86 """Creates a control that will be displayed in the chart's toolbar.""" 87 result = self._value.CreateChartToolbarMenuItem() 88 return result 89 90 def register_exception(self, message: str) -> None: 91 """Registers an exception Exception message""" 92 result = self._value.RegisterException(message) 93 return result 94 95 def dispose(self) -> None: 96 result = self._value.Dispose() 97 return result 98 99 100 @clr.clrmethod(Parameters, [Parameters]) 101 def get_parameters(self, parameters: Parameters) -> Parameters: 102 ... 103 104 @clr.clrmethod(Parameters, [Parameters, OptimizationParameters]) 105 def get_optimization_parameters(self, parameters: Parameters, parameter_values: OptimizationParameters) -> Parameters: 106 ... 107 108 @clr.clrmethod(None, [None]) 109 def initialize(self) -> None: 110 """A method call when the script is being initialized.""" 111 ... 112 113 @clr.clrmethod(None, [None]) 114 def on_destroy(self) -> None: 115 """A method call when the script is being destroyed.""" 116 ...
Defines properties and methods for a script, including initialization and metadata.
29 @staticmethod 30 def new(*args, **kwargs): 31 """Generic factory method for Script. Use overloads for IDE type hints.""" 32 return Script(*args, **kwargs)
Generic factory method for Script. Use overloads for IDE type hints.
61 @property 62 def metadata(self) -> Metadata: 63 from tbapi.api.models.metadata import Metadata 64 val = self._value.Metadata 65 return Metadata(_existing=val)
The metadata associated with the script.
66 @property 67 def parameters(self) -> Parameters: 68 from tbapi.api.parameters import Parameters 69 val = self._value.Parameters 70 return Parameters(_existing=val)
The parameters for the script.
90 def register_exception(self, message: str) -> None: 91 """Registers an exception Exception message""" 92 result = self._value.RegisterException(message) 93 return result
Registers an exception Exception message
Method decorator for exposing python methods to .NET. The argument and return types must be specified as arguments to clrmethod.
e.g.::
class X(object):
@clrmethod(int, [str])
def test(self, x):
return len(x)
Methods decorated this way can be called from .NET, e.g.::
dynamic x = getX(); // get an instance of X declared in Python
int z = x.test("hello"); // calls into python and returns len("hello")
Method decorator for exposing python methods to .NET. The argument and return types must be specified as arguments to clrmethod.
e.g.::
class X(object):
@clrmethod(int, [str])
def test(self, x):
return len(x)
Methods decorated this way can be called from .NET, e.g.::
dynamic x = getX(); // get an instance of X declared in Python
int z = x.test("hello"); // calls into python and returns len("hello")
Method decorator for exposing python methods to .NET. The argument and return types must be specified as arguments to clrmethod.
e.g.::
class X(object):
@clrmethod(int, [str])
def test(self, x):
return len(x)
Methods decorated this way can be called from .NET, e.g.::
dynamic x = getX(); // get an instance of X declared in Python
int z = x.test("hello"); // calls into python and returns len("hello")
Method decorator for exposing python methods to .NET. The argument and return types must be specified as arguments to clrmethod.
e.g.::
class X(object):
@clrmethod(int, [str])
def test(self, x):
return len(x)
Methods decorated this way can be called from .NET, e.g.::
dynamic x = getX(); // get an instance of X declared in Python
int z = x.test("hello"); // calls into python and returns len("hello")