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

PositionOpened

PositionOpened represents a position having been opened. The ExecutionEngine emits it when a fill creates a new position (see From fill to position). Handler: on_position_opened.

Fields

PositionOpened shares the position event field set. See Position event fields for the full matrix across the three events. The fields that distinguish PositionOpened:

FieldPython typeDescription
entryOrderSideThe entry order side that opened the position.
sidePositionSideThe current position side (LONG or SHORT).
quantityQuantityThe current open quantity.
avg_px_openfloatThe average open price.
realized_pnlMoneyThe realized PnL for the position.

At open, closing_order_id is None, and avg_px_close and realized_return are zero.

Example

Reading the event in a strategy handler:

def on_position_opened(self, event: PositionOpened) -> None:
    self.log.info(
        f"Opened {event.side} {event.quantity} {event.instrument_id} "
        f"@ {event.avg_px_open}",
    )
  • 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