SIM Algorithm
Overview
This document describes how to use the SIM trading connector.
Ember ships with two services that can be used to simulate order execution:
- SIMULATOR – A special algorithm that provides realistic order execution. The algorithm uses the QuoteFlow library to maintain the state of the markets and estimate accurate order execution.
- SIM – A special trading connector that can replay some simple execution scenarios, for example a simple fill at limit price, or order reject. See the rest of this document for more information.
Configuration
The following config stanza shows how to enable the SIM trading connector in ember.conf:
connectors {
SIM: ${sim}
}
See the Ember Configuration Reference guide for more information about the ember.conf configuration file.
Order routing
To send orders to SIM, specify it as an order destination.
SIM supports multiple order execution scenarios. Simple scenarios can be specified using the exchange order field. For more complex scenarios you can use the custom order attribute SimScript(7001)
.
Supported exchanges
Exchange | Description of SIM behavior |
---|---|
REJECT | Instant reject. SIM immediately rejects the order. |
CANCEL | Instant cancel. SIM immediately cancels the order. |
FILL | Instant fill. SIM immediately fills entire order. The fill uses the limit price or stop price (when provided), or a dummy price $1234. |
CORRECT | Simulator issues a FILL event, immediately followed by a FILL CORRECTION. |
BUST | Simulator issues a FILL event, immediately followed by a FILL CANCELLATION (BUST). |
ACK,FILL | Similar to FILL, but the Simulator issues an order acknowledgement event prior to fill. |
ACK,CANCEL | Similar to CANCEL, but the Simulator issues an order acknowledgement event prior to cancel. |
ACK,REJECT | Similar to REJECT, but the Simulator issues an order acknowledgement event prior to reject. |
CANCELRJCT | Issues cancel rejects. |
CANCELFILL | Exceptional scenario: An order is reported as CANCELLED, followed by a FILL event (abnormal order state transition that may happen on some exchanges, like Eurex). |
BLACKHOLE | “Black Hole” – no events are issued for the order. |
ACK | Order receives an acknowledgement event and nothing else. |
RESTATE | Simulator acknowledges the order, then reports an “order restate event”. Can be used to test stop/stop-limit order trigger behavior. |
TFILL | Very similar to FILL, but the fill is reported using the “total quantity/average price” reporting method (used by some exchanges). This can be used to test the OMS functionality (Ember OMS converts such fills to normal incremental fills for algorithms and clients. |
SCRIPT | See the next section. |
Exchange values are case-sensitive, trailing/inner/leading spaces are not allowed.
Scripted order execution
For users who want more flexibility, SIM provides an ability to specify what exact events should be issued for an order. You can also specify how events should be delayed (to simulate order transmission or execution delay).
Exchange | Description of SIM behavior |
---|---|
SCRIPT | Executes an order according to a script specified by custom order request attribute 7001. |
Attribute 7001 contains a comma separated events that should be issued for an order (left to right). The following events are supported:
Script event | Description of SIM behavior | Optional parameters |
---|---|---|
ACK | Order acknowledgement event (OrderPendingNewEvent ) | N/A |
OPEN | Order is open on exchange (OrderNewEvent ) | N/A |
CANCEL | Order cancel confirmation event (OrderCancelEvent ) | Order cancellation reason. For example: CANCEL:Cancelled by exchange |
REJECT | Order rejection event (OrderRejectEvent ) | Order rejection reason. For example: REJECT:Market is closed |
CANCELRJCT | Order Cancel Reject (OrderCancelRejectEvent ) | Order cancellation reject reason. For example: CANCELRJCT:Too early to cancel |
FILL | Order fill event (complete or partial) | The first optional argument is fill quantity (by default, the entire order). The second optional argument is a fill price (by default, the limit or stop price of the order is used as the fill price).Third and forth optional parameters may specify commission and commission currency. For example: FILL FILL:50 FILL:100:123.45 FILL:100:123.45:0.25 FILL:100:123.45:0.25:USD |
CORRECT | Fill correction event (OrderTradeCorrectionEvent ) | Index of fill event to correct (zero-based). Identifies a previous fill event. By default, the first fill event is corrected. For example: CORRECT CORRECT:1 Just like for FILL, the first optional argument is a corrected fill quantity (by default, the entire order). The second optional argument is a corrected fill price (by default, the limit or stop price of the order). |
BUST | Fill cancellation event (OrderTradeCancelEvent ) | Index of fill event to cancel (zero-based). Identifies a previous fill event. By default, the first fill event is cancelled. For example: BUST BUST:1 |
RESTATE | Issues an order restate event (OrderRestateEvent ).For example, for a triggered stop order. | N/A |
DELAY | Delay prior to the next event in the script | Parameter specifies delay duration. If the duration is not specified, a one second delay is used. Intervals can be measured in the following units:
DELAY:10S |
DISCONNECT | Simulates an “Exchange Disconnected” event. | |
CONNECT | Simulates an “Exchange Connected” event. |
The following screenshot shows how to submit a SCRIPT order to SIM using Ember Monitor:
Scripting examples
Examples of execution simulation scripts:
REJECT:Bad price | Order reject event with a “bad price” rejection reason |
---|---|
OPEN,FILL | The order completes the fill after the order becomes open on the exchange. |
OPEN,FILL:5 | Same as above, but the order is filled only for quantity = 5. |
FILL:5:123.45 | Order is filled without am intermediary OPEN event; fill quantity is 5; fill price is 123.45. |
OPEN,FILL:900,CANCEL | Partial fill of size 900, followed by Cancel message (missing fill of 100, assuming that the order size is 1000). |
DELAY:1S,ACK,DELAY:5S,FILL | Initial order acknowledgement event is delayed by 1 second after order submission. Fill is delayed 6 seconds (1+5). |
OPEN,CANCEL,FILL | Example of abnormal “fill after cancel” order workflow. |
OPEN,FILL:33, DELAY:5S, FILL | Empty script results in no events. This is abnormal – typically, all order destination venues are required to provide some kind of feedback events for each order. |