The framework always responds to market depth requests, even if no depth data is available from the back-end system. What it will then send is simply changes in the current bid and ask, with no trading volume.
Where market depth is available, the back-end system may send either of the following:
Multiple quotes at each price (from different liquidity providers)
A single quote at each price
You request market depth using
| Parameter | Description |
| instrumentId | |
| requestId | An optional ID for your request, used in termination (see below). If you do not provide one, the framework will automatically allocate an ID, and report it in all responses. If you allocate your own ID, you are recommended to use FXB.utils.GenerateGuid(). |
| callback | An optional asynchronous callback function which receives the depth. You can process market-depth messages in OnMessage(), or optionally choose to receive them in a specific asynchronous callback as well. |
For example:
// Allow the framework to allocate an ID for the request, reported as the requestId in messages
Framework.RequestMarketDepth("EUR/USD", null, function (Msg) {
// Response containing market depth, also received in/via OnMessage()
// ID of the request, for use in termination, will be in Msg.requestId
});
You should terminate market depth requests when you no longer need them, using
Each market-depth update message has the following properties:
| Property | Description |
| instrumentId | |
| requestId | The ID of the market-depth request, either provided by you in your call to |
| initial | Boolean value indicating whether this the first message, or a subsequent update to the depth |
| changes | An array of changes to the market depth. For the first message, |
| depth | Object describing the full market depth, incorporating the latest changes. In other words, the framework gives you both the individual changes and also the resulting full book. You don't need to calculate the book yourself from the changes. |
The
| | Description |
| id | An ID for the quote which is being added/removed/modified |
| state | The type of change to the quote: one of |
| price | The price of the quote (e.g. 1.23456) |
| volume | The volume of the quote (e.g. 10000000) |
The
As noted above, the back-end system may have multiple quotes at each price (from different liquidity providers). The
The depth object contains the following properties:
| | Description |
| aggregated | Object containing |
| book | Object containing Dictionaries (not arrays) of the individual current bid and ask quotes. Each quote consists of an |
| bestAsk | Best ask price (same as |
| bestBid | Bid bed price (same as |
| askVolume | Total volume of all ask quotes |
| bidVolume | Total volume of all bid quotes |
A couple of final notes:
You need to be a little careful with this data. During unusual market conditions, or just very briefly during updates, it is possible for there to be no quotes on the bid side or ask side (or even both). Therefore, you cannot safely assume that
Internally within the broker's back-end system, it is possible for there to be different routes for market depth versus "trading" prices. It is not absolutely guaranteed that the