tbapi.api.bases.position_sizer

 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.Bases import PositionSizer as _PositionSizer
 7from typing import Any, overload
 8from abc import ABC, abstractmethod
 9from tbapi.api.bases.symbol_script import SymbolScript
10from tbapi.api.interfaces.orders.iorder_accessor import IOrderAccessor
11from tbapi.api.enums.run_type import RunType
12from Tickblaze.Scripts.Api.Enums import RunType as _RunType
13if TYPE_CHECKING:
14    from tbapi.api.interfaces.isymbol import ISymbol
15    from tbapi.api.interfaces.iaccount import IAccount
16    from tbapi.api.interfaces.orders.iposition import IPosition
17
18@tb_interface(_PositionSizer)
19class PositionSizer(SymbolScript, IOrderAccessor):
20    """A base class for position sizing scripts."""
21
22    @staticmethod
23    def new(*args, **kwargs):
24        """Generic factory method for PositionSizer. Use overloads for IDE type hints."""
25        return PositionSizer(*args, **kwargs)
26
27    @property
28    def symbol(self) -> ISymbol:
29        from tbapi.api.interfaces.isymbol import ISymbol
30        val = self._value.Symbol
31        return ISymbol(_existing=val)
32    @property
33    def account(self) -> IAccount:
34        from tbapi.api.interfaces.iaccount import IAccount
35        val = self._value.Account
36        return IAccount(_existing=val)
37    @property
38    def pending_orders(self) -> IReadOnlyList:
39        val = self._value.PendingOrders
40        return val
41    @property
42    def position(self) -> IPosition:
43        from tbapi.api.interfaces.orders.iposition import IPosition
44        val = self._value.Position
45        return IPosition(_existing=val)
46    @property
47    def run_type(self) -> RunType:
48        val = int(self._value.RunType)
49        return RunType(val)
50
51    def get_exchange_rate(self, from_currency: str, to_currency: str) -> float:
52        result = self._value.GetExchangeRate(from_currency, to_currency)
53        return result
54  
@tb_interface(_PositionSizer)
class PositionSizer(tbapi.api.bases.symbol_script.SymbolScript, tbapi.api.interfaces.orders.iorder_accessor.IOrderAccessor):
26@tb_interface(_PositionSizer)
27class PositionSizer(SymbolScript, IOrderAccessor):
28    """A base class for position sizing scripts."""
29
30    @staticmethod
31    def new(*args, **kwargs):
32        """Generic factory method for PositionSizer. Use overloads for IDE type hints."""
33        return PositionSizer(*args, **kwargs)
34
35    @property
36    def symbol(self) -> ISymbol:
37        from tbapi.api.interfaces.isymbol import ISymbol
38        val = self._value.Symbol
39        return ISymbol(_existing=val)
40    @property
41    def account(self) -> IAccount:
42        from tbapi.api.interfaces.iaccount import IAccount
43        val = self._value.Account
44        return IAccount(_existing=val)
45    @property
46    def pending_orders(self) -> IReadOnlyList:
47        val = self._value.PendingOrders
48        return val
49    @property
50    def position(self) -> IPosition:
51        from tbapi.api.interfaces.orders.iposition import IPosition
52        val = self._value.Position
53        return IPosition(_existing=val)
54    @property
55    def run_type(self) -> RunType:
56        val = int(self._value.RunType)
57        return RunType(val)
58
59    def get_exchange_rate(self, from_currency: str, to_currency: str) -> float:
60        result = self._value.GetExchangeRate(from_currency, to_currency)
61        return result

A base class for position sizing scripts.

PositionSizer(*args, **kwargs)
199        def __init__(self, *args, **kwargs):
200            pass
@staticmethod
def new(*args, **kwargs):
30    @staticmethod
31    def new(*args, **kwargs):
32        """Generic factory method for PositionSizer. Use overloads for IDE type hints."""
33        return PositionSizer(*args, **kwargs)

Generic factory method for PositionSizer. Use overloads for IDE type hints.

35    @property
36    def symbol(self) -> ISymbol:
37        from tbapi.api.interfaces.isymbol import ISymbol
38        val = self._value.Symbol
39        return ISymbol(_existing=val)

The financial symbol associated with the orders and position.

40    @property
41    def account(self) -> IAccount:
42        from tbapi.api.interfaces.iaccount import IAccount
43        val = self._value.Account
44        return IAccount(_existing=val)

The account associated with the orders and position.

pending_orders: 'IReadOnlyList'
45    @property
46    def pending_orders(self) -> IReadOnlyList:
47        val = self._value.PendingOrders
48        return val

A collection of orders that are currently pending execution.

49    @property
50    def position(self) -> IPosition:
51        from tbapi.api.interfaces.orders.iposition import IPosition
52        val = self._value.Position
53        return IPosition(_existing=val)

The position associated with the current symbol and account.

run_type: tbapi.api.enums.run_type.RunType
54    @property
55    def run_type(self) -> RunType:
56        val = int(self._value.RunType)
57        return RunType(val)
def get_exchange_rate(self, from_currency: str, to_currency: str) -> float:
59    def get_exchange_rate(self, from_currency: str, to_currency: str) -> float:
60        result = self._value.GetExchangeRate(from_currency, to_currency)
61        return result

Retrieves the exchange rate for converting one currency to another. The currency to convert from (e.g., "USD"). The currency to convert to (e.g., "EUR"). The exchange rate between the specified currencies.