Single Order Execution: The Traps of A Careless TWAP

Photo by Nick Fewings on Unsplash

Greetings! Welcome back to the Chassis publication series. In the past several months we have put our discussions on the heavy focus of high frequency market making. Starting today we will shift gears a little bit and write several articles about a new topic that hasn’t been frequently and adequately discussed in the crypto trading community: Single Order Execution. It’s quite important if you ever need to place an order whose size is relatively large compared to the market’s available liquidity: For BTC, this might be a $100K order. For smaller coins, this might even be a $1K order. We’ll perform a quick review on the available algorithms for handing such orders and point out several dangerous aspects on how carelessly constructed algorithms, even for the simplest case, can lead to losses and become a vulnerable target from other traders.

Single order execution algorithms are used to execute a single large order without excessive impact on the market price by splitting it into smaller child orders. Although there are a wide variety of algorithms where, if we strip off the customizations, we can see a small set of core algorithms that are most commonly utilized. The table below shows some common algorithms grouped using three main categories: impact-driven, cost-driven, and opportunistic. It also shows some of the specific factors which algorithms are most affected by or sensitive to. If you are eager to know more details right away about all these algorithms, see:

  1. Barry Johnson “Algorithmic & Trading DMA — An Introduction To Direct Access Trading Strategies” (2010).
  2. H. Kent Baker, Greg Filbeck. “Portfolio Theory of Management” (2013).
  3. Jeffrey M Bacidore, “Algorithmic Trading: A Practitioner’s Guide” (2020).
Common algorithms grouped using three main categories. Reprinted from “Algorithmic Trading and Direct Market Access” by Barry Johnson.

In the past several weeks we have been working hard on bringing some of these prominent algorithms as simple-to-use applications into our open source library: Release v5.21.0 has achieved the first step: the Time Weighted Average Price (TWAP) execution algorithm. And we want to share our thoughts and discoveries about how things can go wrong and become dangerous even for such a “simple” algorithm. TWAP, in its simplest form, is an algorithm with which traders can define a time period over which they want to buy or sell assets. It will slice a big order into smaller ones and execute them over that defined period. We can represent this task with some pseudo-code:

for timer = 1 to M:
quantity = 0.1
sleep(N seconds)

Let’s discuss what the traps are and you can see them present in commercially available crypto softwares:

[1] Negligence of Signalling Risk: If the implementation uses a fixed trading pattern by evenly slice the big order into equal smaller parts and puts the order submissions on equally temporally spaced time points, it may be easy for other traders (predatory traders) to detect such trading patterns by using order flow and trade information. Surprisingly, a dozen of crypto trading software providers offer the TWAP algorithm in this naive and predictable form. The threat coming from these predatory traders can be quite significant. In fact, we are one of those who are actively looking for such opportunities by analyzing a comprehensive dataset ( that we’ve accumulated in the past several years. The solution to this TWAP information leakage issue is also surprisingly easy: introduce some randomness in either the trading quantity for each child order or the trading timing for each child order or both. And we chose to randomize the child order quantity. Using our single-order-execution application, you can configure the desired amount of randomness. 🎉

[2] Negligence of Dollar-Cost Averaging: It is well-known that dollar-cost averaging is an investment strategy in which an investor divides up the total amount to be invested across periodic purchases of a target asset in an effort to reduce the impact of volatility on the overall purchase. The important thing is that as a buy-side trader what we need to average is the dollar not the target asset and as a sell-side trader what we need to average is the target asset not the dollar. For example, if we are trying to buy BTC with USD, we’d create child orders each having the same USD quantity not the same BTC quantity, and if we are trying to sell BTC for USD, we’d create child orders each having the same BTC quantity not the same USD quantity. Surprisingly, even some prominent crypto trading software providers TWAP implementation only allow users to specify an order quantity in the base currency no matter what. For us, such a feature isn’t optional but a must-have. Using our single-order-execution application, you can configure whether to submit orders with (approximately due to [1]) equal quantities in base currency or in quote currency. 🎉

[3] Negligence of Backtesting: Single order execution algorithms were invented to deal with efficient execution of large orders. Before touching a non-trivial amount of real money, a careful trader will always test it in a simulated environment. This can be paper trading, or even better backtesting if you have the relevant market data at hand. Even for a “simple” TWAP strategy, if we are given the task of buying BTC in the next 1 hour with 1 million USD, the natural questions that we’d ask are: a. What is the optimal number of child orders? b. For each child order, what is the appropriate order limit price? c. At the end of this task is 100% order completion a hard requirement or a soft requirement? Careless traders may choose to answer these questions by gut-feeling and careful traders by quantitative testing. Surprisingly, none of the crypto trading software providers that we studied offers backtesting capabilities on single order execution algorithms. Using our single-order-execution application, you can configure the program to run in backtest mode using market data from any data provider (which of course includes ourselves: 🎉

If you are interested in our work or collaborating with us, join us on Discord: 🎉 We specialize in market data collection, high speed trading system, infrastructure optimization, and proprietary market making. You’re welcome to hire us as engineers, liquidity providers, traders, or asset managers.

Disclaimer: This is an educational article rather than investment/financial advice.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store