Execution

The execution subpackage groups components relating to the execution stack for the platform.

The layered architecture of the execution stack somewhat mirrors the data stack with a central engine, cache layer beneath, database layer beneath, with alternative implementations able to be written on top.

Due to the high-performance, the core components are reusable between both backtest and live implementations - helping to ensure consistent logic for trading operations.

Client

class ExecutionClient ( ClientId client_id, Venue venue: Optional[Venue], OMSType oms_type, AccountType account_type, Currency base_currency: Optional[Currency], MessageBus msgbus, Cache cache, Clock clock, Logger logger, dict config=None )

Bases: nautilus_trader.common.component.Component

The abstract base class for all execution clients.

Parameters
  • client_id ( ClientId ) – The client ID.

  • venue (Venue, optional with no default so None must be passed explicitly) – The client venue. If multi-venue then can be None .

  • oms_type ( OMSType ) – The venues order management system type.

  • account_type ( AccountType ) – The account type for the client.

  • base_currency (Currency, optional with no default so None must be passed explicitly) – The account base currency. Use None for multi-currency accounts.

  • msgbus ( MessageBus ) – The message bus for the client.

  • cache ( Cache ) – The cache for the client.

  • clock ( Clock ) – The clock for the client.

  • logger ( Logger ) – The logger for the client.

  • config ( dict [ str , object ] , optional ) – The configuration for the instance.

Raises
  • ValueError – If client_id is not equal to account_id.get_issuer() .

  • ValueError – If oms_type is NONE value (must be defined).

Warning

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

account_id

The clients account ID.

Returns

AccountId or None

account_type

The clients account type.

Returns

AccountType

base_currency

The clients account base currency (None for multi-currency accounts).

Returns

Currency or None

cancel_all_orders ( self , CancelAllOrders command ) void

Cancel all orders for the instrument ID contained in the given command.

Parameters

command ( CancelAllOrders ) – The command to execute.

cancel_order ( self , CancelOrder command ) void

Cancel the order with the client order ID contained in the given command.

Parameters

command ( CancelOrder ) – The command to execute.

degrade ( self ) void

Degrade the component.

While executing on_degrade() , any exception will be logged and reraised. The component will remain in a DEGRADING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

dispose ( self ) void

Dispose of the component.

While executing on_dispose() , any exception will be logged and reraised. The component will remain in a DISPOSING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

fault ( self ) void

Fault the component.

This method is idempotent and irreversible. No other methods should be called after faulting.

While executing on_fault() , any exception will be logged and reraised. The component will remain in a FAULTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

classmethod fully_qualified_name ( type cls ) str

Return the fully qualified name for the components class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

generate_account_state ( self , list balances , list margins , bool reported , uint64_t ts_event , dict info=None ) void

Generate an AccountState event and publish on the message bus.

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

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

  • reported ( bool ) – If the balances are reported directly from the exchange.

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

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

generate_order_accepted ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderAccepted event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • 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).

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

generate_order_cancel_rejected ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , unicode reason , uint64_t ts_event ) void

Generate an OrderCancelRejected event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

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

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

generate_order_canceled ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderCanceled event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • 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).

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

generate_order_expired ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderExpired event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • 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).

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

generate_order_filled ( self, StrategyId strategy_id, InstrumentId instrument_id, ClientOrderId client_order_id, VenueOrderId venue_order_id, PositionId venue_position_id: Optional[PositionId], TradeId trade_id, OrderSide order_side, OrderType order_type, Quantity last_qty, Price last_px, Currency quote_currency, Money commission, LiquiditySide liquidity_side, uint64_t ts_event ) void

Generate an OrderFilled event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • 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 ID.

  • venue_position_id (PositionId, optional with no default so None must be passed explicitly) – The venue position ID associated with the order. If the trading venue has assigned a position ID / ticket then pass that here, otherwise pass None and the execution engine OMS will handle position ID resolution.

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

  • order_type ( OrderType ) – 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).

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

  • commission ( Money ) – The fill commission.

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

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

generate_order_modify_rejected ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , unicode reason , uint64_t ts_event ) void

Generate an OrderModifyRejected event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • 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 update rejected reason.

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

generate_order_pending_cancel ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderPendingCancel event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • 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).

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

generate_order_pending_update ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderPendingUpdate event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • 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).

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

generate_order_rejected ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , unicode reason , uint64_t ts_event ) void

