Events

Defines the fundamental event types represented within the trading domain.

Account Events

class AccountState ( AccountId account_id , AccountType account_type , Currency base_currency , bool reported , list balances , list margins , dict info , UUID4 event_id , uint64_t ts_event , uint64_t ts_init )

Bases: nautilus_trader.core.message.Event

Represents an event which includes information on the state of the account.

Parameters
  • account_id ( AccountId ) – The account ID.

  • account_type ( AccountId ) – The account type for the event.

  • base_currency ( Currency , optional ) – The account base currency. Use None for multi-currency accounts.

  • reported ( bool ) – If the state is reported from the exchange (otherwise system calculated).

  • balances ( list [ AccountBalance ] ) – The account balances.

  • margins ( list [ MarginBalance ] ) – The margin balances (can be empty).

  • info ( dict [ str , object ] ) – The additional implementation specific account information.

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the account state event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

Raises

ValueError – If balances is empty.

account_id

The account ID associated with the event.

Returns

AccountId

account_type

The account type for the event.

Returns

AccountType

balances

The account balances.

Returns

list[AccountBalance]

base_currency

The account type for the event.

Returns

Currency or None

category

The message category.

Returns

MessageCategory

static from_dict ( dict values ) AccountState

Return an account state event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

AccountState

id

The message ID.

Returns

UUID4

info

The additional implementation specific account information.

Returns

dict[str, object]

is_reported

If the state is reported from the exchange (otherwise system calculated).

Returns

bool

margins

The margin balances.

Returns

list[MarginBalance]

