Alice in Wonderland: Applying Sandwich Arbitrage on Centralized Exchanges

Crypto Chassis
5 min readNov 16, 2022

--

Photo by Mae Mu on Unsplash

Greetings, Ladies and Gentlemen! Hope that you had a great breakfast/lunch/dinner. In recent years with the proliferation of decentralized exchanges (DEXs), a new type of arbitrage has emerged and the community named it “sandwich arbitrage”. An interesting question triggered our thoughts long time ago: Can the same type of arbitrage be applied on centralized exchanges (CEXs)? Before answering this question, let us first digest some information from a “sandwich arbitrage” example in our every day’s life.

Suppose that Apple Inc. is going to release a fascinating next-generation product of its iPad. It announces that this new iPad will become available to purchase at a price of $1000 at an Apple Store at 6am in the morning of January 1st. Bob is a big fan of iPad and he really wants to get it. However, Bob is very lazy and doesn’t want to get up so early in the morning, so he decides to come to the Apple Store later on around lunch time. Alice is a smart and hard-working girl. On January 1st she gets up very early in the morning and arrives at the Apple Store before anyone else does. She buys out all the available iPads from the Apple Store. Later on around lunch time, Bob arrives at the Apple Store only to find that all the new iPads are gone. Bob also finds that outside the Apple Store Alice is offering the new iPad at a price of $1010 which is quite acceptable to Bob. So Bob gladly buys an iPad from Alice. In the terminology of quantitative trading, Alice is an arbitrageur and executed a sandwich arbitrage between Apple Store and Bob. Let us pause here and ask ourselves a few interesting questions: a. What value does Alice provide to the market? When Alice purchases the iPad from the Apple Store, she plays the role of a market taker, and later on when Alice sells the iPad to Bob, she plays the role of a market maker. Remember that one of the values that a market taker provides is price discovery. In this case, Alice helps the Apple Store discovering a better price tag for its iPad. One of the values that a market maker provides is bridging the time gap between a potential buyer and a potential seller. In this case, Alice helps Bob staying lazy and not having to get up early. b. What risk does Alice assume? One of the obvious risks that Alice has to assume is the inventory risk. If no one is willing to buy the iPad at the price of $1010 at which Alice offers and the iPad’s price falls down to below $1000 at which Alice buys it, Alice is at a loss.

Now let us see how we could possibly apply the same techniques to trading on CEXs. As an Alice, we have to spot an opportunity on the market to quickly buy (or sell) an instrument at a reasonably good price as a market taker. And we have to achieve this before anyone else does (at least before most people realize it). Next we have to quickly advertise our inventory on the market for sale (or for purchase) at a reasonably good price as a market maker. The difference in the prices has to at least cover our transaction cost. So how does this type of arbitrage (let’s call it sandwich arbitrage) differentiate itself from the type of arbitrage that we analyzed in our previous article entitled “Atomic Arbitrage: A Quantitative Study” (let’s call it “standard arbitrage”)? a. Sandwich arbitrage’s execution sequence is taker-maker while standard arbitrage’s execution sequence is maker-taker. Because maker order’s execution guarantee is much lower compared to taker order, sandwich arbitrage assumes a significantly higher inventory risk compared to standard arbitrage. b. Sandwich arbitrage requires both front-running and back-running while standard arbitrage only requires front-running. This means that sandwich arbitrage needs an even faster execution speed compared to standard arbitrage. c. Sandwich arbitrage does not occupy any capital until the arbitrage operation is performed while standard arbitrage occupies 100% of the capital due to its open maker orders. Therefore sandwich arbitrage has much better capital scalability compared to standard arbitrage. d. Sandwich arbitrage completely unwinds all positions after the arbitrage is done while standard arbitrage requires a separate position-unwinding operation after the arbitrage is done.

Last but not least, let us examine a real world example taken from the trading battlefield around UTC time 2022–10–31T19:29:55Z when a sandwich arbitrage was successfully performed by our trading system on FTX’s DOGE/USD. As an exercise for the reader, use the technique outlined in our previous article entitled “Atomic Arbitrage: A Quantitative Study” to find out the footprint of this trade from the public trade records.

[2022-10-31T19:29:55.071772681Z] side: BUY, price: 0.125115, quantity: 6339.0, isMaker: 0[2022-10-31T19:29:55.169075653Z] side: SELL, price: 0.125195, quantity: 6339.0, isMaker: 1

As an Alice, at 2022–10–31T19:29:55.071772681Z, we bought 6339 DOGE from the Apple Store at a price of $0.125115 as a market taker. Then ~98 milliseconds later we sold 6339 DOGE to Bob at a price of $0.125195 as a market maker. We don’t have the luxury to colocate our trading servers to the exchange’s servers or use any VIP-only private endpoints to gain an edge. Our success depends on the super-performant library (https://github.com/crypto-chassis/ccapi) that we have handcrafted with C++. Our codebase for sandwich arbitrage strategy on CEXs is still in its nascency and a substantial amount of future work needs to be done. Before concluding this article, we want to highlight its inventory risk that we mentioned above using another real world example again on FTX’s DOGE/USD:

[2022-11-02T05:04:27.739536012Z] side: SELL, price: 0.14084, quantity: 5639.0, isMaker: 0[2022-11-02T05:04:30.219040212Z] side: BUY, price: 0.141005, quantity: 268.0, isMaker: 1[2022-11-02T05:04:30.234336083Z] side: BUY, price: 0.141005, quantity: 5371.0, isMaker: 1

This time as an Alice, our anticipation turned out to be incorrect. Our maker order was filled ~2.5 seconds later than our taker order. The time was long enough for a volatile market like DOGE to drift to anywhere and inflict a loss on us.

If you are interested in our work or collaborating with us, join us on Discord: https://discord.gg/b5EKcp9s8T and find us on Github: https://github.com/crypto-chassis/ccapi 🎉. We specialize in market data collection, high speed trading system, infrastructure optimization, and proprietary market making.

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

--

--