Start iteration | |
i | Initialise the count variable, start the iteration, move into the iterate state. No block parameters are required for this process. |
When | true |
Then | count = 0 iterate [Order Manager] move to state [ iterate ] |
Check iteration complete | |
i | If the iteration is complete, move into next state, where we do something with the count. |
When | complete from Order Manager (iteration complete) |
Then | move to state [ next state ] |
Check order is for symbol and in market | |
i | If the order’s symbol is what we are looking for and it is currently working in the market, increment the count. |
When | ( symbol from Order Manager (order status) is equal to symbol ) and in market from Order Manager (order status) |
Then | count = ( count + 1 ) |
Next iteration step | |
i | Always move onto the next iteration step. The iteration state must contain a rule that calls next, else the scenario might never leave the iteration state. Note that the action is to move to this state, which is different from remaining in this state (all rules are re-evaluated, even if they have not changed, such as this rule). |
When | true |
Then | next [Order Manager] move to state [ iterate ] |
SubmitOrder1 | |
i | Issue an order to BUY 100 lots of APMA. Use an order identifier of "1". Set the timer’s trigger time to be 5 seconds and assign the same identifier to the timer. Start the timer. This creates a timer that fires after 5 seconds. When it fires, it returns the identifier assigned to the timer, which is 1 in this example. |
When | true |
Then | order identifier from Order Manager = "1" symbol from Order Manager = "APMA" side from Order Manager = "BUY" quantity from Order Manager = 100 submit order [Order Manager] time from Wait 1 = "5" timer id from Wait 1 = "1" start [Wait 1] remain in this state |
SubmitOrder2 | |
i | As above, but now the order identifier is "2" and the order is to SELL 200 lots of "ABCD". |
When | true |
Then | order identifier from Order Manager = "2" symbol from Order Manager = "ABCD" side from Order Manager = "SELL" quantity from Order Manager = 200 submit order [Order Manager] time from Wait 1 = "5" timer id from Wait 1 = "2" start [Wait 1] remain in this state |
Wait for both orders to complete | |
i | Total number of orders in the market is zero, so both orders are complete. |
When | in market from Order Manager (order book status) is equal to 0 |
Then | move to state [end] |
Wait for one of the timers to fire | |
i | When a timer fires, the scenario uses the timer’s identifier to point to the order in the order book that has the same identifier. The scenario then cancels that order, and leaves the other order untouched. The scenario resets the timer so that it is ready for the next time-up event. |
When | time up from Wait 1 (timer) |
Then | order identifier from Order Manager = timer id from Wait 1 (timer) cancel order [Order Manager] reset [Wait 1] remain in this state |
Parameter | Description |
order identifier | A unique identifier in the scope of the Order Manager block. The block uses this identifier to perform operations on the order. |
service identifier | The name of the market service provider monitor to use, or an empty string to use any market service provider monitor. |
broker identifier | The name of the broker to send the order to. To determine whether you need to specify this parameter, and obtain more information about the meaning of this parameter, see the documentation (this is often a README file) for the adapter you are using. If the documentation does not mention this parameter, you do not need to specify it. |
book identifier | The name of the book the order should be accounted against. To determine whether you need to specify this parameter, and obtain more information about the meaning of this parameter, see the documentation for the adapter you are using. If the documentation does not mention this parameter, you do not need to specify it. |
market identifier | The name of the market to send the order to. To determine whether you need to specify this parameter, and obtain more information about the meaning of this parameter, see the documentation for the adapter you are using. If the documentation does not mention this parameter, you do not need to specify it. |
exchange | The name of the exchange to send the order to. To determine whether you need to specify this parameter, and obtain more information about the meaning of this parameter, see the documentation for the adapter you are using. If the documentation does not mention this parameter, you do not need to specify it. |
symbol | The instrument to trade. |
price | The price to trade at, or 0 for a market order. |
quantity | The amount to trade. For example, the number of shares to buy or sell. |
side | BUY or SELL. Some services also support other values such as BUY MINUS or SELLSHORT. |
type | MARKET or LIMIT. Some services also support other values such as STOPMARKET or STOPLIMIT. If left blank, the order is placed as a LIMIT if a price is specified or a MARKET order if no price is specified (or is 0). |
extra parameters | Any extra parameters for the service. |
leave orders open on scenario exit | If true, the block does not cancel orders when the scenario enters the end state. This leaves the orders uncontrollable in the market. |
clear orders in final state | If true, removes references in the order book to the order after the order enters the Completed state. You cannot retrieve such an order with a retrieve order or iterate operation, and the order book status output feed does not include cleared orders in its counts. |
auto-generate order identifier | If true, the Order Manager block generates the order identifier for you when you place an order. The generated identifier has the following format: Order_n Obtain the generated order identifier from the order identifier field of the order status output feed. The Order Manager block sends data to this feed immediately after you place an order. The default is that this parameter is set to false, which means that you must explicitly specify a unique order identifier when you submit an order. (This ensures that scenarios created with Order Manager block versions from before this parameter was added can continue to work without modification.) |
add scenario info to extra params | If true, the Order Manager block adds scenario information to the extraParams field of events generated by the OrderManagerSupport monitor. The default is that this parameter is false. You might need to set this parameter if you are writing a monitor to be used in the service layer. Such a monitor accepts messages from the Order Manager block and sends messages to the market. If you are not writing a service layer monitor, you would not need to modify this parameter. For information about the service layer, see the OrderManagerSupport monitor, which is in the monitors\finance directory of your Apama installation directory. When this parameter is true, the Order Manager block adds the following information: Current Scenario Id — in the extraParams dictionary, the key is ScenarioName. Current Scenario display name — the key is ScenarioDisplayName. Current Scenario instance Id — the key is ScenarioInstance. After your Order Manager block executes a submit order, modify order, or cancel order operation, the Order Manager block adds the above listed scenario information to the extraParams field of the NewOrder, AmendOrder, or CancelOrder event that the OrderManagerSupport monitor generates. Setting this parameter is useful when there are many scenarios in your system, and you need to know which scenario sent a new order, or cancelled or amended an order. You can set up monitors that listen for the NewOrder, AmendOrder, and CancelOrder events, inspect their extraParams member, and extract the scenario information. In your dashboard, you might display a list of the orders sent. If so, it is useful to see both the scenario display name of the scenario that created that order (so you can see which of your algorithms initiated the order) and also the scenario instance ID (so you can track the order back to the specific instance that generated it). |
Operation | Description |
submit order | Send the order to the market. The order automatically enters state 1, waiting for acknowledgment. |
modify order | Change the order in the market. The order automatically enters state 5, pending change, unless the order is not modifiable at this time. |
cancel order | Cancel the order in the market. The order automatically enters state 6, pending cancel, unless the order is not modifiable at this time. The market can reject a cancellation. Consequently, after an order is in the pending cancel state, it can become cancelled, completed, or, if the cancellation is rejected, working. |
retrieve order | Retrieve information about the order specified by the order identifier parameter. You can obtain the state of a previously placed order even if other orders have been processed since the specified order. |
clear | Clears the order status and iteration complete output feeds. This operation has no effect on the market state. If you have output feeds connected directly to your user interface, you might call this operation to refresh the user interface. |
cancel all orders | Cancel all orders. Note that the market might reject some cancellations. |
iterate | Begin iterating over all orders in the Order Manger block’s order book. The iteration is complete when the iteration complete output feed becomes true. For an example, see Obtaining the status of orders placed. |
next | Continue to the next order in the iteration. The order in which the next operation visits orders in the order book is undefined. |
clear book | Delete information about all orders that have been placed, including any that are still active. Initiate this operation with great care. It is dangerous to lose track of orders if they are still active. This operation empties the internal order book. Immediately following this operation, the value of the total executed field of the order book status output feed is zero. |
clear order | Delete information about the order identified by the order identifier parameter, even if that order is still active. There are no further trades for this order. In general, you should not clear an active order because you can then no longer amend or cancel that order, nor obtain information about that order, such as how much money was made or lost as a result of that order. |
Feed | Fields | Description |
order status | order identifier | The Order Manager block’s unique identifier, which was specified or generated when this order was placed. This identifier distinguishes this order from every other order placed by this block. |
market order identifier | An identifier supplied by the market, typically unique across all orders in that market. | |
symbol | Identifier for the instrument being traded. | |
price | The price requested either when the order was submitted or the latest modification. A price of 0.0 signifies a market order. | |
quantity | The total number of units, such as shares, to trade, or the number the order has been amended to. | |
side | The side of the order — BUY, SELL, or some other side supported by the market. | |
type | The type of the order — MARKET, LIMIT, or some other type supported by the market. | |
state | The order’s state indicated by 0-9. See Order states and statuses. | |
money executed | The sum of price * quantity for all fills of this order, or 0.0 if no fills have occurred. | |
average price executed | The volume-weighted average price over all fills, or 0.0 if no fills have occurred. For example, suppose you place an order to buy 100 shares of IBM at up to $10.00 per share. You bought 20 shares at $9.95 and 20 shares at $9.97. The average price executed is $9.96. | |
last price executed | The price obtained per item for the last fill, or 0.0 if no fills have occurred. | |
last quantity executed | The number of items traded in the last fill, or 0 if no fills of this order have occurred. | |
quantity executed | The number of items traded so far, or 0 if no fills of this order have occurred. | |
quantity remaining | The number of items left to trade in the market as part of this order. | |
in market | true if the order is known to the market. | |
is visible | true if the order is visible in the market. Some markets consider orders to be invisible until a certain condition has been met, for example, stop orders are invisible until the trigger price is hit. | |
modifiable | true if the order can be modified immediately. The Order Manager block queues any attempts to modify an order when it is not modifiable. The queued modification cannot occur if the order enters a final state before becoming modifiable. | |
cancelled | true if the order has been rejected or cancelled, possibly before being entered into the market. A cancelled order might have had some quantity traded. | |
change rejected | true if the most recent modification or cancellation was rejected by the market. An explanation might be available in the status message field. | |
externally modified | true if the order has been modified by anything other than the scenario, for example, the market or a third party. | |
final | true if the quantity specified for the order has been traded, or if the order was cancelled. | |
status message | A message from either the market service provider monitor or the market explaining what has happened. The format and meaning of the message varies from service to service and market to market. | |
extra parameters | String that specifies additional parameters, which contain more information about the instrument being traded. | |
order book status | number of orders | The number of orders that are in the block’s order book. This is the number of orders that have been placed from this instance of the Order Manager block, including those that are in a final state, but not those orders that have been cleared from the order book |
total placed | The total number of shares for which an order has been placed from this instance of the Order Manager block, where the order has reached the market. This includes orders that have been cancelled, rejected, and completed, as well as orders that are in the market. | |
total executed | The sum of the quantities executed for all orders. For example, the quantity executed for a particular order might be the number of shares that have already been sold. If there are two orders that each sold 100 shares, they would add 200 to the value of total executed. This number does not include any orders that have been cleared from the order book. | |
total working | The sum of the quantities remaining to be traded for all orders that are in the market. As you might expect, this includes orders in states 2, 5, 6, and 8. However, it also includes orders that are in state 1, that is, orders that have been submitted to the market but not yet accepted. For example, if you place an order to buy 100 shares and so far 75 shares have been bought, the value of total working is 25. | |
waiting for acknowledgement | The number of orders in the order book that are in state 1 — waiting for acknowledgment from the market service provider monitor. | |
working | The number of orders in the order book that are in the market and modifiable. These are the orders that are in state 2 (in the market) and they are not in state 5 (pending change) or state 6 (pending cancel). | |
complete | The number of orders in the order book that are in state 3 (completely filled). | |
rejected | The number of orders in the order book that are in state 4 (rejected). | |
pending change | The number of orders in the order book that are in state 5 (pending change). | |
pending cancel | The number of orders in the order book that are in state 6 (pending cancel). For additional details, see Cancelling orders. | |
cancelled | The number of orders in the order book that are in state 7 (cancelled). | |
suspended | The number of orders in the order book that are in state 8 (suspended). | |
in market | The number of orders in the order book that are in the market but not necessarily modifiable. These are the orders that are in state 2 (in the market) or state 5 (pending change) or state 6 (pending cancel). | |
visible | The number of orders that are visible in the market. For example, stop orders are invisible until they have been triggered. | |
modifiable | The number of orders that are modifiable. | |
tradeable | The number of orders that might trade. This count includes every order that is not final. If a scenario waits until it has no outstanding orders in the market, it should wait for the tradeable field to become 0. | |
iteration complete | complete | true if the iteration has completed |
order execution | order identifier | The Order Manager block’s unique identifier that was specified or generated when this order was placed. This identifier distinguishes this order from every other order placed by this block. |
symbol | Identifier for the instrument being traded. | |
side | The side of the order – BUY or SELL. | |
money executed | The total amount of money that has been exchanged for all fills of this order. This is the sum of the amounts exchanged for each order. For each order, this is price * quantity. | |
average price executed | The volume-weighted average price per item over all fills of this order. | |
quantity executed | The sum of the number of items, such as shares, traded in each fill of this order. | |
last money executed | The amount of money exchanged for the last fill of this order. This is: last price executed * last quantity executed. | |
last price executed | The price per item in the last fill of this order. | |
last quantity executed | The number of items traded in the last fill of this order. | |
final | true if the quantity specified for the order has been traded. | |
extra parameters | A string that contains any other information from the market. See Optional and extra parameters. | |
order quantity | order identifier | The Order Manager block’s unique identifier that was specified or generated when this order was placed. This identifier distinguishes this order from every other order placed by this block. |
symbol | Identifier for the instrument being traded. | |
side | The side of the order – BUY or SELL. | |
quantity executed | The total number of items, perhaps shares, traded in every fill of this order. | |
last quantity executed | The number of items, perhaps shares, traded in the last fill of this order. | |
final | true if the quantity specified for the order has been traded. | |
extra parameters | A string that contains any other information from the market. See Optional and extra parameters. |