static to_dict ( AccountState obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

Order Events

class OrderAccepted ( TraderId trader_id , StrategyId strategy_id , AccountId account_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , UUID4 event_id , uint64_t ts_event , uint64_t ts_init , bool reconciliation=False )

Bases: nautilus_trader.model.events.order.OrderEvent

Represents an event where an order has been accepted by the trading venue.

This event often corresponds to a NEW OrdStatus <39> field in FIX trade reports.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • account_id ( AccountId ) – The account ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order accepted event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

  • reconciliation ( bool , default False ) – If the event was generated during reconciliation.

References

https://www.onixs.biz/fix-dictionary/5.0.SP2/tagNum_39.html

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

static from_dict ( dict values ) OrderAccepted

Return an order accepted event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

OrderAccepted

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

reconciliation

If the event was generated during reconciliation.

Returns

bool

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( OrderAccepted obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

class OrderCancelRejected ( TraderId trader_id, StrategyId strategy_id, AccountId account_id, InstrumentId instrument_id, ClientOrderId client_order_id, VenueOrderId venue_order_id: Optional[VenueOrderId], unicode reason, UUID4 event_id, uint64_t ts_event, uint64_t ts_init, bool reconciliation=False )

Bases: nautilus_trader.model.events.order.OrderEvent

Represents an event where a CancelOrder command has been rejected by the trading venue.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • account_id ( AccountId ) – The account ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • reason ( str ) – The order cancel rejected reason.

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order cancel rejected event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

  • reconciliation ( bool , default False ) – If the event was generated during reconciliation.

Raises

ValueError – If reason is not a valid string.

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

static from_dict ( dict values ) OrderCancelRejected

Return an order cancel rejected event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

OrderCancelRejected

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

reason

The reason for order cancel rejection.

Returns

str

reconciliation

If the event was generated during reconciliation.

Returns

bool

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( OrderCancelRejected obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

class OrderCanceled ( TraderId trader_id , StrategyId strategy_id , AccountId account_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , UUID4 event_id , uint64_t ts_event , uint64_t ts_init , bool reconciliation=False )

Bases: nautilus_trader.model.events.order.OrderEvent

Represents an event where an order has been canceled at the trading venue.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • account_id ( AccountId ) – The account ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when order canceled event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

  • reconciliation ( bool , default False ) – If the event was generated during reconciliation.

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

static from_dict ( dict values ) OrderCanceled

Return an order canceled event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

OrderCanceled

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

reconciliation

If the event was generated during reconciliation.

Returns

bool

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( OrderCanceled obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

class OrderDenied ( TraderId trader_id , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , unicode reason , UUID4 event_id , uint64_t ts_init )

Bases: nautilus_trader.model.events.order.OrderEvent

Represents an event where an order has been denied by the Nautilus system.

This could be due an unsupported feature, a risk limit exceedance, or for any other reason that an otherwise valid order is not able to be submitted.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • reason ( str ) – The order denied reason.

  • event_id ( UUID4 ) – The event ID.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

Raises

ValueError – If denied_reason is not a valid_string.

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

static from_dict ( dict values ) OrderDenied

Return an order denied event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

OrderDenied

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

reason

The reason the order was denied.

Returns

str

reconciliation

If the event was generated during reconciliation.

Returns

bool

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( OrderDenied obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

class OrderEvent ( TraderId trader_id, StrategyId strategy_id, AccountId account_id: Optional[AccountId], InstrumentId instrument_id, ClientOrderId client_order_id, VenueOrderId venue_order_id: Optional[VenueOrderId], UUID4 event_id, uint64_t ts_event, uint64_t ts_init, bool reconciliation )

Bases: nautilus_trader.core.message.Event

The abstract base class for all order events.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • account_id (AccountId, optional with no default so None must be passed explicitly) – The account ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id (VenueOrderId, optional with no default so None must be passed explicitly) – The venue order ID (assigned by the venue).

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

  • reconciliation ( bool ) – If the event was generated during reconciliation.

Warning

This class should not be used directly, but through a concrete subclass.

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

reconciliation

If the event was generated during reconciliation.

Returns

bool

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

class OrderExpired ( TraderId trader_id , StrategyId strategy_id , AccountId account_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , UUID4 event_id , uint64_t ts_event , uint64_t ts_init , bool reconciliation=False )

Bases: nautilus_trader.model.events.order.OrderEvent

Represents an event where an order has expired at the trading venue.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • account_id ( AccountId ) – The account ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order expired event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

  • reconciliation ( bool , default False ) – If the event was generated during reconciliation.

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

static from_dict ( dict values ) OrderExpired

Return an order expired event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

OrderExpired

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

reconciliation

If the event was generated during reconciliation.

Returns

bool

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( OrderExpired obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

class OrderFilled ( TraderId trader_id, StrategyId strategy_id, AccountId account_id, InstrumentId instrument_id, ClientOrderId client_order_id, VenueOrderId venue_order_id, TradeId trade_id, PositionId position_id: Optional[PositionId], OrderSide order_side, OrderType order_type, Quantity last_qty, Price last_px, Currency currency, Money commission, LiquiditySide liquidity_side, UUID4 event_id, uint64_t ts_event, uint64_t ts_init, bool reconciliation=False, dict info=None )

Bases: nautilus_trader.model.events.order.OrderEvent

Represents an event where an order has been filled at the exchange.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • account_id ( AccountId ) – The account ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • trade_id ( TradeId ) – The trade match ID (assigned by the venue).

  • position_id (PositionId, optional with no default so None must be passed explicitly) – The position ID associated with the order fill (assigned by the venue).

  • order_side ( OrderType ) – The execution order side.

  • order_side – The execution order type.

  • last_qty ( Quantity ) – The fill quantity for this execution.

  • last_px ( Price ) – The fill price for this execution (not average price).

  • currency ( Currency ) – The currency of the price.

  • commission ( Money ) – The fill commission.

  • liquidity_side (LiquiditySide { NONE , MAKER , TAKER }) – The execution liquidity side.

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order filled event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

  • info ( dict [ str , object ] , optional ) – The additional fill information.

  • reconciliation ( bool , default False ) – If the event was generated during reconciliation.

Raises
  • ValueError – If order_side is NONE .

  • ValueError – If last_qty is not positive (> 0).

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

commission

The commission generated from the fill.

Returns

Money

currency

The currency of the price.

Returns

Currency

static from_dict ( dict values ) OrderFilled

Return an order filled event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

OrderFilled

id

The message ID.

Returns

UUID4

info

The additional fill information.

Returns

dict[str, object]

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

is_buy

Return whether the fill order side is BUY .

Returns

bool

is_sell

Return whether the fill order side is SELL .

Returns

bool

last_px

The fill price for this execution.

Returns

Price

last_qty

The fill quantity.

Returns

Quantity

liquidity_side

The liquidity side of the event { MAKER , TAKER }.

Returns

LiquiditySide

order_side

The order side.

Returns

OrderSide

order_type

The order type.

Returns

OrderType

position_id

The position ID (assigned by the venue).

Returns

PositionId or None

reconciliation

If the event was generated during reconciliation.

Returns

bool

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( OrderFilled obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trade_id

The trade match ID (assigned by the venue).

Returns

TradeId

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

class OrderInitialized ( TraderId trader_id, StrategyId strategy_id, InstrumentId instrument_id, ClientOrderId client_order_id, OrderSide order_side, OrderType order_type, Quantity quantity, TimeInForce time_in_force, bool post_only, bool reduce_only, dict options, OrderListId order_list_id: Optional[OrderListId], ContingencyType contingency_type, list linked_order_ids: Optional[List[ClientOrderId]], ClientOrderId parent_order_id: Optional[ClientOrderId], unicode tags: Optional[str], UUID4 event_id, uint64_t ts_init, bool reconciliation=False )

Bases: nautilus_trader.model.events.order.OrderEvent

Represents an event where an order has been initialized.

This is a seed event which can instantiate any order through a creation method. This event should contain enough information to be able to send it ‘over the wire’ and have a valid order created with exactly the same properties as if it had been instantiated locally.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • order_side (OrderSide { BUY , SELL }) – The order side.

  • order_type ( OrderType ) – The order type.

  • quantity ( Quantity ) – The order quantity.

  • time_in_force (TimeInForce { GTC , IOC , FOK , GTD , DAY , AT_THE_OPEN , AT_THE_CLOSE }) – The order time in force.

  • post_only ( bool ) – If the order will only provide liquidity (make a market).

  • reduce_only ( bool ) – If the order carries the ‘reduce-only’ execution instruction.

  • options ( dict [ str , str ] ) – The order initialization options. Contains mappings for specific order parameters.

  • order_list_id (OrderListId, optional with no default so None must be passed explicitly) – The order list ID associated with the order.

  • contingency_type ( ContingencyType ) – The order contingency type.

  • linked_order_ids (list[ClientOrderId], optional with no default so None must be passed explicitly) – The order linked client order ID(s).

  • parent_order_id (ClientOrderId, optional with no default so None must be passed explicitly) – The orders parent client order ID.

  • tags (str, optional with no default so None must be passed explicitly) – The custom user tags for the order. These are optional and can contain any arbitrary delimiter if required.

  • event_id ( UUID4 ) – The event ID.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

  • reconciliation ( bool , default False ) – If the event was generated during reconciliation.

Raises

ValueError – If order_side is NONE .

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

contingency_type

The orders contingency type.

Returns

ContingencyType

static from_dict ( dict values ) OrderInitialized

Return an order initialized event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

OrderInitialized

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

linked_order_ids

The orders linked client order ID(s).

Returns

list[ClientOrderId] or None

options

The order initialization options.

Returns

dict

order_list_id

The order list ID associated with the order.

Returns

OrderListId or None

order_type

The order type.

Returns

OrderType

parent_order_id

The orders parent client order ID.

Returns

ClientOrderId or None

post_only

If the order will only provide liquidity (make a market).

Returns

bool

quantity

The order quantity.

Returns

Quantity

reconciliation

If the event was generated during reconciliation.

Returns

bool

reduce_only

If the order carries the ‘reduce-only’ execution instruction.

Returns

bool

side

The order side.

Returns

OrderSide

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

tags

The order custom user tags.

Returns

str or None

time_in_force

The order time in force.

Returns

TimeInForce

static to_dict ( OrderInitialized obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

class OrderModifyRejected ( TraderId trader_id, StrategyId strategy_id, AccountId account_id, InstrumentId instrument_id, ClientOrderId client_order_id, VenueOrderId venue_order_id: Optional[VenueOrderId], unicode reason, UUID4 event_id, uint64_t ts_event, uint64_t ts_init, bool reconciliation=False )

Bases: nautilus_trader.model.events.order.OrderEvent

Represents an event where a ModifyOrder command has been rejected by the trading venue.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • account_id ( AccountId ) – The account ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id (VenueOrderId, optional with no default so None must be passed explicitly) – The venue order ID (assigned by the venue).

  • reason ( str ) – The order update rejected reason.

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order update rejected event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

  • reconciliation ( bool , default False ) – If the event was generated during reconciliation.

Raises

ValueError – If reason is not a valid string.

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

static from_dict ( dict values ) OrderModifyRejected

Return an order update rejected event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

OrderModifyRejected

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

reason

The reason for modify order rejection.

Returns

str

reconciliation

If the event was generated during reconciliation.

Returns

bool

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( OrderModifyRejected obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

class OrderPendingCancel ( TraderId trader_id, StrategyId strategy_id, AccountId account_id, InstrumentId instrument_id, ClientOrderId client_order_id, VenueOrderId venue_order_id: Optional[VenueOrderId], UUID4 event_id, uint64_t ts_event, uint64_t ts_init, bool reconciliation=False )

Bases: nautilus_trader.model.events.order.OrderEvent

Represents an event where a CancelOrder command has been sent to the trading venue.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • account_id ( AccountId ) – The account ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id (VenueOrderId, optional with no default so None must be passed explicitly) – The venue order ID (assigned by the venue).

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order pending cancel event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

  • reconciliation ( bool , default False ) – If the event was generated during reconciliation.

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

static from_dict ( dict values ) OrderPendingCancel

Return an order pending cancel event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

OrderPendingCancel

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

reconciliation

If the event was generated during reconciliation.

Returns

bool

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( OrderPendingCancel obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

class OrderPendingUpdate ( TraderId trader_id, StrategyId strategy_id, AccountId account_id, InstrumentId instrument_id, ClientOrderId client_order_id, VenueOrderId venue_order_id: Optional[VenueOrderId], UUID4 event_id, uint64_t ts_event, uint64_t ts_init, bool reconciliation=False )

Bases: nautilus_trader.model.events.order.OrderEvent

Represents an event where an ModifyOrder command has been sent to the trading venue.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • account_id ( AccountId ) – The account ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id (VenueOrderId, optional with no default so None must be passed explicitly) – The venue order ID (assigned by the venue).

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order pending update event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

  • reconciliation ( bool , default False ) – If the event was generated during reconciliation.

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

static from_dict ( dict values ) OrderPendingUpdate

Return an order pending update event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

OrderPendingUpdate

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

reconciliation

If the event was generated during reconciliation.

Returns

bool

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( OrderPendingUpdate obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

class OrderRejected ( TraderId trader_id , StrategyId strategy_id , AccountId account_id , InstrumentId instrument_id , ClientOrderId client_order_id , unicode reason , UUID4 event_id , uint64_t ts_event , uint64_t ts_init , bool reconciliation=False )

Bases: nautilus_trader.model.events.order.OrderEvent

Represents an event where an order has been rejected by the trading venue.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • account_id ( AccountId ) – The account ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • reason ( datetime ) – The order rejected reason.

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order rejected event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

  • reconciliation ( bool , default False ) – If the event was generated during reconciliation.

Raises

ValueError – If reason is not a valid string.

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

static from_dict ( dict values ) OrderRejected

Return an order rejected event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

OrderRejected

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

reason

The reason the order was rejected.

Returns

str

reconciliation

If the event was generated during reconciliation.

Returns

bool

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( OrderRejected obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

class OrderSubmitted ( TraderId trader_id , StrategyId strategy_id , AccountId account_id , InstrumentId instrument_id , ClientOrderId client_order_id , UUID4 event_id , uint64_t ts_event , uint64_t ts_init )

Bases: nautilus_trader.model.events.order.OrderEvent

Represents an event where an order has been submitted by the system to the trading venue.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • account_id ( AccountId ) – The account ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order submitted event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

static from_dict ( dict values ) OrderSubmitted

Return an order submitted event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

OrderSubmitted

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

reconciliation

If the event was generated during reconciliation.

Returns

bool

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( OrderSubmitted obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

class OrderTriggered ( TraderId trader_id , StrategyId strategy_id , AccountId account_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , UUID4 event_id , uint64_t ts_event , uint64_t ts_init , bool reconciliation=False )

Bases: nautilus_trader.model.events.order.OrderEvent

Represents an event where an order has triggered.

Applicable to StopLimit orders only.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • account_id ( AccountId ) – The account ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order triggered event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

  • reconciliation ( bool , default False ) – If the event was generated during reconciliation.

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

static from_dict ( dict values ) OrderTriggered

Return an order triggered event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

OrderTriggered

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

reconciliation

If the event was generated during reconciliation.

Returns

bool

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( OrderTriggered obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

class OrderUpdated ( TraderId trader_id, StrategyId strategy_id, AccountId account_id, InstrumentId instrument_id, ClientOrderId client_order_id, VenueOrderId venue_order_id, Quantity quantity, Price price: Optional[Price], Price trigger_price: Optional[Price], UUID4 event_id, uint64_t ts_event, uint64_t ts_init, bool reconciliation=False )

Bases: nautilus_trader.model.events.order.OrderEvent

Represents an event where an order has been updated at the trading venue.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • account_id ( AccountId ) – The account ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • quantity ( Quantity ) – The orders current quantity.

  • price (Price, optional with no default so None must be passed explicitly) – The orders current price.

  • trigger_price (Price, optional with no default so None must be passed explicitly) – The orders current trigger.

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order updated event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

  • reconciliation ( bool , default False ) – If the event was generated during reconciliation.

Raises

ValueError – If quantity is not positive (> 0).

account_id

The account ID associated with the event.

Returns

AccountId or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID associated with the event.

Returns

ClientOrderId

static from_dict ( dict values ) OrderUpdated

Return an order updated event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

OrderUpdated

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

price

The orders current price.

Returns

Price

quantity

The orders current quantity.

Returns

Quantity

reconciliation

If the event was generated during reconciliation.

Returns

bool

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( OrderUpdated obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

trigger_price

The orders current trigger price.

Returns

Price or None

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

venue_order_id

The venue order ID associated with the event.

Returns

VenueOrderId or None

Position Events

class PositionChanged ( TraderId trader_id , StrategyId strategy_id , InstrumentId instrument_id , PositionId position_id , AccountId account_id , ClientOrderId opening_order_id , OrderSide entry , PositionSide side , double net_qty , Quantity quantity , Quantity peak_qty , Quantity last_qty , Price last_px , Currency currency , double avg_px_open , double avg_px_close , double realized_return , Money realized_pnl , Money unrealized_pnl , UUID4 event_id , uint64_t ts_opened , uint64_t ts_event , uint64_t ts_init )

Bases: nautilus_trader.model.events.position.PositionEvent

Represents an event where a position has changed.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • position_id ( PositionId ) – The position IDt.

  • account_id ( AccountId ) – The strategy ID.

  • opening_order_id ( ClientOrderId ) – The client order ID for the order which opened the position.

  • strategy_id – The strategy ID associated with the event.

  • entry (OrderSide { BUY , SELL }) – The position entry order side.

  • side (PositionSide { FLAT , LONG , SHORT }) – The current position side.

  • net_qty ( double ) – The current net quantity (positive for LONG , negative for SHORT ).

  • quantity ( Quantity ) – The current open quantity.

  • peak_qty ( Quantity ) – The peak directional quantity reached by the position.

  • last_qty ( Quantity ) – The last fill quantity for the position.

  • last_px ( Price ) – The last fill price for the position (not average price).

  • currency ( Currency ) – The position quote currency.

  • avg_px_open ( Decimal ) – The average open price.

  • avg_px_close ( Decimal , optional ) – The average close price.

  • realized_return ( Decimal ) – The realized return for the position.

  • realized_pnl ( Money ) – The realized PnL for the position.

  • unrealized_pnl ( Money ) – The unrealized PnL for the position.

  • event_id ( UUID4 ) – The event ID.

  • ts_opened ( uint64_t ) – The UNIX timestamp (nanoseconds) when the position opened event occurred.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the position changed event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

account_id

The account ID associated with the position.

Returns

AccountId

avg_px_close

The average closing price.

Returns

double

avg_px_open

The average open price.

Returns

double

category

The message category.

Returns

MessageCategory

closing_order_id

The client order ID for the order which closed the position.

Returns

ClientOrderId or None

static create ( Position position , OrderFilled fill , UUID4 event_id , uint64_t ts_init )

Return a position changed event from the given params.

Parameters
  • position ( Position ) – The position for the event.

  • fill ( OrderFilled ) – The order fill for the event.

  • event_id ( UUID4 ) – The event ID.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

PositionChanged

currency

The position quote currency.

Returns

Currency

duration_ns

The total open duration (nanoseconds).

Returns

uint64_t

entry

The entry direction from open.

Returns

OrderSide

static from_dict ( dict values ) PositionChanged

Return a position changed event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

PositionChanged

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

last_px

The last fill price for the position.

Returns

Price

last_qty

The last fill quantity for the position.

Returns

Quantity

net_qty

The net quantity (positive for LONG , negative for SHORT ).

Returns

Decimal

opening_order_id

The client order ID for the order which opened the position.

Returns

ClientOrderId

peak_qty

The peak directional quantity reached by the position.

Returns

Quantity

position_id

The position ID associated with the event.

Returns

PositionId

quantity

The position open quantity.

Returns

Quantity

realized_pnl

The realized PnL for the position (including commissions).

Returns

Money

realized_return

The realized return for the position.

Returns

double

side

The position side.

Returns

PositionSide

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( PositionChanged obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_closed

The UNIX timestamp (nanoseconds) when the position was closed.

Returns

uint64_t

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

ts_opened

The UNIX timestamp (nanoseconds) when the position was opened.

Returns

uint64_t

unrealized_pnl

The unrealized PnL for the position (including commissions).

Returns

Money

class PositionClosed ( TraderId trader_id , StrategyId strategy_id , InstrumentId instrument_id , PositionId position_id , AccountId account_id , ClientOrderId opening_order_id , ClientOrderId closing_order_id , OrderSide entry , PositionSide side , double net_qty , Quantity quantity , Quantity peak_qty , Quantity last_qty , Price last_px , Currency currency , double avg_px_open , double avg_px_close , double realized_return , Money realized_pnl , UUID4 event_id , uint64_t ts_opened , uint64_t ts_closed , uint64_t duration_ns , uint64_t ts_init )

Bases: nautilus_trader.model.events.position.PositionEvent

Represents an event where a position has been closed.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • position_id ( PositionId ) – The position IDt.

  • account_id ( AccountId ) – The strategy ID.

  • opening_order_id ( ClientOrderId ) – The client order ID for the order which opened the position.

  • closing_order_id ( ClientOrderId ) – The client order ID for the order which closed the position.

  • strategy_id – The strategy ID associated with the event.

  • entry (OrderSide { BUY , SELL }) – The position entry order side.

  • side (PositionSide { FLAT }) – The current position side.

  • net_qty ( double ) – The current net quantity (positive for LONG , negative for SHORT ).

  • quantity ( Quantity ) – The current open quantity.

  • peak_qty ( Quantity ) – The peak directional quantity reached by the position.

  • last_qty ( Quantity ) – The last fill quantity for the position.

  • last_px ( Price ) – The last fill price for the position (not average price).

  • currency ( Currency ) – The position quote currency.

  • avg_px_open ( Decimal ) – The average open price.

  • avg_px_close ( Decimal ) – The average close price.

  • realized_return ( Decimal ) – The realized return for the position.

  • realized_pnl ( Money ) – The realized PnL for the position.

  • event_id ( UUID4 ) – The event ID.

  • ts_opened ( uint64_t ) – The UNIX timestamp (nanoseconds) when the position opened event occurred.

  • ts_closed ( uint64_t ) – The UNIX timestamp (nanoseconds) when the position closed event occurred.

  • duration_ns ( uint64_t ) – The total open duration (nanoseconds).

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

account_id

The account ID associated with the position.

Returns

AccountId

avg_px_close

The average closing price.

Returns

double

avg_px_open

The average open price.

Returns

double

category

The message category.

Returns

MessageCategory

closing_order_id

The client order ID for the order which closed the position.

Returns

ClientOrderId or None

static create ( Position position , OrderFilled fill , UUID4 event_id , uint64_t ts_init )

Return a position closed event from the given params.

Parameters
  • position ( Position ) – The position for the event.

  • fill ( OrderFilled ) – The order fill for the event.

  • event_id ( UUID4 ) – The event ID.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

PositionClosed

currency

The position quote currency.

Returns

Currency

duration_ns

The total open duration (nanoseconds).

Returns

uint64_t

entry

The entry direction from open.

Returns

OrderSide

static from_dict ( dict values ) PositionClosed

Return a position closed event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

PositionClosed

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

last_px

The last fill price for the position.

Returns

Price

last_qty

The last fill quantity for the position.

Returns

Quantity

net_qty

The net quantity (positive for LONG , negative for SHORT ).

Returns

Decimal

opening_order_id

The client order ID for the order which opened the position.

Returns

ClientOrderId

peak_qty

The peak directional quantity reached by the position.

Returns

Quantity

position_id

The position ID associated with the event.

Returns

PositionId

quantity

The position open quantity.

Returns

Quantity

realized_pnl

The realized PnL for the position (including commissions).

Returns

Money

realized_return

The realized return for the position.

Returns

double

side

The position side.

Returns

PositionSide

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( PositionClosed obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_closed

The UNIX timestamp (nanoseconds) when the position was closed.

Returns

uint64_t

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

ts_opened

The UNIX timestamp (nanoseconds) when the position was opened.

Returns

uint64_t

unrealized_pnl

The unrealized PnL for the position (including commissions).

Returns

Money

class PositionEvent ( TraderId trader_id, StrategyId strategy_id, InstrumentId instrument_id, PositionId position_id, AccountId account_id, ClientOrderId opening_order_id, ClientOrderId closing_order_id: Optional[ClientOrderId], OrderSide entry, PositionSide side, double net_qty, Quantity quantity, Quantity peak_qty, Quantity last_qty, Price last_px, Currency currency, double avg_px_open, double avg_px_close, double realized_return, Money realized_pnl, Money unrealized_pnl, UUID4 event_id, uint64_t ts_opened, uint64_t ts_closed, uint64_t duration_ns, uint64_t ts_event, uint64_t ts_init )

Bases: nautilus_trader.core.message.Event

The abstract base class for all position events.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • position_id ( PositionId ) – The position IDt.

  • account_id ( AccountId ) – The strategy ID.

  • opening_order_id ( ClientOrderId ) – The client order ID for the order which opened the position.

  • closing_order_id ( ClientOrderId ) – The client order ID for the order which closed the position.

  • entry (OrderSide { BUY , SELL }) – The position entry order side.

  • side (PositionSide { FLAT , LONG , SHORT }) – The current position side.

  • net_qty ( double ) – The current net quantity (positive for LONG , negative for SHORT ).

  • quantity ( Quantity ) – The current open quantity.

  • peak_qty ( Quantity ) – The peak directional quantity reached by the position.

  • last_qty ( Quantity ) – The last fill quantity for the position.

  • last_px ( Price ) – The last fill price for the position (not average price).

  • currency ( Currency ) – The position quote currency.

  • avg_px_open ( double ) – The average open price.

  • avg_px_close ( double ) – The average close price.

  • realized_return ( double ) – The realized return for the position.

  • realized_pnl ( Money ) – The realized PnL for the position.

  • unrealized_pnl ( Money ) – The unrealized PnL for the position.

  • event_id ( UUID4 ) – The event ID.

  • ts_opened ( uint64_t ) – The UNIX timestamp (nanoseconds) when the position opened event occurred.

  • ts_closed ( uint64_t ) – The UNIX timestamp (nanoseconds) when the position closed event occurred.

  • duration_ns ( uint64_t ) – The total open duration (nanoseconds), will be 0 if still open.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

Warning

This class should not be used directly, but through a concrete subclass.

account_id

The account ID associated with the position.

Returns

AccountId

avg_px_close

The average closing price.

Returns

double

avg_px_open

The average open price.

Returns

double

category

The message category.

Returns

MessageCategory

closing_order_id

The client order ID for the order which closed the position.

Returns

ClientOrderId or None

currency

The position quote currency.

Returns

Currency

duration_ns

The total open duration (nanoseconds).

Returns

uint64_t

entry

The entry direction from open.

Returns

OrderSide

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

last_px

The last fill price for the position.

Returns

Price

last_qty

The last fill quantity for the position.

Returns

Quantity

net_qty

The net quantity (positive for LONG , negative for SHORT ).

Returns

Decimal

opening_order_id

The client order ID for the order which opened the position.

Returns

ClientOrderId

peak_qty

The peak directional quantity reached by the position.

Returns

Quantity

position_id

The position ID associated with the event.

Returns

PositionId

quantity

The position open quantity.

Returns

Quantity

realized_pnl

The realized PnL for the position (including commissions).

Returns

Money

realized_return

The realized return for the position.

Returns

double

side

The position side.

Returns

PositionSide

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_closed

The UNIX timestamp (nanoseconds) when the position was closed.

Returns

uint64_t

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

ts_opened

The UNIX timestamp (nanoseconds) when the position was opened.

Returns

uint64_t

unrealized_pnl

The unrealized PnL for the position (including commissions).

Returns

Money

class PositionOpened ( TraderId trader_id , StrategyId strategy_id , InstrumentId instrument_id , PositionId position_id , AccountId account_id , ClientOrderId opening_order_id , OrderSide entry , PositionSide side , double net_qty , Quantity quantity , Quantity peak_qty , Quantity last_qty , Price last_px , Currency currency , double avg_px_open , Money realized_pnl , UUID4 event_id , uint64_t ts_event , uint64_t ts_init )

Bases: nautilus_trader.model.events.position.PositionEvent

Represents an event where a position has been opened.

Parameters
  • trader_id ( TraderId ) – The trader ID.

  • strategy_id ( StrategyId ) – The strategy ID.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • position_id ( PositionId ) – The position IDt.

  • account_id ( AccountId ) – The strategy ID.

  • opening_order_id ( ClientOrderId ) – The client order ID for the order which opened the position.

  • strategy_id – The strategy ID associated with the event.

  • entry (OrderSide { BUY , SELL }) – The position entry order side.

  • side (PositionSide { LONG , SHORT }) – The current position side.

  • net_qty ( double ) – The current net quantity (positive for LONG , negative for SHORT ).

  • quantity ( Quantity ) – The current open quantity.

  • peak_qty ( Quantity ) – The peak directional quantity reached by the position.

  • last_qty ( Quantity ) – The last fill quantity for the position.

  • last_px ( Price ) – The last fill price for the position (not average price).

  • currency ( Currency ) – The position quote currency.

  • avg_px_open ( double ) – The average open price.

  • realized_pnl ( Money ) – The realized PnL for the position.

  • event_id ( UUID4 ) – The event ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the position opened event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

account_id

The account ID associated with the position.

Returns

AccountId

avg_px_close

The average closing price.

Returns

double

avg_px_open

The average open price.

Returns

double

category

The message category.

Returns

MessageCategory

closing_order_id

The client order ID for the order which closed the position.

Returns

ClientOrderId or None

static create ( Position position , OrderFilled fill , UUID4 event_id , uint64_t ts_init )

Return a position opened event from the given params.

Parameters
  • position ( Position ) – The position for the event.

  • fill ( OrderFilled ) – The order fill for the event.

  • event_id ( UUID4 ) – The event ID.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

PositionOpened

currency

The position quote currency.

Returns

Currency

duration_ns

The total open duration (nanoseconds).

Returns

uint64_t

entry

The entry direction from open.

Returns

OrderSide

static from_dict ( dict values ) PositionOpened

Return a position opened event from the given dict values.

Parameters

values ( dict [ str , object ] ) – The values for initialization.

Returns

PositionOpened

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the event.

Returns

InstrumentId

last_px

The last fill price for the position.

Returns

Price

last_qty

The last fill quantity for the position.

Returns

Quantity

net_qty

The net quantity (positive for LONG , negative for SHORT ).

Returns

Decimal

opening_order_id

The client order ID for the order which opened the position.

Returns

ClientOrderId

peak_qty

The peak directional quantity reached by the position.

Returns

Quantity

position_id

The position ID associated with the event.

Returns

PositionId

quantity

The position open quantity.

Returns

Quantity

realized_pnl

The realized PnL for the position (including commissions).

Returns

Money

realized_return

The realized return for the position.

Returns

double

side

The position side.

Returns

PositionSide

strategy_id

The strategy ID associated with the event.

Returns

StrategyId

static to_dict ( PositionOpened obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the event.

Returns

TraderId

ts_closed

The UNIX timestamp (nanoseconds) when the position was closed.

Returns

uint64_t

ts_event

The UNIX timestamp (nanoseconds) when the event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

ts_opened

The UNIX timestamp (nanoseconds) when the position was opened.

Returns

uint64_t

unrealized_pnl

The unrealized PnL for the position (including commissions).

Returns

Money