Generate an OrderRejected event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • reason ( datetime ) – The order rejected reason.

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

generate_order_submitted ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , uint64_t ts_event ) void

Generate an OrderSubmitted event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

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

generate_order_triggered ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderTriggered event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • 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).

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

generate_order_updated ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , Quantity quantity , Price price , Price trigger_price , uint64_t ts_event , bool venue_order_id_modified=False ) void

Generate an OrderUpdated event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • 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 ) – The orders current price.

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

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

  • venue_order_id_modified ( bool ) – If the ID was modified for this event.

get_account ( self ) Account

Return the account for the client (if registered).

Returns

Account or None

id

The components ID.

Returns

ComponentId

is_connected

If the client is connected.

Returns

bool

is_degraded

Return whether the current component state is DEGRADED .

Returns

bool

is_disposed

Return whether the current component state is DISPOSED .

Returns

bool

is_faulted

Return whether the current component state is FAULTED .

Returns

bool

is_initialized

Return whether the component has been initialized (component.state >= INITIALIZED ).

Returns

bool

is_running

Return whether the current component state is RUNNING .

Returns

bool

is_stopped

Return whether the current component state is STOPPED .

Returns

bool

modify_order ( self , ModifyOrder command ) void

Modify the order with parameters contained in the command.

Parameters

command ( ModifyOrder ) – The command to execute.

oms_type

The venues order management system type.

Returns

OMSType

reset ( self ) void

Reset the component.

All stateful fields are reset to their initial value.

While executing on_reset() , any exception will be logged and reraised. The component will remain in a RESETTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

resume ( self ) void

Resume the component.

While executing on_resume() , any exception will be logged and reraised. The component will remain in a RESUMING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

start ( self ) void

Start the component.

While executing on_start() , any exception will be logged and reraised. The component will remain in a STARTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

state

Return the components current state.

Returns

ComponentState

stop ( self ) void

Stop the component.

While executing on_stop() , any exception will be logged and reraised. The component will remain in a STOPPING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

submit_order ( self , SubmitOrder command ) void

Submit the order contained in the given command for execution.

Parameters

command ( SubmitOrder ) – The command to execute.

submit_order_list ( self , SubmitOrderList command ) void

Submit the order list contained in the given command for execution.

Parameters

command ( SubmitOrderList ) – The command to execute.

sync_order_status ( self , QueryOrder command ) void

Request a reconciliation for the queried order which will generate an OrderStatusReport

trader_id

The trader ID associated with the component.

Returns

TraderId

type

The components type.

Returns

type

venue

The clients venue ID (if not a routing client).

Returns

Venue or None

Engine

The ExecutionEngine is the central component of the entire execution stack.

The execution engines primary responsibility is to orchestrate interactions between the ExecutionClient instances, and the rest of the platform. This includes sending commands to, and receiving events from, the trading venue endpoints via its registered execution clients.

The engine employs a simple fan-in fan-out messaging pattern to execute TradingCommand messages, and process AccountState or OrderEvent type messages.

Alternative implementations can be written on top of the generic engine - which just need to override the execute and process methods.

class ExecutionEngine ( MessageBus msgbus , Cache cache , Clock clock , Logger logger , config: Optional[ExecEngineConfig] = None )

Bases: nautilus_trader.common.component.Component

Provides a high-performance execution engine for the management of many ExecutionClient instances, and the asynchronous ingest and distribution of trading commands and events.

Parameters
  • msgbus ( MessageBus ) – The message bus for the engine.

  • cache ( Cache ) – The cache for the engine.

  • clock ( Clock ) – The clock for the engine.

  • logger ( Logger ) – The logger for the engine.

  • config ( ExecEngineConfig , optional ) – The configuration for the instance.

Raises

TypeError – If config is not of type ExecEngineConfig .

allow_cash_positions

If unleveraged spot cash assets should track positions.

Returns

bool

check_connected ( self ) bool

Check all of the engines clients are connected.

Returns

bool – True if all clients connected, else False.

check_disconnected ( self ) bool

Check all of the engines clients are disconnected.

Returns

bool – True if all clients disconnected, else False.

check_integrity ( self ) bool

Check integrity of data within the cache and clients.

Returns

bool – True if checks pass, else False.

check_residuals ( self ) bool

Check for any residual open state and log warnings if found.

