4.5.1ORDER_x messages in OnMessage

The ORDER_OPEN, ORDER_CHANGE, and ORDER_CLOSE messages are issued on changes to the order list (which includes both pending orders and open trades).

ORDER_CHANGE is issued for changes in the current price and/or profit on an open trade, as well as trading actions such as moving its stop-loss.

The FXB.Message object will contain arrays listing the new/changed/closed orders:

FXB.MessageTypes.

Array

ORDER_OPEN

ordersOpened[]

ORDER_CHANGE

ordersChanged[]

ORDER_CLOSE

ordersClosed[]

A single message from the framework can contain multiple updates, and therefore the message may contain all of these arrays. For example:

Framework.OnMessage = function(Msg) {

if (Msg.is(FXB.MessageTypes.ORDER_OPEN)) {

… process changes in Msg.ordersOpened[]

}

if (Msg.is(FXB.MessageTypes.ORDER_CLOSE)) {

… process changes in Msg.ordersClosed[]

}

};

Each item in one of these arrays is simply an FXB.Order object describing the new/changed/closed order or trade.

You can react to the changes either by looking at the arrays of orders, or by looking at the Framework.Orderscollection which will already have been updated.

However, in addition to the standard members of FXB.Order, each item in the arrays also has an updateMarker. This is a bit-mask describing what has changed about the order. Particularly for changes rather than opens and closes, this is designed to help you minimise the work in updating a user interface, avoiding updates to HTML elements which don't need to be changed.

The possible flags are members of the FXB.UpdateFlags enumeration:

FXB.UpdateFlags.

Description

FLAG_ORDER_NEW

Order is new (should only exist in ordersOpened[] array)

FLAG_ORDER_TYPE

Change in orderType - for example, when logged in to a back-end platform where an order can change from pending to filled without changing ticket/reference number

FLAG_ORDER_VOLUME

Volume has changed, for example as a result of a partial close

FLAG_ORDER_PROFIT

Profit has changed

FLAG_ORDER_SLTP

Stop-loss and/or take-profit has changed

FLAG_ORDER_CURRENTPRICE

Current price (closePrice) has changed

FLAG_ORDER_OPENPRICE

Open price has changed - alteration to the entry price on a pending order

FLAG_ORDER_COMMENT

Order comment has changed

FLAG_ORDER_OTHER

Any other change to order properties

FLAG_ORDER_CLOSED

Order is closed/cancelled (should only exist in ordersClosed[] array)