Skip to content

execution ¤

Execution ¤

Execution(
    id: str,
    exchange: Exchange,
    data: DataFeed,
    size: float,
    price: float,
    at: float,
    order_id: str | None = None,
    order: Order | None = None,
    position_id: str | None = None,
    position: Position | None = None,
    **kwargs
)

Bases: BaseTransaction

Execution

Source code in lettrade/exchange/execution.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def __init__(
    self,
    id: str,
    exchange: "Exchange",
    data: "DataFeed",
    size: float,
    price: float,
    at: float,
    order_id: str | None = None,
    order: "Order | None" = None,
    position_id: str | None = None,
    position: "Position | None" = None,
    **kwargs,
):
    super().__init__(
        id=id,
        exchange=exchange,
        data=data,
        size=size,
        **kwargs,
    )
    self.order_id = order_id
    self.order: "Order" = order
    self.position_id = position_id
    self.position: "Position" = position
    self.price = price
    self.at = at

is_long property ¤

is_long: bool

True if side is long (size is positive).

Returns:

  • bool ( bool ) –

    True/False

is_short property ¤

is_short: bool

True if side is short (size is negative).

Returns:

  • bool ( bool ) –

    description

side property ¤

side: TradeSide

True if side is short (size is negative).

Returns:

merge ¤

merge(other: Execution)

Merge to keep object handler but not overwrite for Strategy using when Strategy want to store object and object will be automatic update directly

Source code in lettrade/exchange/execution.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def merge(self, other: "Execution"):
    """
    Merge to keep object handler but not overwrite for Strategy using when Strategy want to store object and object will be automatic update directly
    """
    if other is self:
        return

    if self.id != other.id:
        raise RuntimeError(f"Merge difference id {self.id} != {other.id} execution")

    self.price = other.price
    self.size = other.size

    if other.at:
        self.at = other.at
    if other.order_id:
        self.order_id = other.order_id
    if other.order:
        self.order = other.order
    if other.position_id:
        self.position_id = other.position_id
    if other.position:
        self.position = other.position