Using market orders for your crypto trading bot

In the world of crypto bot trading, market orders are commonly used, particularly when beginning to develop a trading bot. They’re straightforward and easy to implement, allowing traders to buy or sell assets at the current market price without having to worry about setting a specific price point. However, while market orders may seem like the most practical option, they may not always be the best way to trade for your crypto trading bot.

In this article I will explain more about market orders and share my own experiences.

Lets dive in!

What are market orders

When placing a market order on a crypto exchange, you are instructing the exchange to buy or sell a specific cryptocurrency at the best available price on the market. This means that the order will be executed immediately, as long as there are enough buyers or sellers on the exchange to fulfill the order.

In other words, if you wish to buy Bitcoin using a market order, the exchange will locate the best available sell orders on the market and match them with your buy order, allowing you to buy the Bitcoin immediately. Similarly, if you want to sell some Bitcoin using a market order, the exchange will find the best available buy orders on the market and match them with your sell order, allowing you to sell the Bitcoin immediately.

Market orders can be a good option if you want to execute a trade quickly and do not mind paying the current market price for the cryptocurrency you are buying or selling. However, keep in mind that the price you pay or receive for your cryptocurrency may not be precisely what you expected since the market price can fluctuate rapidly. Another issue is that you may experience slippage, particularly when placing large orders.

In extreme situations, especially when dealing with significant amounts of capital, your market order may slice through the order book. This happens when your order is so large that there is insufficient demand at current prices to fulfill it. As a result, your order affects the price and causes it to move. For example, if you were to place a substantial market buy order on a small altcoin, the price of the altcoin may increase by several percentage points. However, this also implies that if you placed a buy order at $1, it could have been executed at $1.05, which could be a risky move.

What are limit orders

When you place a limit order to buy a specific cryptocurrency, you set the maximum price you’re willing to pay. If the market price of the cryptocurrency drops to your limit price, your order will be executed and you’ll buy the cryptocurrency at that price or lower. If the price doesn’t reach your limit, your order will not be executed. Additionally, it’s possible that only a portion of your order will be filled, leaving you with a partial position.

Limit orders are useful because they allow you to control the price at which you buy the cryptocurrency. This can be helpful in volatile markets where prices can change quickly. By using a limit order, you can avoid overpaying for Bitcoin or missing out on a good buying opportunity.

When you are using limit orders you will not have any price slippage. Also the impact you are having on the market is significantly lower than while using market orders.

The convenience of market orders while trading with your crypto trading bot

When developing a crypto trading bot, market orders are your best bet when getting started. Market orders can also offer the advantage of knowing that your position is filled in reality, which may not always be the case when using limit orders.

However, the price you see in your backtest is probably not the price at which your order is filled. It is highly likely that if you place an order at $10,000 and the market is moving up quickly, it is filled at $10,050, for example.

This may not seem like a significant problem, right? Bitcoin is volatile, and I will make that back on the trade. However, that may not be the case. Algo trading is about big numbers, and if your trading strategy focuses on profiting from small price movements, that $50 can be a significant amount of your profit. If you do this 1,000 times, it will cost you a lot of profit or turn your profitable trading strategy into a losing one.

As a result, there are two options available for accurately calculating your backtest results:

If you opt to use limit orders, ensure that your crypto trading bot keeps track of whether positions are filled properly during backtesting.
Alternatively, if you choose to use market orders, factor in the potential slippage and higher trading fees into your backtesting calculations to accurately evaluate the performance of your bot.
So, if you are trading with little capital or developing your crypto trading bot, use market orders to your advantage. If you are not, only use them for stop losses or make sure the market order trading fees and slippage will not impact your profit too much. Cross-check your live trading performance with your backtest!

My experiences

When you first start trading, slippage may not be a big concern because you won’t have a lot of capital running on your bots. However, as you grow, slippage may become a bigger problem. There are two types of slippage in bot trading: price slippage, which was explained earlier in this article, and time slippage, which is the time it takes to execute your order.

When your algo decides it’s time to place an order, it has to go through a series of steps:

  1. The candle closes, the algo decides to buy
  2. The buy signal now goes to your crypto trading bot
  3. The crypto trading bot sets up an API connection with your exchange and places the order
  4. The exchange executes the market order.

All of these steps take time, and the amount of time can vary depending on your setup and the speed of the exchange.

For example, let’s say Elon Musk tweets that he likes Bitcoin, causing the price of Bitcoin to rise rapidly. If your time slippage is 2 seconds and the price rises 0.5% during those seconds (which can happen in the crypto wild west), your entry may not be as good as your algo thought it was.

Because of price and time slippage, the difference between your backtest and real-life performance can grow. For instance, if you open a position at $10000 and it gets filled at $10050 due to price and time slippage, that’s a difference of 0.5%. However, if you’re trading with a multiplier (a delta) of 4, this difference of 0.5% becomes 2% (0.5 x 4 = 2%). If this happens 5 times out of 20 trades in a month, the difference between your backtest and real-life performance is now 10%.

Using limit orders in crypto bot trading

The only solution to this problem is to use limit orders where it is possible. Generally, in crypto bot trading, you have the following orders:

  • Buy or Sell
  • Take Profit
  • Stop Loss

For the buy, sell, or take profit orders, it is definitely possible to use limit orders. Stop loss orders will always be market orders due to the nature of the order. You want to know that the order really gets closed when it gets hit. I’ve seen trading bots using limit stop orders, but if the market is moving too fast, it is possible that the limit stop order does not get filled. In that case, your position could get liquidated.

The technical implementation of using limit orders can, however, be complex. Let’s start with an example: 

You are opening a limit order on the 5-minute timeframe at $5.10, which happens at the open of a new candle. At the end of the 5-minute candle, the limit order is not filled. You need to ensure that your trading bot knows the limit order is not filled, which is a technical challenge. Let’s say you solved this challenge and the algorithm knows that it’s not in a position. Now, the algorithm has three choices:

Cancel the last order and open a new limit order at the new candle, and repeat until filled.
Wait for a longer period to fill, which might never happen.
Cancel the last order and not open a new order.
Choose the option that matches your strategy. However, make sure that in your backtests, you also implement this logic. Because in your backtest, you want to make sure that these scenarios are calculated appropriately. If you don’t, your backtest will be very unreliable.

It has taken me more than a year to get limit orders implemented correctly in my crypto trading bots and backtests. Since then, we have reduced price slippage by 90% (we still have slippage on stop loss orders, those are market orders). And we have reduced trading fees by 50%. So, is it worth it?

Well, it’s mandatory in my line of business. We trade with big numbers, so using market orders is no longer an option.

Trading fees while using market orders with your crypto trading bot

Trading fees can be a concern when using market orders in crypto bot trading. Market order trading fees on crypto exchanges are typically higher than those for limit orders. During the development of your crypto trading bot, backtesting is often used to verify its profitability. If you choose to use market orders, you may encounter slippage with each trade and incur higher trading fees. For example, on Binance, limit orders cost 0.02% in fees compared to market orders at 0.04%.

Conclusion

Market orders can be convenient for bot trading and can save you time and effort in developing your bot, since limit orders require additional logic to be built into your trading bot. However, if you are experiencing high price slippage, time slippage, or high trading fees, limit orders may be the better option.

The opinion expressed in this blog article is for general informational purposes only and is not intended to provide specific advice or recommendations for any individual or on any specific security or investment product.