NautilusTrader
ConceptsEvents
These docs track the unreleased nightly build and may change without notice. Switch to the latest stable docs.

PositionChanged

PositionChanged records an update that leaves a position open. The ExecutionEngine emits it when a fill changes an open position without closing it, or when a fill correction leaves the corrected position open. See From fill to position. Handler: on_position_changed.

Fields

See Position event fields for the complete field matrix. In addition to the opening snapshot fields, PositionChanged exposes:

FieldPython typeDescription
peak_quantityQuantityThe largest directional quantity reached by the position.
peak_qtyQuantityCompatibility alias for peak_quantity.
avg_px_closefloat or NoneThe average close price so far, if any quantity has closed.
realized_returnfloatThe realized return for the position.
realized_pnlMoney or NoneThe realized PnL, if available.
unrealized_pnlMoneySet to zero by the engine, not a mark‑to‑market calculation.
ts_openedintUNIX timestamp (nanoseconds) when the position opened.

Example

Reading the event in a strategy handler:

def on_position_changed(self, event: PositionChanged) -> None:
    self.log.info(
        f"Changed {event.instrument_id} to {event.signed_qty} (realized={event.realized_pnl})",
    )
  • Events - Event categories, dispatch, and the fill‑to‑position chain.
  • Positions - Position lifecycle, aggregation, and PnL.
  • Orders - Orders whose fills open and close positions.

On this page