Skip to main content

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

ExchangeDescription of SIM behavior
REJECTInstant reject. SIM immediately rejects the order.
CANCELInstant cancel. SIM immediately cancels the order.
FILLInstant fill. SIM immediately fills entire order. The fill uses the limit price or stop price (when provided), or a dummy price $1234.
CORRECTSimulator issues a FILL event, immediately followed by a FILL CORRECTION.
BUSTSimulator issues a FILL event, immediately followed by a FILL CANCELLATION (BUST).
ACK,FILLSimilar to FILL, but the Simulator issues an order acknowledgement event prior to fill.
ACK,CANCELSimilar to CANCEL, but the Simulator issues an order acknowledgement event prior to cancel.
ACK,REJECTSimilar to REJECT, but the Simulator issues an order acknowledgement event prior to reject.
CANCELRJCTIssues cancel rejects.
CANCELFILLExceptional 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.
ACKOrder receives an acknowledgement event and nothing else.
RESTATESimulator acknowledges the order, then reports an “order restate event”. Can be used to test stop/stop-limit order trigger behavior.
TFILLVery 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.
SCRIPTSee the next section.
note

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

ExchangeDescription of SIM behavior
SCRIPTExecutes 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 eventDescription of SIM behaviorOptional parameters
ACKOrder acknowledgement event (OrderPendingNewEvent)N/A
OPENOrder is open on exchange (OrderNewEvent)N/A
CANCELOrder cancel confirmation event (OrderCancelEvent)Order cancellation reason.

For example:
CANCEL:Cancelled by exchange
REJECTOrder rejection event (OrderRejectEvent)Order rejection reason.

For example:
REJECT:Market is closed
CANCELRJCTOrder Cancel Reject (OrderCancelRejectEvent)Order cancellation reject reason.

For example:
CANCELRJCT:Too early to cancel
FILLOrder 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
CORRECTFill 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).
BUSTFill 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
RESTATEIssues an order restate event (OrderRestateEvent).

For example, for a triggered stop order.
N/A
DELAYDelay prior to the next event in the scriptParameter specifies delay duration. If the duration is not specified, a one second delay is used.

Intervals can be measured in the following units:
  • “10X” = 10 milliseconds, (X = Milliseconds)
  • “10S” = 10 seconds, (S = Seconds)
  • “10I” = 10 minutes, (I = Minutes)
  • “10H” = 10 hours, (H = Hours)
For example:
DELAY:10S
DISCONNECTSimulates an “Exchange Disconnected” event.
CONNECTSimulates an “Exchange Connected” event.

The following screenshot shows how to submit a SCRIPT order to SIM using Ember Monitor:

SIM Order Entry in Ember Monitor

Scripting examples

Examples of execution simulation scripts:

REJECT:Bad priceOrder reject event with a “bad price” rejection reason
OPEN,FILLThe order completes the fill after the order becomes open on the exchange.
OPEN,FILL:5Same as above, but the order is filled only for quantity = 5.
FILL:5:123.45Order is filled without am intermediary OPEN event; fill quantity is 5; fill price is 123.45.
OPEN,FILL:900,CANCELPartial fill of size 900, followed by Cancel message (missing fill of 100, assuming that the order size is 1000).
DELAY:1S,ACK,DELAY:5S,FILLInitial order acknowledgement event is delayed by 1 second after order submission. Fill is delayed 6 seconds (1+5).
OPEN,CANCEL,FILLExample of abnormal “fill after cancel” order workflow.
OPEN,FILL:33, DELAY:5S, FILLEmpty 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.