tbapi.api.interfaces.orders.iorder
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.Orders import IOrder as _IOrder 7from typing import Any, overload 8from abc import ABC, abstractmethod 9from tbapi.api.enums.order_status import OrderStatus 10from tbapi.api.enums.order_type import OrderType 11from tbapi.api.enums.order_direction import OrderDirection 12from tbapi.api.enums.time_in_force import TimeInForce 13from Tickblaze.Scripts.Api.Enums import OrderStatus as _OrderStatus 14from Tickblaze.Scripts.Api.Enums import OrderType as _OrderType 15from Tickblaze.Scripts.Api.Enums import OrderDirection as _OrderDirection 16from Tickblaze.Scripts.Api.Enums import TimeInForce as _TimeInForce 17if TYPE_CHECKING: 18 from tbapi.api.interfaces.isymbol import ISymbol 19 20@tb_interface(_IOrder) 21class IOrder(): 22 """Represents an order within the trading system, containing details about the order's characteristics and state.""" 23 24 @property 25 def symbol(self) -> ISymbol: 26 """The financial symbol associated with the order.""" 27 from tbapi.api.interfaces.isymbol import ISymbol 28 val = self._value.Symbol 29 return ISymbol(_existing=val) 30 @property 31 def status(self) -> OrderStatus: 32 """The current status of the order (e.g., pending, executed, canceled).""" 33 val = int(self._value.Status) 34 return OrderStatus(val) 35 @property 36 def is_complete(self) -> bool: 37 """Whether the order is cancelled or executed""" 38 val = self._value.IsComplete 39 return val 40 @property 41 def comment(self) -> str: 42 """Comment attached to the order""" 43 val = self._value.Comment 44 return val 45 @property 46 def type(self) -> OrderType: 47 """The type of the order (e.g., market, limit, stop).""" 48 val = int(self._value.Type) 49 return OrderType(val) 50 @property 51 def direction(self) -> OrderDirection: 52 """The direction of the order (e.g., long, short).""" 53 val = int(self._value.Direction) 54 return OrderDirection(val) 55 @property 56 def time_in_force(self) -> TimeInForce: 57 """Specifies how long the order remains active in the market (e.g., Good Till Cancelled, Immediate or Cancel).""" 58 val = int(self._value.TimeInForce) 59 return TimeInForce(val) 60 @property 61 def price(self) -> float: 62 """The execution price of the order.""" 63 val = self._value.Price 64 return val 65 @property 66 def stop_price(self) -> float: 67 """The stop price for the order, if applicable.""" 68 val = self._value.StopPrice 69 return val 70 @property 71 def limit_price(self) -> float: 72 """The limit price for the order, if applicable.""" 73 val = self._value.LimitPrice 74 return val 75 @property 76 def quantity(self) -> float: 77 """The quantity of the order, representing the number of units to buy or sell.""" 78 val = self._value.Quantity 79 return val 80 @property 81 def is_filled(self) -> bool: 82 """Indicates whether the order was completely filled.""" 83 val = self._value.IsFilled 84 return val 85 @property 86 def filled_quantity(self) -> float: 87 """The filled quantity.""" 88 val = self._value.FilledQuantity 89 return val 90 @filled_quantity.setter 91 def filled_quantity(self, val: float): 92 tmp = self._value 93 tmp.FilledQuantity = val 94 self._value = tmp 95 @property 96 def price_offset(self) -> float: 97 """The trailing offset, either in percent or as a fixed value.""" 98 val = self._value.PriceOffset 99 return val 100 @property 101 def index(self) -> int: 102 """The index of the order, providing a unique identifier within the system.""" 103 val = self._value.Index 104 return val 105 @property 106 def parent_order_index(self) -> int: 107 """The order index to which a StopLoss, TakeProfit or TrailingStopLoss order is attached.""" 108 val = self._value.ParentOrderIndex 109 return val 110 @property 111 def is_stop_loss(self) -> bool: 112 val = self._value.IsStopLoss 113 return val 114 @property 115 def is_take_profit(self) -> bool: 116 val = self._value.IsTakeProfit 117 return val 118 119 def get_order_price(self, ref_price: float | None = None) -> float: 120 result = self._value.GetOrderPrice(ref_price) 121 return result 122
26@tb_interface(_IOrder) 27class IOrder(): 28 """Represents an order within the trading system, containing details about the order's characteristics and state.""" 29 30 @property 31 def symbol(self) -> ISymbol: 32 """The financial symbol associated with the order.""" 33 from tbapi.api.interfaces.isymbol import ISymbol 34 val = self._value.Symbol 35 return ISymbol(_existing=val) 36 @property 37 def status(self) -> OrderStatus: 38 """The current status of the order (e.g., pending, executed, canceled).""" 39 val = int(self._value.Status) 40 return OrderStatus(val) 41 @property 42 def is_complete(self) -> bool: 43 """Whether the order is cancelled or executed""" 44 val = self._value.IsComplete 45 return val 46 @property 47 def comment(self) -> str: 48 """Comment attached to the order""" 49 val = self._value.Comment 50 return val 51 @property 52 def type(self) -> OrderType: 53 """The type of the order (e.g., market, limit, stop).""" 54 val = int(self._value.Type) 55 return OrderType(val) 56 @property 57 def direction(self) -> OrderDirection: 58 """The direction of the order (e.g., long, short).""" 59 val = int(self._value.Direction) 60 return OrderDirection(val) 61 @property 62 def time_in_force(self) -> TimeInForce: 63 """Specifies how long the order remains active in the market (e.g., Good Till Cancelled, Immediate or Cancel).""" 64 val = int(self._value.TimeInForce) 65 return TimeInForce(val) 66 @property 67 def price(self) -> float: 68 """The execution price of the order.""" 69 val = self._value.Price 70 return val 71 @property 72 def stop_price(self) -> float: 73 """The stop price for the order, if applicable.""" 74 val = self._value.StopPrice 75 return val 76 @property 77 def limit_price(self) -> float: 78 """The limit price for the order, if applicable.""" 79 val = self._value.LimitPrice 80 return val 81 @property 82 def quantity(self) -> float: 83 """The quantity of the order, representing the number of units to buy or sell.""" 84 val = self._value.Quantity 85 return val 86 @property 87 def is_filled(self) -> bool: 88 """Indicates whether the order was completely filled.""" 89 val = self._value.IsFilled 90 return val 91 @property 92 def filled_quantity(self) -> float: 93 """The filled quantity.""" 94 val = self._value.FilledQuantity 95 return val 96 @filled_quantity.setter 97 def filled_quantity(self, val: float): 98 tmp = self._value 99 tmp.FilledQuantity = val 100 self._value = tmp 101 @property 102 def price_offset(self) -> float: 103 """The trailing offset, either in percent or as a fixed value.""" 104 val = self._value.PriceOffset 105 return val 106 @property 107 def index(self) -> int: 108 """The index of the order, providing a unique identifier within the system.""" 109 val = self._value.Index 110 return val 111 @property 112 def parent_order_index(self) -> int: 113 """The order index to which a StopLoss, TakeProfit or TrailingStopLoss order is attached.""" 114 val = self._value.ParentOrderIndex 115 return val 116 @property 117 def is_stop_loss(self) -> bool: 118 val = self._value.IsStopLoss 119 return val 120 @property 121 def is_take_profit(self) -> bool: 122 val = self._value.IsTakeProfit 123 return val 124 125 def get_order_price(self, ref_price: float | None = None) -> float: 126 result = self._value.GetOrderPrice(ref_price) 127 return result
Represents an order within the trading system, containing details about the order's characteristics and state.
30 @property 31 def symbol(self) -> ISymbol: 32 """The financial symbol associated with the order.""" 33 from tbapi.api.interfaces.isymbol import ISymbol 34 val = self._value.Symbol 35 return ISymbol(_existing=val)
The financial symbol associated with the order.
36 @property 37 def status(self) -> OrderStatus: 38 """The current status of the order (e.g., pending, executed, canceled).""" 39 val = int(self._value.Status) 40 return OrderStatus(val)
The current status of the order (e.g., pending, executed, canceled).
41 @property 42 def is_complete(self) -> bool: 43 """Whether the order is cancelled or executed""" 44 val = self._value.IsComplete 45 return val
Whether the order is cancelled or executed
46 @property 47 def comment(self) -> str: 48 """Comment attached to the order""" 49 val = self._value.Comment 50 return val
Comment attached to the order
51 @property 52 def type(self) -> OrderType: 53 """The type of the order (e.g., market, limit, stop).""" 54 val = int(self._value.Type) 55 return OrderType(val)
The type of the order (e.g., market, limit, stop).
56 @property 57 def direction(self) -> OrderDirection: 58 """The direction of the order (e.g., long, short).""" 59 val = int(self._value.Direction) 60 return OrderDirection(val)
The direction of the order (e.g., long, short).
61 @property 62 def time_in_force(self) -> TimeInForce: 63 """Specifies how long the order remains active in the market (e.g., Good Till Cancelled, Immediate or Cancel).""" 64 val = int(self._value.TimeInForce) 65 return TimeInForce(val)
Specifies how long the order remains active in the market (e.g., Good Till Cancelled, Immediate or Cancel).
66 @property 67 def price(self) -> float: 68 """The execution price of the order.""" 69 val = self._value.Price 70 return val
The execution price of the order.
71 @property 72 def stop_price(self) -> float: 73 """The stop price for the order, if applicable.""" 74 val = self._value.StopPrice 75 return val
The stop price for the order, if applicable.
76 @property 77 def limit_price(self) -> float: 78 """The limit price for the order, if applicable.""" 79 val = self._value.LimitPrice 80 return val
The limit price for the order, if applicable.
81 @property 82 def quantity(self) -> float: 83 """The quantity of the order, representing the number of units to buy or sell.""" 84 val = self._value.Quantity 85 return val
The quantity of the order, representing the number of units to buy or sell.
86 @property 87 def is_filled(self) -> bool: 88 """Indicates whether the order was completely filled.""" 89 val = self._value.IsFilled 90 return val
Indicates whether the order was completely filled.
91 @property 92 def filled_quantity(self) -> float: 93 """The filled quantity.""" 94 val = self._value.FilledQuantity 95 return val
The filled quantity.
101 @property 102 def price_offset(self) -> float: 103 """The trailing offset, either in percent or as a fixed value.""" 104 val = self._value.PriceOffset 105 return val
The trailing offset, either in percent or as a fixed value.
106 @property 107 def index(self) -> int: 108 """The index of the order, providing a unique identifier within the system.""" 109 val = self._value.Index 110 return val
The index of the order, providing a unique identifier within the system.
111 @property 112 def parent_order_index(self) -> int: 113 """The order index to which a StopLoss, TakeProfit or TrailingStopLoss order is attached.""" 114 val = self._value.ParentOrderIndex 115 return val
The order index to which a StopLoss, TakeProfit or TrailingStopLoss order is attached.