Skip to content

Orders and stops

Side

Bases: Enum

Trade direction. Calls also accept "buy", "sell", "long", "short".

BUY class-attribute instance-attribute

BUY = 'buy'

SELL class-attribute instance-attribute

SELL = 'sell'

opposite property

opposite: Side

The side that closes a position of this side.

sign property

sign: int

1 for BUY, -1 for SELL: the direction in which profit grows.

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".

value instance-attribute

value: float

kind instance-attribute

kind: StopKind

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.

StopKind

Bases: Enum

How a Stop value is read: an absolute price or a distance in points.

PRICE class-attribute instance-attribute

PRICE = 'price'

POINTS class-attribute instance-attribute

POINTS = 'points'

PendingKind

Bases: Enum

The type of a pending order.

LIMIT class-attribute instance-attribute

LIMIT = 'limit'

STOP class-attribute instance-attribute

STOP = 'stop'

STOP_LIMIT class-attribute instance-attribute

STOP_LIMIT = 'stop_limit'