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 ( config : Optional [ ExecAlgorithmConfig ] = None ) ¶
-
Bases:
Actor
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.
- cache ¶
-
The read-only cache for the actor.
- Returns :
-
CacheFacade
- 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 RiskEngine (depending on whether the order is emulated).
Logs an error if no VenueOrderId has been assigned to the order.
- 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. 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. 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.
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
- 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 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_update ( self , InstrumentStatusUpdate update ) void ¶
-
Handle the given instrument status update.
If state is
RUNNING
then passes to on_instrument_status_update .- Parameters :
-
update ( InstrumentStatusUpdate ) – The 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 snapshot.
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_delta ( self , Data data ) void ¶
-
Handle the given order book data.
Passes to on_order_book_delta if state is
RUNNING
.- Parameters :
-
delta ( OrderBookDelta , OrderBookDeltas , OrderBookSnapshot ) – The order book delta 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.
Warning
System method (not intended to be called by user code).
- handle_quote_ticks ( self , list ticks ) void ¶
-
Handle the given historical quote tick data by handling each tick individually.
- Parameters :
-
ticks ( list [ QuoteTick ] ) – The ticks received.
Warning
System method (not intended to be called by user code).
- handle_ticker ( self , Ticker ticker ) void ¶
-
Handle the given ticker.
If state is
RUNNING
then passes to on_ticker .- Parameters :
-
ticker ( Ticker ) – The ticker received.
Warning
System method (not intended to be called by user code).
- handle_trade_tick ( self , TradeTick tick ) void ¶
-
Handle the given trade tick.
If state is
RUNNING
then passes to on_trade_tick .- Parameters :
-
tick ( TradeTick ) – The tick received.
Warning
System method (not intended to be called by user code).
- handle_trade_ticks ( self , list ticks ) void ¶
-
Handle the given tick data by handling each tick individually.
- Parameters :
-
ticks ( list [ TradeTick ] ) – The ticks received.
Warning
System method (not intended to be called by user code).
- handle_venue_status_update ( self , VenueStatusUpdate update ) void ¶
-
Handle the given venue status update.
If state is
RUNNING
then passes to on_venue_status_update .- Parameters :
-
update ( VenueStatusUpdate ) – The update received.
Warning
System method (not intended to be called by user code).
- 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 ( self , dict state ) void ¶
-
Load the actor/strategy state from the give state dictionary.
Calls on_load and passes the state.
- Parameters :
-
state ( dict [ str , object ] ) – The state dictionary.
- Raises :
-
RuntimeError – If actor/strategy is not registered with a trader.
Warning
Exceptions raised will be caught, logged, and reraised.
- log ¶
-
The actors logger.
- Returns :
-
LoggerAdapter
- modify_order ( self , Order order , Quantity quantity=None , Price price=None , Price trigger_price=None , ClientId client_id=None ) void ¶
-
Modify the given order with optional parameters and routing instructions.
An ModifyOrder command will be created and then sent to the RiskEngine .
At least one value must differ from the original order for the command to be valid.
Will use an Order Cancel/Replace Request (a.k.a Order Modification) for FIX protocols, otherwise if order update is not available for the API, then will cancel and replace with a new order using the original ClientOrderId .
- Parameters :
-
-
order ( Order ) – The order to update.
-
quantity ( Quantity , optional ) – The updated quantity for the given order.
-
price ( Price , optional ) – The updated price for the given order (if applicable).
-
trigger_price ( Price , optional ) – The updated trigger price for the given order (if applicable).
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- Raises :
-
-
ValueError – If price is not
None
and order does not have a price . -
ValueError – If trigger is not
None
and order does not have a trigger_price .
-
Warning
If the order is already closed or at PENDING_CANCEL status then the command will not be generated, and a warning will be logged.
References
https://www.onixs.biz/fix-dictionary/5.0.SP2/msgType_G_71.html
- modify_order_in_place ( self , Order order , Quantity quantity=None , Price price=None , Price trigger_price=None ) void ¶
-
Modify the given
INITIALIZED
order in place (immediately) with optional parameters.At least one value must differ from the original order for the command to be valid.
- Parameters :
- Raises :
-
-
ValueError – If order.status is not
INITIALIZED
. -
ValueError – If price is not
None
and order does not have a price . -
ValueError – If trigger is not
None
and order does not have a trigger_price .
-
Warning
If the order is already closed or at PENDING_CANCEL status then the command will not be generated, and a warning will be logged.
References
https://www.onixs.biz/fix-dictionary/5.0.SP2/msgType_G_71.html
- msgbus ¶
-
The message bus for the actor (if registered).
- Returns :
-
MessageBus or
None
- on_bar ( self , Bar bar ) void ¶
-
Actions to be performed when running and receives a bar.
- Parameters :
-
bar ( Bar ) – The bar received.
Warning
System method (not intended to be called by user code).
- on_data ( self , Data data ) void ¶
-
Actions to be performed when running and receives generic data.
- Parameters :
-
data ( Data ) – The data received.
Warning
System method (not intended to be called by user code).
- on_degrade ( self ) void ¶
-
Actions to be performed on degrade.
Warning
System method (not intended to be called by user code).
Should be overridden in the actor implementation.
- on_dispose ( self ) void ¶
-
Actions to be performed on dispose.
Cleanup/release any resources used here.
Warning
System method (not intended to be called by user code).
- on_event ( self , Event event ) void ¶
-
Actions to be performed running and receives an event.
- Parameters :
-
event ( Event ) – The event received.
Warning
System method (not intended to be called by user code).
- on_fault ( self ) void ¶
-
Actions to be performed on fault.
Cleanup any resources used by the actor here.
Warning
System method (not intended to be called by user code).
Should be overridden in the actor implementation.
- on_historical_data ( self , Data data ) void ¶
-
Actions to be performed when running and receives historical data.
- Parameters :
-
data ( Data ) – The historical data received.
Warning
System method (not intended to be called by user code).
- on_instrument ( self , Instrument instrument ) void ¶
-
Actions to be performed when running and receives an instrument.
- Parameters :
-
instrument ( Instrument ) – The instrument received.
Warning
System method (not intended to be called by user code).
- on_instrument_close ( self , InstrumentClose update ) void ¶
-
Actions to be performed when running and receives an instrument close update.
- Parameters :
-
update ( InstrumentClose ) – The update received.
Warning
System method (not intended to be called by user code).
- on_instrument_status_update ( self , InstrumentStatusUpdate update ) void ¶
-
Actions to be performed when running and receives an instrument status update.
- Parameters :
-
update ( InstrumentStatusUpdate ) – The update received.
Warning
System method (not intended to be called by user code).
- on_load ( self , dict state ) void ¶
-
Actions to be performed when the actor state is loaded.
Saved state values will be contained in the give state dictionary.
Warning
System method (not intended to be called by user code).
- on_order ( self , Order order ) void ¶
-
Actions to be performed when running and receives an order.
- Parameters :
-
order ( Order ) – The order to be handled.
Warning
System method (not intended to be called by user code).
- on_order_book ( self , OrderBook order_book ) void ¶
-
Actions to be performed when running and receives an order book snapshot.
- Parameters :
-
order_book ( OrderBook ) – The order book received.
Warning
System method (not intended to be called by user code).
- on_order_book_delta ( self , Data data ) void ¶
-
Actions to be performed when running and receives order book data.
- Parameters :
-
delta ( OrderBookDelta , OrderBookDeltas , OrderBookSnapshot ) – The order book data received.
Warning
System method (not intended to be called by user code).
- on_order_event ( self , OrderEvent event ) void ¶
-
Actions to be performed when running and receives an order event.
- Parameters :
-
event ( OrderEvent ) – The order event to be handled.
Warning
System method (not intended to be called by user code).
- on_order_list ( self , OrderList order_list ) void ¶
-
Actions to be performed when running and receives an order list.
- Parameters :
-
order_list ( OrderList ) – The order list to be handled.
Warning
System method (not intended to be called by user code).
- on_quote_tick ( self , QuoteTick tick ) void ¶
-
Actions to be performed when running and receives a quote tick.
- Parameters :
-
tick ( QuoteTick ) – The tick received.
Warning
System method (not intended to be called by user code).
- on_reset ( self ) void ¶
-
Actions to be performed on reset.
Warning
System method (not intended to be called by user code).
Should be overridden in a user implementation.
- on_resume ( self ) void ¶
-
Actions to be performed on resume.
Warning
System method (not intended to be called by user code).
- on_save ( self ) dict ¶
-
Actions to be performed when the actor state is saved.
Create and return a state dictionary of values to be saved.
- Returns :
-
dict[str, bytes] – The strategy state dictionary.
Warning
System method (not intended to be called by user code).
- on_start ( self ) void ¶
-
Actions to be performed on start.
The intent is that this method is called once per trading ‘run’, when initially starting.
It is recommended to subscribe/request for data here.
Warning
System method (not intended to be called by user code).
Should be overridden in a user implementation.
- on_stop ( self ) void ¶
-
Actions to be performed on stop.
The intent is that this method is called to pause, or when done for day.
Warning
System method (not intended to be called by user code).
Should be overridden in a user implementation.
- on_ticker ( self , Ticker ticker ) void ¶
-
Actions to be performed when running and receives a ticker.
- Parameters :
-
ticker ( Ticker ) – The ticker received.
Warning
System method (not intended to be called by user code).
- on_trade_tick ( self , TradeTick tick ) void ¶
-
Actions to be performed when running and receives a trade tick.
- Parameters :
-
tick ( TradeTick ) – The tick received.
Warning
System method (not intended to be called by user code).
- on_venue_status_update ( self , VenueStatusUpdate update ) void ¶
-
Actions to be performed when running and receives a venue status update.
- Parameters :
-
update ( VenueStatusUpdate ) – The update received.
Warning
System method (not intended to be called by user code).
- portfolio ¶
-
The read-only portfolio for the strategy.
- Returns :
-
PortfolioFacade
- publish_data ( self , DataType data_type , Data data ) void ¶
-
Publish the given data to the message bus.
- Parameters :
-
-
data_type ( DataType ) – The data type being published.
-
data ( Data ) – The data to publish.
-
- publish_signal ( self , unicode name , value , uint64_t ts_event=0 ) void ¶
-
Publish the given value as a signal to the message bus. Optionally setup persistence for this signal .
- Parameters :
-
-
name ( str ) – The name of the signal being published.
-
value ( object ) – The signal data to publish.
-
ts_event ( uint64_t , optional ) – The UNIX timestamp (nanoseconds) when the signal event occurred. If
None
then will timestamp current time.
-
- register ( self , TraderId trader_id , PortfolioFacade portfolio , MessageBus msgbus , CacheFacade cache , Clock clock , Logger logger ) void ¶
-
Register the execution algorithm with a trader.
- Parameters :
-
-
trader_id ( TraderId ) – The trader ID for the execution algorithm.
-
portfolio ( PortfolioFacade ) – The read-only portfolio for the execution algorithm.
-
msgbus ( MessageBus ) – The message bus for the execution algorithm.
-
cache ( CacheFacade ) – The read-only cache for the execution algorithm.
-
clock ( Clock ) – The clock for the execution algorithm.
-
logger ( Logger ) – The logger for the execution algorithm.
-
Warning
System method (not intended to be called by user code).
- register_base ( self , MessageBus msgbus , CacheFacade cache , Clock clock , Logger logger ) void ¶
-
Register with a trader.
- Parameters :
-
-
msgbus ( MessageBus ) – The message bus for the actor.
-
cache ( CacheFacade ) – The read-only cache for the actor.
-
clock ( Clock ) – The clock for the actor.
-
logger ( Logger ) – The logger for the actor.
-
Warning
System method (not intended to be called by user code).
- register_warning_event ( self , type event ) void ¶
-
Register the given event type for warning log levels.
- Parameters :
-
event ( type ) – The event class to register.
- request_bars ( self , BarType bar_type , datetime start=None , datetime end=None , ClientId client_id=None , UUID4 request_id=None ) void ¶
-
Request historical Bar data.
If end is
None
then will request up to the most recent data.- Parameters :
-
-
bar_type ( BarType ) – The bar type for the request.
-
start ( datetime , optional ) – The start datetime (UTC) of request time range (inclusive).
-
end ( datetime , optional ) – The end datetime (UTC) of request time range (inclusive). If
None
then will default to the current datetime (UTC). -
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID. -
request_id ( UUID4 , optional ) – The specific request ID for the command. If
None
then will be generated.
-
- Raises :
-
ValueError – If start is not less than end .
- request_data ( self , ClientId client_id , DataType data_type , UUID4 request_id=None ) void ¶
-
Request custom data for the given data type from the given data client.
- request_instrument ( self , InstrumentId instrument_id , ClientId client_id=None , UUID4 request_id=None ) void ¶
-
Request Instrument data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The instrument ID for the request.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID. -
request_id ( UUID4 , optional ) – The specific request ID for the command. If
None
then will be generated.
-
- request_instruments ( self , Venue venue , ClientId client_id=None , UUID4 request_id=None ) void ¶
-
Request all Instrument data for the given venue.
- Parameters :
- request_quote_ticks ( self , InstrumentId instrument_id , datetime start=None , datetime end=None , ClientId client_id=None , UUID4 request_id=None ) void ¶
-
Request historical QuoteTick data.
If end is
None
then will request up to the most recent data.- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument ID for the request.
-
start ( datetime , optional ) – The start datetime (UTC) of request time range (inclusive).
-
end ( datetime , optional ) – The end datetime (UTC) of request time range (inclusive). If
None
then will default to the current datetime (UTC). -
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID. -
request_id ( UUID4 , optional ) – The specific request ID for the command. If
None
then will be generated.
-
- Raises :
-
ValueError – If start is not less than end .
- request_trade_ticks ( self , InstrumentId instrument_id , datetime start=None , datetime end=None , ClientId client_id=None , UUID4 request_id=None ) void ¶
-
Request historical TradeTick data.
If end is
None
then will request up to the most recent data.- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument ID for the request.
-
start ( datetime , optional ) – The start datetime (UTC) of request time range (inclusive).
-
end ( datetime , optional ) – The end datetime (UTC) of request time range (inclusive). If
None
then will default to the current datetime (UTC). -
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID. -
request_id ( UUID4 , optional ) – The specific request ID for the command. If
None
then will be generated.
-
- Raises :
-
ValueError – If start is not less than end .
- 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.
- save ( self ) dict ¶
-
Return the actor/strategy state dictionary to be saved.
Calls on_save .
- Raises :
-
RuntimeError – If actor/strategy is not registered with a trader.
Warning
Exceptions raised will be caught, logged, and reraised.
- spawn_limit ( self , Order primary , Quantity quantity , Price price , TimeInForce time_in_force=TimeInForce.GTC , datetime expire_time=None , bool post_only=False , bool reduce_only=False , Quantity display_qty=None , TriggerType emulation_trigger=TriggerType.NO_TRIGGER , unicode tags=None , bool reduce_primary=True ) LimitOrder ¶
-
Spawn a new
LIMIT
order from the given primary order.- Parameters :
-
-
primary ( Order ) – The primary order from which this order will spawn.
-
quantity ( Quantity ) – The spawned orders quantity (> 0). Must be less than primary.quantity .
-
price ( Price ) – The spawned orders price.
-
time_in_force (TimeInForce {
GTC
,IOC
,FOK
,GTD
,DAY
,AT_THE_OPEN
,AT_THE_CLOSE
}, defaultGTC
) – The spawned orders time in force. -
expire_time ( datetime , optional ) – The spawned order expiration (for
GTD
orders). -
post_only ( bool , default False ) – If the spawned order will only provide liquidity (make a market).
-
reduce_only ( bool , default False ) – If the spawned order carries the ‘reduce-only’ execution instruction.
-
display_qty ( Quantity , optional ) – The quantity of the spawned order to display on the public book (iceberg).
-
emulation_trigger (TriggerType, default
NO_TRIGGER
) – The spawned orders emulation trigger. -
tags ( str , optional ) – The custom user tags for the order. These are optional and can contain any arbitrary delimiter if required.
-
reduce_primary ( bool , default True ) – If the primary order quantity should be reduced by the given quantity .
-
- Returns :
-
LimitOrder
- Raises :
-
-
ValueError – If primary.exec_algorithm_id is not equal to self.id .
-
ValueError – If quantity is not positive (> 0).
-
ValueError – If time_in_force is
GTD
and expire_time <= UNIX epoch. -
ValueError – If display_qty is negative (< 0) or greater than quantity .
-
- spawn_market ( self , Order primary , Quantity quantity , TimeInForce time_in_force=TimeInForce.GTC , bool reduce_only=False , unicode tags=None , bool reduce_primary=True ) MarketOrder ¶
-
Spawn a new
MARKET
order from the given primary order.- Parameters :
-
-
primary ( Order ) – The primary order from which this order will spawn.
-
quantity ( Quantity ) – The spawned orders quantity (> 0).
-
time_in_force (TimeInForce {
GTC
,IOC
,FOK
,DAY
,AT_THE_OPEN
,AT_THE_CLOSE
}, defaultGTC
) – The spawned orders time in force. Often not applicable for market orders. -
reduce_only ( bool , default False ) – If the spawned order carries the ‘reduce-only’ execution instruction.
-
tags ( str , optional ) – The custom user tags for the order. These are optional and can contain any arbitrary delimiter if required.
-
reduce_primary ( bool , default True ) – If the primary order quantity should be reduced by the given quantity .
-
- Returns :
-
MarketOrder
- Raises :
-
-
ValueError – If primary.exec_algorithm_id is not equal to self.id .
-
ValueError – If quantity is not positive (> 0).
-
ValueError – If time_in_force is
GTD
.
-
- spawn_market_to_limit ( self , Order primary , Quantity quantity , TimeInForce time_in_force=TimeInForce.GTC , datetime expire_time=None , bool reduce_only=False , Quantity display_qty=None , TriggerType emulation_trigger=TriggerType.NO_TRIGGER , unicode tags=None , bool reduce_primary=True ) MarketToLimitOrder ¶
-
Spawn a new
MARKET_TO_LIMIT
order from the given primary order.- Parameters :
-
-
primary ( Order ) – The primary order from which this order will spawn.
-
quantity ( Quantity ) – The spawned orders quantity (> 0). Must be less than primary.quantity .
-
time_in_force (TimeInForce {
GTC
,IOC
,FOK
,GTD
,DAY
,AT_THE_OPEN
,AT_THE_CLOSE
}, defaultGTC
) – The spawned orders time in force. -
expire_time ( datetime , optional ) – The spawned order expiration (for
GTD
orders). -
reduce_only ( bool , default False ) – If the spawned order carries the ‘reduce-only’ execution instruction.
-
display_qty ( Quantity , optional ) – The quantity of the spawned order to display on the public book (iceberg).
-
emulation_trigger (TriggerType, default
NO_TRIGGER
) – The spawned orders emulation trigger. -
tags ( str , optional ) – The custom user tags for the order. These are optional and can contain any arbitrary delimiter if required.
-
reduce_primary ( bool , default True ) – If the primary order quantity should be reduced by the given quantity .
-
- Returns :
-
MarketToLimitOrder
- Raises :
-
-
ValueError – If primary.exec_algorithm_id is not equal to self.id .
-
ValueError – If quantity is not positive (> 0).
-
ValueError – If time_in_force is
GTD
and expire_time <= UNIX epoch. -
ValueError – If display_qty is negative (< 0) or greater than quantity .
-
- 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 , Order order ) void ¶
-
Submit the given order (may be the primary or spawned order).
A SubmitOrder command will be created and sent to the RiskEngine .
If the client order ID is duplicate, then the order will be denied.
- Parameters :
-
-
order ( Order ) – The order to submit.
-
parent_order_id ( ClientOrderId , optional ) – The parent client order identifier. If provided then will be considered a child order of the parent.
-
- Raises :
-
-
ValueError – If order.status is not
INITIALIZED
. -
ValueError – If order.emulation_trigger is not
None
.
-
Warning
If a position_id is passed and a position does not yet exist, then any position opened by the order will have this position ID assigned. This may not be what you intended.
Emulated orders cannot be sent from execution algorithms (intentioally constraining complexity).
- subscribe_bars ( self , BarType bar_type , ClientId client_id=None ) void ¶
-
Subscribe to streaming Bar data for the given bar type.
- subscribe_data ( self , DataType data_type , ClientId client_id=None ) void ¶
-
Subscribe to data of the given data type.
- subscribe_instrument ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Subscribe to update Instrument data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The instrument ID for the subscription.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- subscribe_instrument_close ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Subscribe to close updates for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The instrument to subscribe to status updates for.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- subscribe_instrument_status_updates ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Subscribe to status updates for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The instrument to subscribe to status updates for.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- subscribe_instruments ( self , Venue venue , ClientId client_id=None ) void ¶
-
Subscribe to update Instrument data for the given venue.
- subscribe_order_book_deltas ( self , InstrumentId instrument_id , BookType book_type=BookType.L2_MBP , int depth=0 , dict kwargs=None , ClientId client_id=None ) void ¶
-
Subscribe to the order book data stream, being a snapshot then deltas for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The order book instrument ID to subscribe to.
-
book_type (BookType {
L1_TBBO
,L2_MBP
,L3_MBO
}) – The order book type. -
depth ( int , optional ) – The maximum depth for the order book. A depth of 0 is maximum depth.
-
kwargs ( dict , optional ) – The keyword arguments for exchange specific parameters.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- subscribe_order_book_snapshots ( self , InstrumentId instrument_id , BookType book_type=BookType.L2_MBP , int depth=0 , int interval_ms=1000 , dict kwargs=None , ClientId client_id=None ) void ¶
-
Subscribe to OrderBook snapshots for the given instrument ID.
The DataEngine will only maintain one order book for each instrument. Because of this - the level, depth and kwargs for the stream will be set as per the last subscription request (this will also affect all subscribers).
- Parameters :
-
-
instrument_id ( InstrumentId ) – The order book instrument ID to subscribe to.
-
book_type (BookType {
L1_TBBO
,L2_MBP
,L3_MBO
}) – The order book type. -
depth ( int , optional ) – The maximum depth for the order book. A depth of 0 is maximum depth.
-
interval_ms ( int ) – The order book snapshot interval in milliseconds.
-
kwargs ( dict , optional ) – The keyword arguments for exchange specific parameters.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- Raises :
-
-
ValueError – If depth is negative (< 0).
-
ValueError – If interval_ms is not positive (> 0).
-
- subscribe_quote_ticks ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Subscribe to streaming QuoteTick data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument to subscribe to.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- subscribe_ticker ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Subscribe to streaming Ticker data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument to subscribe to.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- subscribe_trade_ticks ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Subscribe to streaming TradeTick data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument to subscribe to.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- subscribe_venue_status_updates ( self , Venue venue , ClientId client_id=None ) void ¶
-
Subscribe to status updates for the given venue.
- to_importable_config ( self ) ImportableExecAlgorithmConfig ¶
-
Returns an importable configuration for this execution algorithm.
- Returns :
-
ImportableExecAlgorithmConfig
- trader_id ¶
-
The trader ID associated with the component.
- Returns :
-
TraderId
- type ¶
-
The components type.
- Returns :
-
type
- unsubscribe_bars ( self , BarType bar_type , ClientId client_id=None ) void ¶
-
Unsubscribe from streaming Bar data for the given bar type.
- unsubscribe_data ( self , DataType data_type , ClientId client_id=None ) void ¶
-
Unsubscribe from data of the given data type.
- unsubscribe_instrument ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Unsubscribe from update Instrument data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The instrument to unsubscribe from.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- unsubscribe_instrument_status_updates ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Unsubscribe to status updates of the given venue.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The instrument to unsubscribe to status updates for.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue.
-
- unsubscribe_instruments ( self , Venue venue , ClientId client_id=None ) void ¶
-
Unsubscribe from update Instrument data for the given venue.
- unsubscribe_order_book_deltas ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Unsubscribe the order book deltas stream for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The order book instrument to subscribe to.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- unsubscribe_order_book_snapshots ( self , InstrumentId instrument_id , int interval_ms=1000 , ClientId client_id=None ) void ¶
-
Unsubscribe from order book snapshots for the given instrument ID.
The interval must match the previously subscribed interval.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The order book instrument to subscribe to.
-
interval_ms ( int ) – The order book snapshot interval in milliseconds.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- unsubscribe_quote_ticks ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Unsubscribe from streaming QuoteTick data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument to unsubscribe from.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- unsubscribe_ticker ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Unsubscribe from streaming Ticker data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument to unsubscribe from.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- unsubscribe_trade_ticks ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Unsubscribe from streaming TradeTick data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument ID to unsubscribe from.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- unsubscribe_venue_status_updates ( self , Venue venue , ClientId client_id=None ) void ¶
-
Unsubscribe to status updates for the given venue.
- 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:
Component
The 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 beNone
. -
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. UseNone
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
UNSPECIFIED
(must be specified).
-
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
- 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 passNone
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 {
NO_LIQUIDITY_SIDE
,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_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
- query_order ( self , QueryOrder command ) void ¶
-
Initiate a reconciliation for the queried order which will generate an OrderStatusReport .
- Parameters :
-
command ( QueryOrder ) – The command to execute.
- 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.
- 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
- class OrderEmulator ( TraderId trader_id , MessageBus msgbus , Cache cache , Clock clock , Logger logger , config: Optional[OrderEmulatorConfig] = None ) ¶
-
Bases:
Actor
Provides order emulation for specified trigger types.
- cache ¶
-
The read-only cache for the actor.
- Returns :
-
CacheFacade
- clock ¶
-
The actors clock.
- Returns :
-
Clock
- config ¶
-
The actors configuration.
- Returns :
-
NautilusConfig
- create_matching_core ( self , Instrument instrument ) MatchingCore ¶
-
Create an internal matching core for the given instrument .
- Parameters :
-
instrument ( Instrument ) – The instrument for the matching core.
- Returns :
-
MatchingCore
- Raises :
-
RuntimeError – If a matching core for the given instrument already exists.
- 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_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. 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 ¶
-
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.
- classmethod fully_qualified_name ( type cls ) str ¶
-
Return the fully qualified name for the components class.
- Returns :
-
str
References
- get_matching_core ( self , InstrumentId instrument_id ) Optional [ MatchingCore ] ¶
-
Return the emulators matching core for the given instrument ID.
- Returns :
-
MatchingCore or
None
- get_submit_order_commands ( self ) dict [ ClientOrderId , SubmitOrder ] ¶
-
Return the emulators cached submit order commands.
- Returns :
-
dict[ClientOrderId, SubmitOrder]
- get_submit_order_list_commands ( self ) dict [ OrderListId , SubmitOrderList ] ¶
-
Return the emulators cached submit order list commands.
- Returns :
-
dict[OrderListId, SubmitOrderList]
- 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 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_update ( self , InstrumentStatusUpdate update ) void ¶
-
Handle the given instrument status update.
If state is
RUNNING
then passes to on_instrument_status_update .- Parameters :
-
update ( InstrumentStatusUpdate ) – The 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 snapshot.
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_delta ( self , Data data ) void ¶
-
Handle the given order book data.
Passes to on_order_book_delta if state is
RUNNING
.- Parameters :
-
delta ( OrderBookDelta , OrderBookDeltas , OrderBookSnapshot ) – The order book delta 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.
Warning
System method (not intended to be called by user code).
- handle_quote_ticks ( self , list ticks ) void ¶
-
Handle the given historical quote tick data by handling each tick individually.
- Parameters :
-
ticks ( list [ QuoteTick ] ) – The ticks received.
Warning
System method (not intended to be called by user code).
- handle_ticker ( self , Ticker ticker ) void ¶
-
Handle the given ticker.
If state is
RUNNING
then passes to on_ticker .- Parameters :
-
ticker ( Ticker ) – The ticker received.
Warning
System method (not intended to be called by user code).
- handle_trade_tick ( self , TradeTick tick ) void ¶
-
Handle the given trade tick.
If state is
RUNNING
then passes to on_trade_tick .- Parameters :
-
tick ( TradeTick ) – The tick received.
Warning
System method (not intended to be called by user code).
- handle_trade_ticks ( self , list ticks ) void ¶
-
Handle the given tick data by handling each tick individually.
- Parameters :
-
ticks ( list [ TradeTick ] ) – The ticks received.
Warning
System method (not intended to be called by user code).
- handle_venue_status_update ( self , VenueStatusUpdate update ) void ¶
-
Handle the given venue status update.
If state is
RUNNING
then passes to on_venue_status_update .- Parameters :
-
update ( VenueStatusUpdate ) – The update received.
Warning
System method (not intended to be called by user code).
- 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 ( self , dict state ) void ¶
-
Load the actor/strategy state from the give state dictionary.
Calls on_load and passes the state.
- Parameters :
-
state ( dict [ str , object ] ) – The state dictionary.
- Raises :
-
RuntimeError – If actor/strategy is not registered with a trader.
Warning
Exceptions raised will be caught, logged, and reraised.
- log ¶
-
The actors logger.
- Returns :
-
LoggerAdapter
- msgbus ¶
-
The message bus for the actor (if registered).
- Returns :
-
MessageBus or
None
- on_bar ( self , Bar bar ) void ¶
-
Actions to be performed when running and receives a bar.
- Parameters :
-
bar ( Bar ) – The bar received.
Warning
System method (not intended to be called by user code).
- on_data ( self , Data data ) void ¶
-
Actions to be performed when running and receives generic data.
- Parameters :
-
data ( Data ) – The data received.
Warning
System method (not intended to be called by user code).
- on_degrade ( self ) void ¶
-
Actions to be performed on degrade.
Warning
System method (not intended to be called by user code).
Should be overridden in the actor implementation.
- on_dispose ( self ) void ¶
- on_event ( self , Event event ) void ¶
- on_fault ( self ) void ¶
-
Actions to be performed on fault.
Cleanup any resources used by the actor here.
Warning
System method (not intended to be called by user code).
Should be overridden in the actor implementation.
- on_historical_data ( self , Data data ) void ¶
-
Actions to be performed when running and receives historical data.
- Parameters :
-
data ( Data ) – The historical data received.
Warning
System method (not intended to be called by user code).
- on_instrument ( self , Instrument instrument ) void ¶
-
Actions to be performed when running and receives an instrument.
- Parameters :
-
instrument ( Instrument ) – The instrument received.
Warning
System method (not intended to be called by user code).
- on_instrument_close ( self , InstrumentClose update ) void ¶
-
Actions to be performed when running and receives an instrument close update.
- Parameters :
-
update ( InstrumentClose ) – The update received.
Warning
System method (not intended to be called by user code).
- on_instrument_status_update ( self , InstrumentStatusUpdate update ) void ¶
-
Actions to be performed when running and receives an instrument status update.
- Parameters :
-
update ( InstrumentStatusUpdate ) – The update received.
Warning
System method (not intended to be called by user code).
- on_load ( self , dict state ) void ¶
-
Actions to be performed when the actor state is loaded.
Saved state values will be contained in the give state dictionary.
Warning
System method (not intended to be called by user code).
- on_order_book ( self , OrderBook order_book ) void ¶
-
Actions to be performed when running and receives an order book snapshot.
- Parameters :
-
order_book ( OrderBook ) – The order book received.
Warning
System method (not intended to be called by user code).
- on_order_book_delta ( self , Data data ) void ¶
-
Actions to be performed when running and receives order book data.
- Parameters :
-
delta ( OrderBookDelta , OrderBookDeltas , OrderBookSnapshot ) – The order book data received.
Warning
System method (not intended to be called by user code).
- on_quote_tick ( self , QuoteTick tick ) void ¶
- on_reset ( self ) void ¶
- on_resume ( self ) void ¶
-
Actions to be performed on resume.
Warning
System method (not intended to be called by user code).
- on_save ( self ) dict ¶
-
Actions to be performed when the actor state is saved.
Create and return a state dictionary of values to be saved.
- Returns :
-
dict[str, bytes] – The strategy state dictionary.
Warning
System method (not intended to be called by user code).
- on_start ( self ) void ¶
- on_stop ( self ) void ¶
- on_ticker ( self , Ticker ticker ) void ¶
-
Actions to be performed when running and receives a ticker.
- Parameters :
-
ticker ( Ticker ) – The ticker received.
Warning
System method (not intended to be called by user code).
- on_trade_tick ( self , TradeTick tick ) void ¶
- on_venue_status_update ( self , VenueStatusUpdate update ) void ¶
-
Actions to be performed when running and receives a venue status update.
- Parameters :
-
update ( VenueStatusUpdate ) – The update received.
Warning
System method (not intended to be called by user code).
- publish_data ( self , DataType data_type , Data data ) void ¶
-
Publish the given data to the message bus.
- Parameters :
-
-
data_type ( DataType ) – The data type being published.
-
data ( Data ) – The data to publish.
-
- publish_signal ( self , unicode name , value , uint64_t ts_event=0 ) void ¶
-
Publish the given value as a signal to the message bus. Optionally setup persistence for this signal .
- Parameters :
-
-
name ( str ) – The name of the signal being published.
-
value ( object ) – The signal data to publish.
-
ts_event ( uint64_t , optional ) – The UNIX timestamp (nanoseconds) when the signal event occurred. If
None
then will timestamp current time.
-
- register_base ( self , MessageBus msgbus , CacheFacade cache , Clock clock , Logger logger ) void ¶
-
Register with a trader.
- Parameters :
-
-
msgbus ( MessageBus ) – The message bus for the actor.
-
cache ( CacheFacade ) – The read-only cache for the actor.
-
clock ( Clock ) – The clock for the actor.
-
logger ( Logger ) – The logger for the actor.
-
Warning
System method (not intended to be called by user code).
- register_warning_event ( self , type event ) void ¶
-
Register the given event type for warning log levels.
- Parameters :
-
event ( type ) – The event class to register.
- request_bars ( self , BarType bar_type , datetime start=None , datetime end=None , ClientId client_id=None , UUID4 request_id=None ) void ¶
-
Request historical Bar data.
If end is
None
then will request up to the most recent data.- Parameters :
-
-
bar_type ( BarType ) – The bar type for the request.
-
start ( datetime , optional ) – The start datetime (UTC) of request time range (inclusive).
-
end ( datetime , optional ) – The end datetime (UTC) of request time range (inclusive). If
None
then will default to the current datetime (UTC). -
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID. -
request_id ( UUID4 , optional ) – The specific request ID for the command. If
None
then will be generated.
-
- Raises :
-
ValueError – If start is not less than end .
- request_data ( self , ClientId client_id , DataType data_type , UUID4 request_id=None ) void ¶
-
Request custom data for the given data type from the given data client.
- request_instrument ( self , InstrumentId instrument_id , ClientId client_id=None , UUID4 request_id=None ) void ¶
-
Request Instrument data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The instrument ID for the request.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID. -
request_id ( UUID4 , optional ) – The specific request ID for the command. If
None
then will be generated.
-
- request_instruments ( self , Venue venue , ClientId client_id=None , UUID4 request_id=None ) void ¶
-
Request all Instrument data for the given venue.
- Parameters :
- request_quote_ticks ( self , InstrumentId instrument_id , datetime start=None , datetime end=None , ClientId client_id=None , UUID4 request_id=None ) void ¶
-
Request historical QuoteTick data.
If end is
None
then will request up to the most recent data.- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument ID for the request.
-
start ( datetime , optional ) – The start datetime (UTC) of request time range (inclusive).
-
end ( datetime , optional ) – The end datetime (UTC) of request time range (inclusive). If
None
then will default to the current datetime (UTC). -
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID. -
request_id ( UUID4 , optional ) – The specific request ID for the command. If
None
then will be generated.
-
- Raises :
-
ValueError – If start is not less than end .
- request_trade_ticks ( self , InstrumentId instrument_id , datetime start=None , datetime end=None , ClientId client_id=None , UUID4 request_id=None ) void ¶
-
Request historical TradeTick data.
If end is
None
then will request up to the most recent data.- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument ID for the request.
-
start ( datetime , optional ) – The start datetime (UTC) of request time range (inclusive).
-
end ( datetime , optional ) – The end datetime (UTC) of request time range (inclusive). If
None
then will default to the current datetime (UTC). -
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID. -
request_id ( UUID4 , optional ) – The specific request ID for the command. If
None
then will be generated.
-
- Raises :
-
ValueError – If start is not less than end .
- 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.
- save ( self ) dict ¶
-
Return the actor/strategy state dictionary to be saved.
Calls on_save .
- Raises :
-
RuntimeError – If actor/strategy is not registered with a trader.
Warning
Exceptions raised will be caught, logged, and reraised.
- 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.
- subscribe_bars ( self , BarType bar_type , ClientId client_id=None ) void ¶
-
Subscribe to streaming Bar data for the given bar type.
- subscribe_data ( self , DataType data_type , ClientId client_id=None ) void ¶
-
Subscribe to data of the given data type.
- subscribe_instrument ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Subscribe to update Instrument data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The instrument ID for the subscription.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- subscribe_instrument_close ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Subscribe to close updates for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The instrument to subscribe to status updates for.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- subscribe_instrument_status_updates ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Subscribe to status updates for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The instrument to subscribe to status updates for.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- subscribe_instruments ( self , Venue venue , ClientId client_id=None ) void ¶
-
Subscribe to update Instrument data for the given venue.
- subscribe_order_book_deltas ( self , InstrumentId instrument_id , BookType book_type=BookType.L2_MBP , int depth=0 , dict kwargs=None , ClientId client_id=None ) void ¶
-
Subscribe to the order book data stream, being a snapshot then deltas for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The order book instrument ID to subscribe to.
-
book_type (BookType {
L1_TBBO
,L2_MBP
,L3_MBO
}) – The order book type. -
depth ( int , optional ) – The maximum depth for the order book. A depth of 0 is maximum depth.
-
kwargs ( dict , optional ) – The keyword arguments for exchange specific parameters.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- subscribe_order_book_snapshots ( self , InstrumentId instrument_id , BookType book_type=BookType.L2_MBP , int depth=0 , int interval_ms=1000 , dict kwargs=None , ClientId client_id=None ) void ¶
-
Subscribe to OrderBook snapshots for the given instrument ID.
The DataEngine will only maintain one order book for each instrument. Because of this - the level, depth and kwargs for the stream will be set as per the last subscription request (this will also affect all subscribers).
- Parameters :
-
-
instrument_id ( InstrumentId ) – The order book instrument ID to subscribe to.
-
book_type (BookType {
L1_TBBO
,L2_MBP
,L3_MBO
}) – The order book type. -
depth ( int , optional ) – The maximum depth for the order book. A depth of 0 is maximum depth.
-
interval_ms ( int ) – The order book snapshot interval in milliseconds.
-
kwargs ( dict , optional ) – The keyword arguments for exchange specific parameters.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- Raises :
-
-
ValueError – If depth is negative (< 0).
-
ValueError – If interval_ms is not positive (> 0).
-
- subscribe_quote_ticks ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Subscribe to streaming QuoteTick data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument to subscribe to.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- subscribe_ticker ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Subscribe to streaming Ticker data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument to subscribe to.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- subscribe_trade_ticks ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Subscribe to streaming TradeTick data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument to subscribe to.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- subscribe_venue_status_updates ( self , Venue venue , ClientId client_id=None ) void ¶
-
Subscribe to status updates for the given venue.
- subscribed_quotes ¶
-
Return the subscribed quote feeds for the emulator.
- Returns :
-
list[InstrumentId]
- subscribed_trades ¶
-
Return the subscribed trade feeds for the emulator.
- Returns :
-
list[InstrumentId]
- to_importable_config ( self ) ImportableActorConfig ¶
-
Returns an importable configuration for this actor.
- Returns :
-
ImportableActorConfig
- trader_id ¶
-
The trader ID associated with the component.
- Returns :
-
TraderId
- type ¶
-
The components type.
- Returns :
-
type
- unsubscribe_bars ( self , BarType bar_type , ClientId client_id=None ) void ¶
-
Unsubscribe from streaming Bar data for the given bar type.
- unsubscribe_data ( self , DataType data_type , ClientId client_id=None ) void ¶
-
Unsubscribe from data of the given data type.
- unsubscribe_instrument ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Unsubscribe from update Instrument data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The instrument to unsubscribe from.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- unsubscribe_instrument_status_updates ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Unsubscribe to status updates of the given venue.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The instrument to unsubscribe to status updates for.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue.
-
- unsubscribe_instruments ( self , Venue venue , ClientId client_id=None ) void ¶
-
Unsubscribe from update Instrument data for the given venue.
- unsubscribe_order_book_deltas ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Unsubscribe the order book deltas stream for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The order book instrument to subscribe to.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- unsubscribe_order_book_snapshots ( self , InstrumentId instrument_id , int interval_ms=1000 , ClientId client_id=None ) void ¶
-
Unsubscribe from order book snapshots for the given instrument ID.
The interval must match the previously subscribed interval.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The order book instrument to subscribe to.
-
interval_ms ( int ) – The order book snapshot interval in milliseconds.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- unsubscribe_quote_ticks ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Unsubscribe from streaming QuoteTick data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument to unsubscribe from.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- unsubscribe_ticker ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Unsubscribe from streaming Ticker data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument to unsubscribe from.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- unsubscribe_trade_ticks ( self , InstrumentId instrument_id , ClientId client_id=None ) void ¶
-
Unsubscribe from streaming TradeTick data for the given instrument ID.
- Parameters :
-
-
instrument_id ( InstrumentId ) – The tick instrument ID to unsubscribe from.
-
client_id ( ClientId , optional ) – The specific client ID for the command. If
None
then will be inferred from the venue in the instrument ID.
-
- unsubscribe_venue_status_updates ( self , Venue venue , ClientId client_id=None ) void ¶
-
Unsubscribe to status updates for the given venue.
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:
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 generate 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