Let’s start with the most simplistic (at least at first glance) type of order: the market order. A market order is an order to buy or sell a certain amount of an asset at a market price. By market price, we normally assume the best bid or the best ask (see Lesson 3, FX Market Overview from a Developer’s Standpoint, for the explanation of the best bid and ask), and most trading strategy developers test their ideas using only the best bid/ask historical data. So, we can add another record to our order ticket prototype, and this record represents the order type:

Figure 10.5 – Specifying the order type
We already saw (see again Lesson 3, FX Market Overview from a Developer’s Standpoint) that liquidity may have a substantial impact on how orders are executed in reality and it is considered quite a frequent situation when a single large order may move the best bid or ask during its execution. So, it’s important to make sure that the order will be executed at a price closest to the last best bid or best ask seen in the order app immediately before sending the order to the market.
Using this order type makes sure that if the order is executed, then you get the exact amount of the traded asset specified in the order. At the same time, it doesn’t guarantee that the average execution price will be the same as the top of the app because this kind of execution method allows buying or selling up to the entire amount currently present in the order app.
For example, let’s have a look back at the example of an order app shown in Lesson 3 (Figure 3.1 in the Exchange and order app section). Imagine that we send a market order to buy 1,000 contracts. Will it be executed? Yes, because there are more than 1,000 contracts in the order app. But at which price will it be filled?
The order app at the moment of sending the order had 155 contracts at the best ask price (2,149.25), then 306 contracts at 2,149.50, then 291 contracts at 2,149.75, and 532 contracts at 2,150.0. So our order will consume all liquidity from the first 3 price levels and 248 contracts from the 4th. The resulting average execution price can be calculated using the standard weighted average formula:

Here, P means the weighted average price, p denotes the price in the order app, and q means the quantity, the number of contracts traded at the price, p. In our example, it will be about 2,149.658, which is quite far from 2,145.25, which used to be the best ask at the moment we fired our order.
The phenomenon of an order being executed at a worse market price or the process of filling the order in parts according to the present liquidity is called slippage.
So, market orders can be useful when we need to fill the exact trading size, but this also may lead to filling at a price worse than expected. Why then did we say that market orders are the way to get maximum control over transactional risk in the very title of this section?
The reason is that by using market orders, you can be as granular and as precise with the ordering as possible. Indeed, nothing prevents us from developing an algorithm that would first check the liquidity in the order app and then send orders only of the amount that would not destroy it. In case you need to fill an order with a large size (for example, you work for a financial institution), you can split this order into parts and send multiple market orders in sequence until the entire amount is filled – again, without disturbing the order app too much.
Another benefit, if I may say so, of using market orders is that this is the only type of order that is accepted by all trading venues without a single exception. Although we are going to consider orders of other types, such as limit and stop, remember that they are not always supported by the venue with which you plan to work.
Leave a Reply