‘Open state’ is considered to be open orders and open positions.

Returns

bool – True if residuals exist, else False.

command_count

The total count of commands received by the engine.

Returns

int

debug

If debug mode is active (will provide extra debug logging).

Returns

bool

default_client

Return the default execution client registered with the engine.

Returns

Optional[ClientId]

degrade ( self ) void

Degrade the component.

While executing on_degrade() , any exception will be logged and reraised. The component will remain in a DEGRADING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

deregister_client ( self , ExecutionClient client ) void

Deregister the given execution client from the execution engine.

Parameters

client ( ExecutionClient ) – The execution client to deregister.

Raises

ValueError – If client is not registered with the execution engine.

dispose ( self ) void

Dispose of the component.

While executing on_dispose() , any exception will be logged and reraised. The component will remain in a DISPOSING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

event_count

The total count of events received by the engine.

Returns

int

execute ( self , TradingCommand command ) void

Execute the given command.

Parameters

command ( TradingCommand ) – The command to execute.

fault ( self ) void

Fault the component.

This method is idempotent and irreversible. No other methods should be called after faulting.

While executing on_fault() , any exception will be logged and reraised. The component will remain in a FAULTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

flush_db ( self ) void

Flush the execution database which permanently removes all persisted data.

Warning

Permanent data loss.

classmethod fully_qualified_name ( type cls ) str

Return the fully qualified name for the components class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

id

The components ID.

Returns

ComponentId

is_degraded

Return whether the current component state is DEGRADED .

Returns

bool

is_disposed

Return whether the current component state is DISPOSED .

Returns

bool

is_faulted

Return whether the current component state is FAULTED .

Returns

bool

is_initialized

Return whether the component has been initialized (component.state >= INITIALIZED ).

Returns

bool

is_running

Return whether the current component state is RUNNING .

Returns

bool

is_stopped

Return whether the current component state is STOPPED .

Returns

bool

load_cache ( self ) void

Load the cache up from the execution database.

position_id_count ( self , StrategyId strategy_id ) int

The position ID count for the given strategy ID.

Parameters

strategy_id ( StrategyId ) – The strategy ID for the position count.

Returns

int

process ( self , OrderEvent event ) void

Process the given order event.

Parameters

event ( OrderEvent ) – The order event to process.

register_client ( self , ExecutionClient client ) void

Register the given execution client with the execution engine.

If the client.venue is None and a default routing client has not been previously registered then will be registered as such.

Parameters

client ( ExecutionClient ) – The execution client to register.

Raises

ValueError – If client is already registered with the execution engine.

register_default_client ( self , ExecutionClient client ) void

Register the given client as the default routing client (when a specific venue routing cannot be found).

Any existing default routing client will be overwritten.

Parameters

client ( ExecutionClient ) – The client to register.

register_oms_type ( self , Strategy strategy ) void

Register the given trading strategies OMS (Order Management System) type.

Parameters

strategy ( Strategy ) – The strategy for the registration.

register_venue_routing ( self , ExecutionClient client , Venue venue ) void

Register the given client to route orders to the given venue.

Any existing client in the routing map for the given venue will be overwritten.

Parameters
registered_clients

Return the execution clients registered with the engine.

Returns

list[ClientId]

report_count

The total count of reports received by the engine.

Returns

int

reset ( self ) void

Reset the component.

All stateful fields are reset to their initial value.

While executing on_reset() , any exception will be logged and reraised. The component will remain in a RESETTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

resume ( self ) void

Resume the component.

While executing on_resume() , any exception will be logged and reraised. The component will remain in a RESUMING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

start ( self ) void

Start the component.

While executing on_start() , any exception will be logged and reraised. The component will remain in a STARTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

state

Return the components current state.

Returns

ComponentState

stop ( self ) void

Stop the component.

While executing on_stop() , any exception will be logged and reraised. The component will remain in a STOPPING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

trader_id

The trader ID associated with the component.

Returns

TraderId

type

The components type.

Returns

type

Messages

class CancelAllOrders ( TraderId trader_id , StrategyId strategy_id , InstrumentId instrument_id , OrderSide order_side , UUID4 command_id , uint64_t ts_init , ClientId client_id=None )

Bases: nautilus_trader.execution.messages.TradingCommand

Represents a command to cancel all orders for an instrument.

