Orders and stops¶
Side
¶
Bases: Enum
Trade direction. Calls also accept "buy", "sell", "long", "short".
parse
classmethod
¶
parse(value: Side | str) -> Result[Side, TradeError]
A Side, or Err(INVALID_ARGUMENT) for an unknown name.
Stop
dataclass
¶
Stop(value: float, kind: StopKind)
A stop-loss or take-profit level, as a price or as a distance in points.
Build one with Stop.at_price, Stop.points or, for a value that may be
bad at runtime, Stop.parse. A stop of zero, a negative price or a value
that is not finite cannot exist: MT5 would read 0 as "no stop".
parse
classmethod
¶
parse(value: object, kind: StopKind) -> Result[Stop, TradeError]
Build a stop, or return Err(INVALID_STOPS) for a bad value instead of raising.
A kind that is not a StopKind is a programming error and still
raises TypeError.
at_price
classmethod
¶
at_price(price: float) -> Stop
A stop at an absolute price; raises ValueError unless positive and finite.
points
classmethod
¶
points(distance: float) -> Stop
A stop distance points from the entry price; the sign is ignored.
Raises ValueError for zero or a value that is not finite; use
Stop.parse for a value that may be bad at runtime.
stop_loss
¶
stop_loss(side: Side, reference: float, spec: SymbolSpec) -> Result[float, TradeError]
The stop-loss price for a side trade entered at reference, on the tick grid.
take_profit
¶
take_profit(side: Side, reference: float, spec: SymbolSpec) -> Result[float, TradeError]
The take-profit price for a side trade entered at reference, on the tick grid.