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.
Components
class ExecAlgorithm
Bases: Actor
ExecAlgorithm(config: ExecAlgorithmConfig | None = None)
The base class for all execution algorithms.
This class allows traders to implement their own customized execution algorithms.
- Parameters: config (ExecAlgorithmConfig , optional) – The execution algorithm configuration.
- Raises: TypeError – If config is not of type ExecAlgorithmConfig.
WARNING
This class should not be used directly, but through a concrete subclass.
active_task_ids(self) → list
Return the active task identifiers.
- Return type: list[TaskId]
add_synthetic(self, SyntheticInstrument synthetic) → void
Add the created synthetic instrument to the cache.
- Parameters: synthetic (SyntheticInstrument) – The synthetic instrument to add to the cache.
- Raises: KeyError – If synthetic is already in the cache.
cache
The read-only cache for the actor.
- Returns: CacheFacade
cancel_all_tasks(self) → void
Cancel all queued and active tasks.
cancel_order(self, Order order, ClientId client_id=None) → void
Cancel the given order with optional routing instructions.
A CancelOrder command will be created and then sent to either the OrderEmulator or the ExecutionEngine (depending on whether the order is emulated).
Logs an error if no VenueOrderId has been assigned to the order.
- Parameters:
cancel_task(self, task_id: TaskId) → void
Cancel the task with the given task_id (if queued or active).
If the task is not found then a warning is logged.
- Parameters: task_id (TaskId) – The task identifier.
clock
The actors clock.
- Returns: Clock
config
The actors configuration.
- Returns: NautilusConfig
degrade(self) → void
Degrade the component.
While executing on_degrade() any exception will be logged and reraised, then 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_warning_event(self, type event) → void
Deregister the given event type from warning log levels.
- Parameters: event (type) – The event class to deregister.
dispose(self) → void
Dispose of the component.
While executing on_dispose() any exception will be logged and reraised, then 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.
execute(self, TradingCommand command) → void
Handle the given trading command by processing it with the execution algorithm.
- Parameters: command (SubmitOrder) – The command to handle.
- Raises: ValueError – If command.exec_algorithm_id is not equal to self.id.
fault(self) → void
Fault the component.
Calling this method multiple times has the same effect as calling it once (it is idempotent). Once called, it cannot be reversed, and no other methods should be called on this instance.
While executing on_fault() any exception will be logged and reraised, then 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(cls) → str
Return the fully qualified name for the components class.
- Return type: str
handle_bar(self, Bar bar) → void
Handle the given bar data.
If state is RUNNING
then passes to on_bar.
- Parameters: bar (Bar) – The bar received.
WARNING
System method (not intended to be called by user code).
handle_bars(self, list bars) → void
Handle the given historical bar data by handling each bar individually.
- Parameters: bars (list [Bar ]) – The bars to handle.
WARNING
System method (not intended to be called by user code).
handle_data(self, Data data) → void
Handle the given data.
If state is RUNNING
then passes to on_data.
- Parameters: data (Data) – The data received.
WARNING
System method (not intended to be called by user code).
handle_event(self, Event event) → void
Handle the given event.
If state is RUNNING
then passes to on_event.
- Parameters: event (Event) – The event received.
WARNING
System method (not intended to be called by user code).
handle_historical_data(self, data) → void
Handle the given historical data.
- Parameters: data (Data) – The historical data received.
WARNING
System method (not intended to be called by user code).
handle_instrument(self, Instrument instrument) → void
Handle the given instrument.
Passes to on_instrument if state is RUNNING
.
- Parameters: instrument (Instrument) – The instrument received.
WARNING
System method (not intended to be called by user code).
handle_instrument_close(self, InstrumentClose update) → void
Handle the given instrument close update.
If state is RUNNING
then passes to on_instrument_close.
- Parameters: update (InstrumentClose) – The update received.
WARNING
System method (not intended to be called by user code).
handle_instrument_status(self, InstrumentStatus data) → void
Handle the given instrument status update.
If state is RUNNING
then passes to on_instrument_status.
- Parameters: data (InstrumentStatus) – The status update received.
WARNING
System method (not intended to be called by user code).
handle_instruments(self, list instruments) → void
Handle the given instruments data by handling each instrument individually.
- Parameters: instruments (list [Instrument ]) – The instruments received.
WARNING
System method (not intended to be called by user code).
handle_order_book(self, OrderBook order_book) → void
Handle the given order book.
Passes to on_order_book if state is RUNNING
.
- Parameters: order_book (OrderBook) – The order book received.
WARNING
System method (not intended to be called by user code).
handle_order_book_deltas(self, deltas) → void
Handle the given order book deltas.
Passes to on_order_book_deltas if state is RUNNING
.
The deltas will be nautilus_pyo3.OrderBookDeltas if the
pyo3_conversion flag was set for the subscription.
- Parameters: deltas (OrderBookDeltas or nautilus_pyo3.OrderBookDeltas) – The order book deltas received.
WARNING
System method (not intended to be called by user code).
handle_quote_tick(self, QuoteTick tick) → void
Handle the given quote tick.
If state is RUNNING
then passes to on_quote_tick.
- Parameters: tick (QuoteTick) – The tick received.