Parameters
  • trader_id ( TraderId ) – The trader ID for the command.

  • strategy_id ( StrategyId ) – The strategy ID for the command.

  • instrument_id ( InstrumentId ) – The instrument ID for the command.

  • order_side ( OrderSide ) – The order side for the command.

  • command_id ( UUID4 ) – The command ID.

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

  • client_id ( ClientId , optional ) – The execution client ID for the command.

category

The message category.

Returns

MessageCategory

client_id

The execution client ID for the command.

Returns

ClientId or None

static from_dict ( dict values ) CancelAllOrders

Return a cancel order command from the given dict values.

Parameters

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

Returns

CancelAllOrders

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the command.

Returns

InstrumentId

order_side

The order side for the command.

Returns

OrderSide

strategy_id

The strategy ID associated with the command.

Returns

StrategyId

static to_dict ( CancelAllOrders obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the command.

Returns

TraderId

ts_init

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

Returns

uint64_t

class CancelOrder ( TraderId trader_id, StrategyId strategy_id, InstrumentId instrument_id, ClientOrderId client_order_id, VenueOrderId venue_order_id: Optional[VenueOrderId], UUID4 command_id, uint64_t ts_init, ClientId client_id=None )

Bases: nautilus_trader.execution.messages.TradingCommand

Represents a command to cancel an order.

Parameters
  • trader_id ( TraderId ) – The trader ID for the command.

  • strategy_id ( StrategyId ) – The strategy ID for the command.

  • instrument_id ( InstrumentId ) – The instrument ID for the command.

  • client_order_id ( ClientOrderId ) – The client order ID to cancel.

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

  • command_id ( UUID4 ) – The command ID.

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

  • client_id ( ClientId , optional ) – The execution client ID for the command.

References

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

category

The message category.

Returns

MessageCategory

client_id

The execution client ID for the command.

Returns

ClientId or None

client_order_id

The client order ID associated with the command.

Returns

ClientOrderId

static from_dict ( dict values ) CancelOrder

Return a cancel order command from the given dict values.

Parameters

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

Returns

CancelOrder

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the command.

Returns

InstrumentId

strategy_id

The strategy ID associated with the command.

Returns

StrategyId

static to_dict ( CancelOrder obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the command.

Returns

TraderId

ts_init

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

Returns

uint64_t

venue_order_id

The venue order ID associated with the command.

Returns

VenueOrderId or None

class ModifyOrder ( TraderId trader_id, StrategyId strategy_id, InstrumentId instrument_id, ClientOrderId client_order_id, VenueOrderId venue_order_id: Optional[VenueOrderId], Quantity quantity: Optional[Quantity], Price price: Optional[Price], Price trigger_price: Optional[Price], UUID4 command_id, uint64_t ts_init, ClientId client_id=None )

Bases: nautilus_trader.execution.messages.TradingCommand

Represents a command to modify the properties of an existing order.

Parameters
  • trader_id ( TraderId ) – The trader ID for the command.

  • strategy_id ( StrategyId ) – The strategy ID for the command.

  • instrument_id ( InstrumentId ) – The instrument ID for the command.

  • client_order_id ( VenueOrderId ) – The client order ID to update.

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

  • quantity (Quantity, optional with no default so None must be passed explicitly) – The quantity for the order update.

  • price (Price, optional with no default so None must be passed explicitly) – The price for the order update.

  • trigger_price (Price, optional with no default so None must be passed explicitly) – The trigger price for the order update.

  • command_id ( UUID4 ) – The command ID.

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

  • client_id ( ClientId , optional ) – The execution client ID for the command.

References

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

category

The message category.

Returns

MessageCategory

client_id

The execution client ID for the command.

Returns

ClientId or None

client_order_id

The client order ID associated with the command.

Returns

ClientOrderId

static from_dict ( dict values ) ModifyOrder

Return a modify order command from the given dict values.

Parameters

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

Returns

ModifyOrder

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the command.

Returns

InstrumentId

price

The updated price for the command.

Returns

Price or None

quantity

The updated quantity for the command.

Returns

Quantity or None

strategy_id

The strategy ID associated with the command.

Returns

StrategyId

static to_dict ( ModifyOrder obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the command.

Returns

TraderId

trigger_price

The updated trigger price for the command.

Returns

Price or None

ts_init

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

Returns

uint64_t

venue_order_id

The venue order ID associated with the command.

Returns

VenueOrderId or None

class QueryOrder ( TraderId trader_id, StrategyId strategy_id, InstrumentId instrument_id, ClientOrderId client_order_id, VenueOrderId venue_order_id: Optional[VenueOrderId], UUID4 command_id, uint64_t ts_init, ClientId client_id=None )

Bases: nautilus_trader.execution.messages.TradingCommand

Represents a command to query an order.

Parameters
  • trader_id ( TraderId ) – The trader ID for the command.

  • strategy_id ( StrategyId ) – The strategy ID for the command.

  • instrument_id ( InstrumentId ) – The instrument ID for the command.

  • client_order_id ( ClientOrderId ) – The client order ID to cancel.

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

  • command_id ( UUID4 ) – The command ID.

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

  • client_id ( ClientId , optional ) – The execution client ID for the command.

category

The message category.

Returns

MessageCategory

client_id

The execution client ID for the command.

Returns

ClientId or None

client_order_id

The client order ID associated with the command.

Returns

ClientOrderId

static from_dict ( dict values ) QueryOrder

Return a query order command from the given dict values.

Parameters

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

Returns

QueryOrder

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the command.

Returns

InstrumentId

strategy_id

The strategy ID associated with the command.

Returns

StrategyId

static to_dict ( QueryOrder obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the command.

Returns

TraderId

ts_init

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

Returns

uint64_t

venue_order_id

The venue order ID associated with the command.

Returns

VenueOrderId or None

class SubmitOrder ( TraderId trader_id , StrategyId strategy_id , Order order , UUID4 command_id , uint64_t ts_init , PositionId position_id: Optional[PositionId] = None , TriggerType emulation_trigger=TriggerType.NONE , unicode execution_algorithm=None , ClientId client_id=None )

Bases: nautilus_trader.execution.messages.TradingCommand

Represents a command to submit the given order.

Parameters
  • trader_id ( TraderId ) – The trader ID for the command.

  • strategy_id ( StrategyId ) – The strategy ID for the command.

  • order ( Order ) – The order to submit.

  • command_id ( UUID4 ) – The commands ID.

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

  • position_id ( PositionId , optional ) – The position ID for the command.

  • emulation_trigger (TriggerType, default NONE ) – The trigger type for order emulation (if NONE then no emulation).

  • execution_algorithm ( str , optional ) – The name of the execution algorithm for the order.

  • client_id ( ClientId , optional ) – The execution client ID for the command.

Raises
  • ValueError – If emulation_trigger is not NONE and order.order_type == MARKET .

  • ValueError – If execution_algorithm is not None and not a valid string.

References

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

category

The message category.

Returns

MessageCategory

client_id

The execution client ID for the command.

Returns

ClientId or None

emulation_trigger

The trigger type for order emulation (if NONE then no emulation).

Returns

TriggerType

execution_algorithm

The name of the execution algorithm for the order.

Returns

str

static from_dict ( dict values ) SubmitOrder

Return a submit order command from the given dict values.

Parameters

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

Returns

SubmitOrder

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the command.

Returns

InstrumentId

order

The order for the command.

Returns

Order

position_id

The position ID associated with the command.

Returns

PositionId or None

strategy_id

The strategy ID associated with the command.

Returns

StrategyId

static to_dict ( SubmitOrder obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the command.

Returns

TraderId

ts_init

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

Returns

uint64_t

class SubmitOrderList ( TraderId trader_id , StrategyId strategy_id , OrderList order_list , UUID4 command_id , uint64_t ts_init , ClientId client_id=None )

Bases: nautilus_trader.execution.messages.TradingCommand

Represents a command to submit an order list consisting of bulk or related parent-child contingent orders.

This command can correspond to a NewOrderList <E> message for the FIX protocol.

Parameters
  • trader_id ( TraderId ) – The trader ID for the command.

  • strategy_id ( StrategyId ) – The strategy ID for the command.

  • order_list ( OrderList ) – The order list to submit.

  • command_id ( UUID4 ) – The command ID.

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

  • client_id ( ClientId , optional ) – The execution client ID for the command.

References

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

category

The message category.

Returns

MessageCategory

client_id

The execution client ID for the command.

Returns

ClientId or None

static from_dict ( dict values ) SubmitOrderList

Return a submit order list command from the given dict values.

Parameters

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

Returns

SubmitOrderList

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the command.

Returns

InstrumentId

list

The order list for submission.

Returns

OrderList

strategy_id

The strategy ID associated with the command.

Returns

StrategyId

static to_dict ( SubmitOrderList obj )

Return a dictionary representation of this object.

Returns

dict[str, object]

trader_id

The trader ID associated with the command.

Returns

TraderId

ts_init

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

Returns

uint64_t

class TradingCommand ( ClientId client_id: Optional[ClientId], TraderId trader_id, StrategyId strategy_id, InstrumentId instrument_id, UUID4 command_id, uint64_t ts_init )

Bases: nautilus_trader.core.message.Command

The abstract base class for all trading related commands.

Parameters
  • client_id (ClientId, optional with no default so None must be passed explicitly) – The execution client ID for the command.

  • trader_id ( TraderId ) – The trader ID for the command.

  • strategy_id ( StrategyId ) – The strategy ID for the command.

  • instrument_id ( InstrumentId ) – The instrument ID for the command.

  • command_id ( UUID4 ) – The commands ID.

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

category

The message category.

Returns

MessageCategory

client_id

The execution client ID for the command.

Returns

ClientId or None

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID associated with the command.

Returns

InstrumentId

strategy_id

The strategy ID associated with the command.

Returns

StrategyId

trader_id

The trader ID associated with the command.

Returns

TraderId

ts_init

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

Returns

uint64_t

Reports

class ExecutionMassStatus ( ClientId client_id , AccountId account_id , Venue venue , UUID4 report_id , uint64_t ts_init )

Bases: nautilus_trader.core.message.Document

Represents an execution mass status report for an execution client - including status of all orders, trades for those orders and open positions.

Parameters
  • venue ( Venue ) – The venue for the report.

  • client_id ( ClientId ) – The client ID for the report.

  • account_id ( AccountId ) – The account ID for the report.

  • report_id ( UUID4 ) – The report ID.

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

account_id

The account ID for the report.

Returns

AccountId

add_order_reports ( self , list reports ) void

Add the order reports to the mass status.

Parameters

reports ( list [ OrderStatusReport ] ) – The list of reports to add.

Raises

TypeError – If reports contains a type other than TradeReport .

add_position_reports ( self , list reports ) void

Add the position status reports to the mass status.

Parameters

reports ( list [ PositionStatusReport ] ) – The reports to add.

add_trade_reports ( self , list reports ) void

Add the trade reports to the mass status.

Parameters

reports ( list [ TradeReport ] ) – The list of reports to add.

Raises

TypeError – If reports contains a type other than TradeReport .

category

The message category.

Returns

MessageCategory

client_id

The client ID for the report.

Returns

ClientId

id

The message ID.

Returns

UUID4

order_reports ( self ) dict

Return the order status reports.

Returns

dict[VenueOrderId, OrderStatusReport]

position_reports ( self ) dict

Return the position status reports.

Returns

dict[InstrumentId, list[PositionStatusReport]]

trade_reports ( self ) dict

Return the trade reports.

Returns

dict[VenueOrderId, list[TradeReport]

ts_init

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

Returns

uint64_t

venue

The venue for the report.

Returns

Venue

class ExecutionReport ( AccountId account_id , InstrumentId instrument_id , UUID4 report_id , uint64_t ts_init )

Bases: nautilus_trader.core.message.Document

The abstract base class for all execution reports.

account_id

The account ID for the report.

Returns

AccountId

category

The message category.

Returns

MessageCategory

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID for the report.

Returns

InstrumentId

ts_init

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

Returns

uint64_t

class OrderStatusReport ( AccountId account_id , InstrumentId instrument_id , VenueOrderId venue_order_id , OrderSide order_side , OrderType order_type , TimeInForce time_in_force , OrderStatus order_status , Quantity quantity , Quantity filled_qty , UUID4 report_id , uint64_t ts_accepted , uint64_t ts_last , uint64_t ts_init , ClientOrderId client_order_id: Optional[ClientOrderId] = None , OrderListId order_list_id: Optional[OrderListId] = None , ContingencyType contingency_type=ContingencyType.NONE , datetime expire_time: Optional[datetime] = None , Price price: Optional[Price] = None , Price trigger_price: Optional[Price] = None , TriggerType trigger_type=TriggerType.NONE , limit_offset: Optional[Decimal] = None , trailing_offset: Optional[Decimal] = None , TrailingOffsetType trailing_offset_type=TrailingOffsetType.NONE , avg_px: Optional[Decimal] = None , Quantity display_qty: Optional[Quantity] = None , bool post_only=False , bool reduce_only=False , unicode cancel_reason: Optional[str] = None , ts_triggered: Optional[int] = None )

Bases: nautilus_trader.execution.reports.ExecutionReport

Represents an order status at a point in time.

Parameters
  • account_id ( AccountId ) – The account ID for the report.

  • instrument_id ( InstrumentId ) – The instrument ID for the report.

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

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

  • order_type ( OrderType ) – The reported order type.

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

  • order_status ( OrderStatus ) – The reported order status at the exchange.

  • quantity ( Quantity ) – The reported order original quantity.

  • filled_qty ( Quantity ) – The reported filled quantity at the exchange.

  • report_id ( UUID4 ) – The report ID.

  • ts_accepted ( uint64_t ) – The UNIX timestamp (nanoseconds) when the reported order was accepted.

  • ts_last ( uint64_t ) – The UNIX timestamp (nanoseconds) of the last order status change.

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

  • client_order_id ( ClientOrderId , optional ) – The reported client order ID.

  • order_list_id ( OrderListId , optional ) – The reported order list ID associated with the order.

  • contingency_type (ContingencyType, default NONE ) – The reported order contingency type.

  • expire_time ( datetime , optional ) – The order expiration.

  • price ( Price , optional ) – The reported order price (LIMIT).

  • trigger_price ( Price , optional ) – The reported order trigger price (STOP).

  • trigger_type (TriggerType, default NONE ) – The reported order trigger type.

  • limit_offset ( Decimal , optional ) – The trailing offset for the order price (LIMIT).

  • trailing_offset ( Decimal , optional ) – The trailing offset for the trigger price (STOP).

  • trailing_offset_type (TrailingOffsetType, default NONE ) – The order trailing offset type.

  • avg_px ( Decimal , optional ) – The reported order average fill price.

  • display_qty ( Quantity , optional ) – The reported order quantity displayed on the public book (iceberg).

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

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

  • cancel_reason ( str , optional ) – The reported reason for order cancellation.

  • ts_triggered ( uint64_t , optional ) – The UNIX timestamp (nanoseconds) when the object was initialized.

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

  • ValueError – If filled_qty is negative (< 0).

  • ValueError – If trigger_price is not None and trigger_price is equal to TriggerType.NONE .

  • ValueError – If limit_offset or trailing_offset is not None and trailing_offset_type is equal to TrailingOffsetType.NONE .

account_id

The account ID for the report.

Returns

AccountId

avg_px

The reported order average fill price.

Returns

Decimal or None

cancel_reason

The reported reason for order cancellation.

Returns

str or None

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID for the report.

Returns

ClientOrderId or None

contingency_type

The reported orders contingency type.

Returns

ContingencyType

display_qty

The reported order quantity displayed on the public book (iceberg).

Returns

Quantity or None

expire_time

The order expiration.

Returns

datetime or None

filled_qty

The reported filled quantity.

Returns

Quantity

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID for the report.

Returns

InstrumentId

leaves_qty

The reported order total leaves quantity.

Returns

Quantity

limit_offset

The trailing offset for the orders limit price.

Returns

Decimal

order_list_id

The reported order list ID.

Returns

OrderListId or None

order_side

The reported order side.

Returns

OrderSide

order_status

The reported order status at the exchange.

Returns

OrderStatus

order_type

The reported order type.

Returns

OrderType

post_only

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

Returns

bool

price

The reported order price (LIMIT).

Returns

Price or None

quantity

The reported order original quantity.

Returns

Quantity

reduce_only

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

Returns

bool

time_in_force

The reported order time in force.

Returns

TimeInForce

trailing_offset

The trailing offset for the orders trigger price (STOP).

Returns

Decimal

trailing_offset_type

The trailing offset type.

Returns

TrailingOffsetType

trigger_price

The reported order trigger price (STOP).

Returns

Price or None

trigger_type

The trigger type for the order.

Returns

TriggerType

ts_accepted

The UNIX timestamp (nanoseconds) when the reported order was accepted.

Returns

uint64_t

ts_init

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

Returns

uint64_t

ts_last

The UNIX timestamp (nanoseconds) of the last order status change.

Returns

uint64_t

ts_triggered

The UNIX timestamp (nanoseconds) when the order was triggered (0 if not triggered).

Returns

uint64_t

venue_order_id

The reported venue order ID (assigned by the venue).

Returns

VenueOrderId

class PositionStatusReport ( AccountId account_id , InstrumentId instrument_id , PositionSide position_side , Quantity quantity , UUID4 report_id , uint64_t ts_last , uint64_t ts_init , PositionId venue_position_id: Optional[PositionId] = None )

Bases: nautilus_trader.execution.reports.ExecutionReport

Represents a position status at a point in time.

Parameters
  • account_id ( AccountId ) – The account ID for the report.

  • instrument_id ( InstrumentId ) – The reported instrument ID for the position.

  • position_side (PositionSide { FLAT , LONG , SHORT }) – The reported position side at the exchange.

  • quantity ( Quantity ) – The reported position quantity at the exchange.

  • report_id ( UUID4 ) – The report ID.

  • ts_last ( uint64_t ) – The UNIX timestamp (nanoseconds) of the last position change.

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

  • venue_position_id ( PositionId , optional ) – The reported venue position ID (assigned by the venue). If the trading venue has assigned a position ID / ticket for the trade then pass that here, otherwise pass None and the execution engine OMS will handle position ID resolution.

account_id

The account ID for the report.

Returns

AccountId

category

The message category.

Returns

MessageCategory

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID for the report.

Returns

InstrumentId

net_qty

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

Returns

double

position_side

The reported position side at the exchange.

Returns

PositionSide

quantity

The reported position quantity at the exchange.

Returns

Quantity

ts_init

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

Returns

uint64_t

ts_last

The UNIX timestamp (nanoseconds) of the last position change.

Returns

uint64_t

venue_position_id

The reported venue position ID (assigned by the venue).

Returns

PositionId or None

class TradeReport ( AccountId account_id , InstrumentId instrument_id , VenueOrderId venue_order_id , TradeId trade_id , OrderSide order_side , Quantity last_qty , Price last_px , LiquiditySide liquidity_side , UUID4 report_id , uint64_t ts_event , uint64_t ts_init , ClientOrderId client_order_id: Optional[ClientOrderId] = None , PositionId venue_position_id: Optional[PositionId] = None , Money commission: Optional[Money] = None )

Bases: nautilus_trader.execution.reports.ExecutionReport

Represents a report of a single trade.

Parameters
  • account_id ( AccountId ) – The account ID for the report.

  • instrument_id ( InstrumentId ) – The reported instrument ID for the trade.

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

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

  • order_side (OrderSide { BUY , SELL }) – The reported order side for the trade.

  • last_qty ( Quantity ) – The reported quantity of the trade.

  • last_px ( Price ) – The reported price of the trade.

  • liquidity_side (LiquiditySide { NONE , MAKER , TAKER }) – The reported liquidity side for the trade.

  • report_id ( UUID4 ) – The report ID.

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

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

  • client_order_id ( ClientOrderId , optional ) – The reported client order ID for the trade.

  • venue_position_id ( PositionId , optional ) – The reported venue position ID for the trade. If the trading venue has assigned a position ID / ticket for the trade then pass that here, otherwise pass None and the execution engine OMS will handle position ID resolution.

  • commission ( Money , optional ) – The reported commission for the trade (can be None ).

Raises

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

account_id

The account ID for the report.

Returns

AccountId

category

The message category.

Returns

MessageCategory

client_order_id

The client order ID for the report.

Returns

ClientOrderId or None

commission

The reported commission.

Returns

Money

id

The message ID.

Returns

UUID4

instrument_id

The instrument ID for the report.

Returns

InstrumentId

last_px

The reported price of the last fill.

Returns

Price

last_qty

The reported quantity of the last fill.

Returns

Quantity

liquidity_side

The reported liquidity side.

Returns

LiquiditySide

order_side

The reported trades side.

Returns

OrderSide

trade_id

The reported trade match ID (assigned by the venue).

Returns

TradeId

ts_event

The UNIX timestamp (nanoseconds) when the execution event occurred.

Returns

LiquiditySide

ts_init

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

Returns

uint64_t

venue_order_id

The reported venue order ID (assigned by the venue).

Returns

VenueOrderId

venue_position_id

The reported venue position ID (assigned by the venue).

Returns

PositionId or None