10,000-word article: The journey of building a CEX-DEX arbitrage bot from 0 to 1

This article is approximately 6378 words,and reading the entire article takes about 8 minutes
Consciously choose one thing and focus on it until the facts driving the decision change.

Original author: Daniel McKinnon

Original translation: @0xKaKa03

1. The opportunity

During the bull run of 2021, a few friends and I managed to corner the atomic arbitrage market on the Avalanche blockchain. Unfortunately, our luck eventually ran out, and I called it a day.

But one thing that always stuck with me was this: At the height of our profits, one of the most successful crypto traders of all time told me, “What the hell are you doing atomic arbitrage for? The competition is crazy, there’s more money to be made in statistical arbitrage.”

He is certainly right about the first point. Because atomic arbitrage is done entirely on the blockchain and can be performed using borrowed funds (flash loans), every 14-year-old chess prodigy on the internet is a potential competitor. However, other than observing his massive success, I have never been able to verify the second point myself.

One day out of boredom and curiosity, I wrote a script to pull the AVAX/USDT price from DEXTraderJoe, which dominates the Avalanche blockchain, and CEX Binance, which once accounted for more than 50% of the trading volume, and generated the following chart.

10,000-word article: The journey of building a CEX-DEX arbitrage bot from 0 to 1

“Nothing,” I thought, “The opportunity must have been arbitraged away.”

But wait. As an atomic trader, I was used to seeing hundreds of dollars of risk-free trades popping up like an Amazon volcano. The penny spreads I observed between CEXs and DEXs didn’t even register with me. However, my partner, a real-life high-frequency trader, used to making millions of dollars in returns from sub-basis point opportunities, started salivating.

Statistical arbitrage trading is all about trying to earn pips. It’s a volume game. If you see a 25 pip spread and know that it costs 23 pips to execute the trade, you’re a winner. Multiply that 2 pips by $10 million in volume and suddenly you have a robot that makes $2,000 a day. Simple, right?

If you’ve ever wondered why most transactions on the blockchain seem to consist of random amounts of money being exchanged without anyone consciously making such trades, statistical arbitrage (statarb) is the reason. No human speculator in the world woke up one day and decided that he would rather hold 600.51 JOE than 253.51 USDT.e (note that the dollar value here reflects the price at the time of my screenshot, not the price at the time of the trade execution; this trader did not lose $7 on this exchange). Instead, a trade on another exchange slightly tipped the JOE/USDT price equilibrium, and the bot realized that it could make a $0.05 profit.

10,000-word article: The journey of building a CEX-DEX arbitrage bot from 0 to 1

The experiment

In trading, you can never really be sure that you will capture the alpha you see. Spotting arbitrage opportunities is often the easiest part.

After spending more time analyzing the CEX/DEX spread, we started tracking about half a dozen bots that seemed to be profiting from “our” trades, without understanding how sophisticated their operations were. However, we thought we had a chance for a few reasons:

1. All of their transactions are top-of-block transactions. If you remember from my previous post, I have lost my validator node. Competing for atomic arbitrage on Avalanche requires a network of hundreds of validators, but top-of-block transactions usually do not, so this is very important.

2. The largest robots only trade top trading pairs, such as AVAX/USDT, WETH.e/USDT, BTC.b/USDT, etc. Competition seems to be weaker for tokens listed on centralized exchanges (CEX) but with smaller trading volumes, such as JOE/USDT and STG/USDT. [Translators note: The tail market is more suitable for novices]

In order to verify our hypothesis as quickly as possible, we wrote a few hundred lines of Python code to build a minimal statistical arbitrage robot. Our code contains five basic functions, distributed in five processes:

1. A CEX listener that subscribes to Binances real-time bookTicker websocket data stream, which provides the best bid and ask prices and their quantities for each update

2. A DEX listener that processes block top logs and records Uniswap V2-like pool prices

3, an opportunity finder, compares CEX prices to DEX prices and calculates whether there is a profitable trade after deducting fees. To determine the order size, we simply assume that all available liquidity on the CEX will be taken at the best price. In a sense, this assumption is the same as the no-arbitrage condition often assumed in trading. The mathematical formula for this first version is very simple:

_if abs(DEX price-CEX price)> 30 bps (DEX fee)+ 10 bps (CEX fee)+ gas (initially hardcodedto_ 25% of profits)>trade_

4. A decentralized exchange order executor receives the trade parameters, packages them into an order, and sends it to one of the existing routers.

5 , a centralized exchange order executor that handles the same transactions on the Binance side.

Amazingly, we started making money right away, netting about $200 on the first day. Not bad. We only had 1-2 competitors at the time, and they were bidding less than 25% of the profit on gas. Proof of concept complete, we were ready to scale.

# How to lose money as a stat arbooooor

Unfortunately, our competitors soon took notice and our bottom line turned negative.

Statistical arbitrage profit is calculated by the following simple formula: Profit = Selling asset price*-Selling asset quantity + Buying asset price*Buying asset quantity-Gas token price*Gas token quantity

At the risk of stating the obvious, a trade will only be executed if the expected profit value is greater than 0. However, the assumptions underlying the profit calculation do not actually match the reality of execution. There are four different ways you can lose money when trading CEX/DEX arbitrage:

  • Slippage on the CEX side. This happens when the price is outdated before it reaches your bot, or a competitor initiates a trade first and grabs the needed liquidity first.

  • Slippage on the DEX side. A competitor’s trade gets executed before yours (either in the same block or one or more blocks earlier) and pushes the price in an unfavorable direction.

  • Too high a gas bid. You accidentally paid more gas than the transaction was worth. This could be caused by a malicious PGA, an incorrect profit calculation, or a miscalculation of gas consumption.

  • DEX-side rollback. A competitor’s trade is executed before yours: causing the price to slip beyond your acceptable range, which in turn causes your trade to roll back.

While the first three scenarios will shave a few bps off your bottom line, the last one can really hurt. A trade reversal on the DEX side not only means you waste some gas (remember, margins on these trades are usually very slim), it also means you need to reverse the trade on the CEX side to avoid an inventory imbalance. This results in double fees on the CEX side (~20 bps), plus any price shock from reversing the trade when the price is almost always against you (~20 bps). If your goal is to make an average of 2 bps of profit per trade, this means that a single DEX reversal will wipe out the gains of 20 successful trades on average, but extreme cases can be much worse. Its called picking up nickels in front of a steam roller.

Given this risk, the obvious remedy is to bid more aggressively for gas to ensure that rollbacks never occur on the DEX side (note: on EVM blockchains like Avalanche, transactions are typically ordered by gas). This is exactly what our competitors do.

We started out bidding 25% of our expected profit as gas fees: this was above the unstable equilibrium on the chain. After a day or two, our competitors noticed and raised their bids, squeezing us out of the blocks. We went from winning every trade to losing every trade.

Note: There is no Nash equilibrium for the gas auction of statistical arbitrage, which means that the expected return of these transactions is negative.

If the previous section wasnt clear enough, our competitors bid about 20% of their profits on gas fees to ensure their transactions are listed at the top of the block. We raised our bid and they responded. What happens if we respond again? We will almost certainly regain market share at the expense of our profit margins. But then what will our competitors do?

At first glance, the equilibrium profit from these trades is zero, since gas bids should be driven up to the value of the arbitrage. However, the situation is actually worse than that. Gas bids for statistical arbitrage (and atomic arbitrage before the introduction of Flashbots) are similar to the classic dollar auction thought experiment, in which rational participants would pay more than face value for a dollar bill. This is because second place (third, fourth, and so on) is actually paying for the privilege of losing the auction.

Spoiler: Statistical arbitrage is actually quite profitable, no one is bidding up gas fees to the point where they are more profitable than trading, and we haven’t raised the base gas price significantly. We don’t want to signal a price war to our competitors, so we implemented a Priority Gas Auction (PGA) algorithm that starts with a low gas bid and gradually raises the bid as competitors appear in the memory pool.

I dont really understand why this mitigation works in statistical arbitrage but not in atomic arbitrage or pinch trading, where the tips to the flashbots to win the obvious trades have skyrocketed to almost 100% of the profit (and the searcher gets nothing). If anyone knows the answer to this question, please contact me.

Last edit: zKSTONKs proposed the following pseudoproof that partially answers this question. Please get in touch if you would like to continue the discussion.

[Translators note: In one sentence, the explanation is that cex-dex arbitrage is more risky, and in order to increase the overall profit expectation, the gas strategy of arbitrageurs is more conservative. However, because dex atomic arbitrage has a lower risk, even if the gas is greatly increased, the overall expected profit is still positive (at least it is difficult to lose money), so a more aggressive gas strategy will be adopted (and then fall into a vicious circle)]

A simple answer is that the variance (risk) of atomic arbitrage is lower than statistical arbitrage, so the required return on investment is lower for atomic arbitrage. This assumes a risk-averse utility function, which is a common assumption in financial modeling.

Without loss of generality, we can ignore gas fees. We use the previous profit formula: profit=p_a*q_a-p_b* 9_b. Previously, the quantity was a random variable (because transactions may be rolled back). For simplicity, we assume that the quantity is constant and only focus on the price.

We model prices as a Geometric Brownian Motion (GBM). We send a transaction at time 0 and the transaction is executed at time t. We use p_t~i to represent the (random variable) price of asset i at time t. sigma_i is a constant representing volatility.

We can now express our profit as profit=p_t^a*q_a-p_t^b*q_b. For simplicity, we assume that p^b=1, for example asset b is USD, so the price is always 1. Since the price of asset b is constant, the volatility of b, sigma_b, is 0.

So our profit formula is now `profit=p_t^a*q_a-9 _b

Now, using the formula for the Geometric Brownian Motion (GBM) expectation, we have E[profit]=p_ 0 ^a*q_a-q_b. Our profit variance is `Var(profit)=(p_ 0 ^a)^ 2*(-1+exp(t*(sigma_a)^ 2))*(q_ a)^ 2 `.

Note that if we do atomic arbitrage, then sigma_a-sigma_b = 0, so the variance of the profit is zero.

However, if the arbitrage is not atomic, then the variance is positive.

Lets compare an atomic arbitrage opportunity and a centralized exchange-decentralized exchange (cex-dex) arbitrage opportunity, which have the same expected profit (Elprofit]. Since the variance of atomic arbitrage is zero, while the variance of cex-dex arbitrage is positive, the log utility of cex-dex trading is lower. Therefore, we are willing to pay less to perform cex-dex arbitrage, so our gas bid should be lower than atomic arbitrage. -

This proof shows that for CEX/DEX arbitrage we can expect gas bids to be lower than for atomic arbitrage, but it does not establish an upper limit on the gas bid for atomic arbitrage. In the world of Flashbots, the upper limit is indeed the value of the arbitrage, but before Flashbots, the cost of failed trades was borne by the losing party, and gas bids could exceed the value of the trade, just as in CEX/DEX arbitrage. Lets put our heads together and rigorously find out why gas bids on CEX/DEX are so much lower than their possible upper limit.

3. Priority Gas Auction (PGA)

I believe all PGA algorithms are essentially the same.

  • Set initial gas bid

  • Listen to the memory pool for transactions that appear to be performing the same arbitrage

  • Resend the transaction with a higher gas fee

  • Repeat this process until the block is mined

On Avalanche, depending on how well your system is optimized to monitor the mempool and resubmit transactions, you can expect single-digit resubmit times per block.

While the algorithm is simple, it significantly increases the complexity of the arbitrage bot and requires upgrading to a distributed system. The minimum viable product (MVP) described above runs on a few cores of a single machine. However, since transactions bounce around the memory pool randomly around the world, simply waiting for a transaction with a higher gas fee to drift to your machine and then leisurely resubmitting the transaction to the memory pool is ineffective.

Instead, a network of optimized nodes is needed to poll for new transactions and resubmit arbitrage transactions to the block proposer as soon as the maximum allowed limit is reached. In addition, new subroutines need to be written to track previous transactions and resubmissions in the node network. For a more detailed description of how this works, see my previous post

The last ingredient needed for a barely competitive statistical arbitrage bot is an algorithm for calculating order sizes to maximize profits. If we assume that we will never place orders beyond the top depth of the centralized exchange (CEX) order book, and that we trade Uni V2 style decentralized exchange (DEX) pools as we did initially, we can derive a nice analytical solution (the derivation is omitted because both assumptions are very unrealistic today)

10,000-word article: The journey of building a CEX-DEX arbitrage bot from 0 to 1

This calculation becomes even more complicated when considering different DEX trading venues and multiple levels of CEX order books. For those of us who like mathematics, we have to give up the simple analytical solution and use a binary search algorithm (also known as a numerical method, including the trisection method, Newtons method, golden section search, etc.). [Translators note: When designing multiple CEX multi-layer orderbooks and V3-like protocols and various weird protocols, the analytical solution becomes almost impossible]

Go son and seek your volume

Once we incorporated PGA and order sizing into our bot, and spent some time optimizing our validator network and DEX strategy we started winning arbitrage opportunities on JOE and STG on a consistent basis again. This was a nice proof of concept, but the volume was nowhere near enough to generate a big enough profit to justify the work.

As mentioned in the introduction, we built a system that earned a few basis points per trade, but total volume on Avalanche at the time was about $10 million per day, which meant that even if we had 100% market share, profits were limited to between $2,000 and $20,000 per day. In reality, since we were limited to trading STG and JOE, the profit numbers were much smaller. To make all the effort worthwhile we needed to start taking more trades.

The crown goes to those with the lowest CeXfees

We naively added AVAX, WETH.e, and BTC.b to the bots configuration to see if we could replicate our success with JOE and STG. It didnt work at all. Every single one of our trades lagged behind our competitors (either lower in the correct block, or in a later block).

Since the trading volume in these markets is much larger, we have moved from competing with amateurs to competing with big players. A typical JOE/USDT transaction is usually in the mid-hundreds to low thousands of notional values, with a spread of about tens of basis points (gross profit), while AVAX/USDT transactions have notional values of tens or even hundreds of thousands of dollars from time to time.

This means:

1. Inventory demand has increased significantly. Tens of thousands of stocks can be used to trade JOE and STG, but these quantities are not enough for AVAX.

2. The cost of rolling back has increased significantly. The net cost of rolling back a $100,000 AVAX/USDT trade is about $400. This cost really starts to sting when the total daily profit available is only about an order of magnitude higher.

3. The volume of transactions increased significantly. While this may sound obvious, it is the subject of this section.

Upon inspection, it was clear that our competitors were simply placing orders earlier than us. Regular Binance accounts pay 10 bps in fees for both providing and acquiring liquidity, while VIP 9 accounts, which trade over $4 billion per month, only pay 1.8 bps in acquisition fees and 0.9 bps in providing fees. There are also better fee tiers that offer market making rebates for those who contribute more than 0.15% of Binances total trading volume.

A 5x reduction in fees not only significantly increases profits (remember, our goal is to earn 2 basis points per trade - just by moving up the fee tier, this number increases to 10 basis points), it also allows trades to be executed earlier. Spreads dont appear out of thin air, but gradually become larger. If a bot using a basic Binance account needs a 30 basis point spread to make a profit, another bot with a better fee tier will almost certainly be the first to arbitrage at 25 basis points. Translators note: If it comes to arbitrage on cex, high-level VIPs and high rebates are important, which can reduce fees and some will increase your api rate, but these need to be smashed from trading volume]

6. Note: Market Makers and Takers

Looking at Binances fee tiers, you might be inclined to provide liquidity on the CEX side rather than take orders. This not only saves on fees, but also avoids cross spreads, and in theory you can get a better price if you assume that the price will fluctuate a bit and someone will fill your buy/sell order shortly after you place the order.

This is a legitimate temptation and I suspect many successful traders run a market making statistical arbitrage strategy. However, this approach requires a more complex trading system as you need to be able to track every pending limit order, close the position if the price moves in the opposite direction and manage inventory more carefully.

We tried market making strategies early in this operation and when I first started CEX arbitrage. My overall conclusion is that market making orders will almost always be filled, but if you don’t put a lot of effort into order management, the risk of rapid price changes will offset the benefits of better prices and lower fees. Based on experience, I have found that a single limit order that is not filled can wipe out weeks of trading profits. In addition, market making strategies are actually pushing the limits of arbitrage because holding these positions even for a short period of time will increase the higher beta risk exposure.

7. Inventory, futures, and leverage

We have mentioned inventory several times without clearly defining it. Unlike atomic trades, to do statistical arbitrage you must hold a (significant) balance of all the currencies you wish to trade on each trading venue. If the AVAX/USDT price on the DEX is lower than on the CEX, you buy AVAX on the DEX with USDT and do the opposite on the CEX. The no-arbitrage condition guarantees that mean reversion will let you reverse your trades and rebalance your inventory, but there is no way to predict how long this will take.

In reality, when markets are volatile, the capital required to continue trading until mean reversion occurs can be so large (tens of millions of dollars) that you can choose one of two approaches:

1. Pause trading when inventory is exhausted. In the above example, we will eventually run out of USDT on the DEX and AVAX on the CEX. At some point, the arbitrage opportunity will reverse and trading will bring our inventory back into balance. This approach is conservative, but will miss out on a lot of profits because the most profitable periods are often the most irrational stages of the market and arbitrage opportunities will often continue to run in the same direction.

2. Rebalance. In the above example, we will transfer half of the AVAX on the DEX to the CEX, and at the same time transfer an equal amount of USDT from the CEX to the DEX. This will reset our inventory, but it also brings some problems. When will the rebalance be performed? What if the market price changes during the token transfer process? How to deal with cross-chain tokens? How to deal with equivalent tokens on CEX and DEX, such as BUSD and USDC

Translators note: That is, equal price return and back and forth

The first option is not really viable if you want to utilize your inventory efficiently. You either give up most of your profits or end up with very low utilization. Remember, you can get a risk-free 5% yield right now (1.5bps per day), so you need to get significantly higher returns than that through risky strategies like crypto statistical arbitrage (holding crypto assets, counterparty risk, opportunity costs, etc.). To simplify the math, this means you need to turn over your inventory at least once a day for it to be valuable. With rebalancing, this is easily achieved (we often turn over ~10x per day), but if not, most of your inventory will sit idle most of the time, waiting for a big move, at which point you might as well be investing in Treasuries.

The second option adds a ton of complexity. Our originally simple MVP arbitrage bot now has a network of nodes resubmitting trades, various calculations to check size and profitability, an analytics module to track profits, and a rebalancing module to monitor positions and move funds back and forth.

You might lump this section together with the previous one and ask why even trade spot at all. Futures offer lower fees, implied leverage (less inventory requirements), deeper liquidity, tighter spreads, and (generally) better price discovery. These are all true, but inventory management is made more difficult by the fact that futures cannot be easily exchanged for spot products to enable inventory swaps. We never really got over this, but most statistical arbitrage teams do trade futures. If you are one of those teams and would like to share how you deal with this, please contact me, I’d be interested.

8. Some side notes

The following are some of my scattered thoughts on a few topics I would like to discuss, some of which we have tried or experienced, and some of which are only in our long-term planning.

## Aside: why not just trade one side

If it’s not obvious yet, our bot has now become quite complex. What started out as a simple Python script to perform simple trades has now grown into a very complex system. Could it be simplified by only trading on the DEX side? About 80% of the time price discovery originates on Binance.

Some teams do take this approach and avoid a lot of the complexity of centralized exchanges (CEX) and inventory management, but without bilateral transactions, its no longer true arbitrage and you start taking on price risk. I prefer not to be exposed to cryptocurrency price risk, but if you are comfortable with it, definitely go this route.

By the way, there is a great interview with Kvle Davies of 3AC about how they gradually expanded what they thought was an arbitrage window. At first, they started with atomic trades. Next, they used the GBTC premium. Finally, they bought discounted token presales with lock-ups, which was not really an arbitrage at all, but more of a random directional bet. The last two arbitrages got them blown up. You can use your own judgment to use this information.

There isn’t much to do on the CEX side, other than getting the best fee tier and placing your bot next to a CEX server room (like Binance’s AWS Tokyo node). Yes, you’ll run into issues like receiving outdated WebSocket messages and needing to build models to figure out which ones are worth trading, but that’s relatively straightforward compared to the challenges on the DEX side. Translator’s Note: From what I’ve heard on Twitter recently, CEXs are actually a lot of trouble.

9. Aside: bridged tokens are a PlTA By the way: cross-chain tokens are really troublesome

When I talked about finding more volume earlier, I mentioned starting to trade WETH.e/USDT and BTC.b/USDT, rather than ETH/USDT and BTC/USDT, because the latter don’t actually exist on the Avalanche blockchain. There are now dozens of blockchains with reasonable decentralized exchange (DEX) volume, and probably hundreds of different cross-chain token versions whose prices need to be balanced through arbitrage.

However, these arbitrages are often annoying, difficult to perform, and risky due to rebalancing and inventory management issues. If you trade BTC.b/USDC on a DEX and BTC/BUSD on a CEX, and one side runs out of inventory, you need to keep track of the costs and risks of bridging BTC.b to the Bitcoin blockchain and transferring BTC to Binance, and the same is true for USDC/BUSD, whose automatic conversion was suspended shortly after we started trading. In addition to taking on the tail risk of the bridge being attacked, this complexity has made us mostly choose to trade the bridge token without rebalancing, but there are still opportunities for those who dare to try.

Translators note: There are many issues to pay attention to regarding cross-chain bridges, such as cross-chain time, cross-chain quota, how to find a bridge, money lost across the bridge, etc. It is a very complex project (complexity also means less competition)

Aside: hedging and inventory management

The inventory management I have described so far is relatively basic: reversing failed DEX transactions, using stable and denominated trading instruments, and accepting price fluctuations. But by optimizing these links, despite the significant increase in complexity, profits can be significantly improved.

As mentioned before, reversing a failed DEX trade is expensive. If you have a view on the correct inventory to hold in the future, you can avoid the penalty of a failed DEX and simply hold the wrong inventory until it is cheaper to dispose or the trade naturally reverses. While we have never done this, I would imagine that for large traders who may be moving millions of dollars per swap, a very sophisticated inventory management system would be necessary, as simply reversing a trade would be unacceptable.

Trading instruments denominated in stablecoins make inventory management easier: A balanced portfolio should maintain 50% tokens and 50% stablecoins on centralized exchanges (CEX) and decentralized exchanges (DEX). Trading instruments denominated in cryptocurrencies make tracking more difficult, but also bring more opportunities. Once this approach is adopted, the code responsible for inventory management and rebalancing will almost certainly be more complex than the code responsible for trading, and will most likely evolve into a very complex convex optimization program.

Finally, it is worth mentioning hedging. We do not hedge for two reasons:

1. We are willing to bear the loss of the inventory we hold

2. Statistical arbitrage trading is inherently self-hedging, meaning that inventory demand will increase as cryptocurrency prices rise, and vice versa

However, larger traders, some of whom hold hundreds of millions of dollars in notional inventory, will almost certainly need to hedge. Adjusting the hedge for each instrument after each trade may not be feasible, but it is possible to separate the coins into baskets and hedge the overall beta exposure at the end of each trading day. In addition, funding rates for tokens tend to be negative on average, so hedging can bring small returns to the portfolio, but at the cost of added complexity and the risk that additional funding may be needed if the price of cryptocurrencies rises sharply.

Translators note: Why does a negative rate bring a small return? Is this a typo or I dont understand it

Aside: you will be constantly dealing with random crypto problems trading stat arb

Trading Atomic Arbitrage is pretty good. Aside from the possibility of losing money in the gas auction for arbitrage opportunities at the top of the block (limited by the gas value in your EOA) or encountering attacks like Salmonella, there is basically no chance of losing money. We left the Atomic Arbitrage bot running for a few months after we had mentally emptied it, and although the returns were not large, we knew it would not lose money and would occasionally pick up a good trade.

Statistical arbitrage doesn’t work like that. Every week something happens in the crypto space. Here are a few examples from our run:

1. SVB collapses, causing USDC to lose its anchor

2. Binance stops exchanging BUSD for USDC at a 1:1 ratio

3. The STG team tried to switch to a new contract, but withdrew the decision a few weeks later Translators note: How to avoid the problems caused by the contract change? Do you need to pay attention to various announcements?

4. Eran suspends withdrawals [Translators note: Get the exchange opening and closing information as soon as possible]

5. GMX oracle was manipulated and quoted wrong prices [Translator’s note: sometimes aggregators also have wrong quotes]

Any of these events can cause you to lose a significant amount of stock if not detected early. From a pure risk management perspective, statistical arbitrage trading is a full-time job, while atomic trading is not. Instead of dealing with a single system (albeit quite complex) that essentially only accumulates profits, you are dealing with a group of systems, where a single failure in any one of them can wipe out weeks of profits in seconds.

12. Aside: stat arb profits are Pareto distributed (as in atomics)

Throughout this article, I have been talking about averages, but the distribution of trading profits is not. While earning 2 basis points per trade and trading $10 million a day consistently sounds good, trading volume varies from event to event. JOE may rise for three consecutive days, contributing 90% of the profits, and then be quiet for three months while trading activity shifts to other assets. Drilling down into those JOE trades, 90% of the trades may only have gained 1 basis point on a small scale, but a few captured 100 basis points on a notional amount of $10,000, resulting in a profit or loss for the day.

The lesson is that catching tail opportunities is very important. Arbitrage robots that only trade the main part will not make money. Be prepared to deal with strange trading venues, strange currencies, and special opportunities.

Aside: on the value of being first to a venue

Relatedly, new platforms often offer the best profit opportunities. The chart below shows the best price for AVAX/USDT on TraderJoe versus the best bid and ask on Dexalot, an on-chain limit order book launched on its own separate subnet. You can see that sometimes the bid and ask cross for minutes, allowing people to manually click arbitrage like with the intraday Ether Delta.

The fun doesn’t stop there. Dexalot offers market making rewards to liquidity providers, so it’s possible to earn tens of thousands of dollars in ALOT per month simply by quoting prices much wider than Binance and earning both the spread and the tokens.

10,000-word article: The journey of building a CEX-DEX arbitrage bot from 0 to 1

14. Aside: on RFQs

Several platforms, such as 1inch, Hashiflow, etc., provide off-chain quotes. The general structure is that licensed partners quote for multiple assets at the top of each block, and these quotes can be read by their AP (usually not on-chain), but the specifics vary. After a few weeks of researching multiple such price sources, I concluded that their quotes are always 1-2 basis points wider than the best CEX price. These are good trading venues for traders willing to pay that price for on-chain CEX quotes, but their liquidity providers are very professional and there doesnt seem to be much opportunity to arbitrage outdated quotes.

Aside: routing

In decentralized exchanges (DEXs), during periods of market volatility, the best prices for tokens are rarely obtained through their most direct trading pools. The following chart shows the synthetic best bid and ask prices for O obtained through the Q/USDT Trader Joe trading pool and the YieldYak (automatic router) API. You will notice that during this period, you can often get better prices through a path similar to Q>AVAX→>USDT.

The same situation exists on centralized exchanges (CEX), but price improvements tend to converge faster. The chart below shows the best bid price on Binance via a direct (d) or routed (r) path. You can see that at certain times, selling AXAX>{ETH, BTC}>USDT can make a few cents more than selling AVEX→>USD directly. Given the slim margins in statistical arbitrage trading, a few percentage points of difference gained by optimizing routing can make a big difference.

16. Comparative advantage and careers

This experience may be my final chapter in crypto. I’ve been trading crypto on and off for the past six years. The first trading bots I wrote were just a few hundred lines of crude Python code to profit from the huge price discrepancies between major tokens quoted on major exchanges. Finding these opportunities requires only a little intuition and a risk appetite. But the bar keeps getting higher. To stay competitive, our latest bots have made a lot of improvements to the validator software, built and evaluated graphs containing thousands of tokens, perform math to 18 decimal places, and have strong reliability and error catching capabilities, all written in highly optimized Rust code.

While it was fun to learn all of this, the core skills required to contribute to arbitrage bots today are far removed from my personal core competencies, which I consider to be at the intersection of AI and product management. Looking back, from a pure expected value perspective, I do think this crypto side hustle may have negatively impacted the compounding value of my main career (since this crypto journey began, I have worked as a product manager at Meta and Google focusing on voice and language, now known as AI), while not helping my bank account much.

That being said, I wouldnt do anything differently (well... maybe I would have sold all my crypto at the 2021 highs). Im pretty proud of what Ive accomplished in crypto, but the distraction has certainly taken its toll. Its been fun to refocus on my career as I wind down my activities here, while also seeing how far some of my peers have come while I was busy trying to scrape together pips.

The most important revelation and lesson Ive learned for myself is to consciously choose one thing and focus on it until the facts driving the decision change. In the near future, that one thing is building voice and language interfaces for AR glasses at Meta. Stay tuned for the future.

17. Thoughts on the future of crypto

I have been thinking a lot about crypto from a product perspective over the past few years. This was mostly for selfish reasons, as I thought it would be a very smart move to raise a round of funding in 2021 and go full-time if we could convert trading revenue into product revenue. However, despite a strong greed drive, I have not been able to figure out what kind of products I could build in the crypto space.

In my opinion, there are two areas where cryptocurrencies have strong product-market fit:

  • BTC store of value

  • DeFi Decentralized Finance (DeFi)

BTC as a store of value is now pretty Lindy, and I’m sure it won’t go away. However, there’s really nothing to be done. The BTC community might even go a step further and say: nothing should be done at all. Yes, ETFs have been launched, and now it’s easier for seniors to include them in their retirement portfolios, but I don’t see how product companies can innovate on BTC’s core value proposition.

DeFi is newer and a more obvious focus. There are tons of super smart people analyzing the details of every transaction and building new products to make swaps faster, cheaper, more secure, and so on. But beyond admiring these optimizations in the abstract, I’m not sure what problems these projects are actually solving. Uniswap, by far the most popular DeFi protocol, has just over 100,000 daily active users after years of operation. If 100,000 is the ceiling, is it reasonable and impactful to focus on building trading infrastructure that might only cover a small fraction of them?

You can see this lack of product-market fit (PMF) by randomly selecting specific problems that the average user is solving on any blockchain [etherscan.io/txs?block=1905...)

In the examples above, you see hundreds of arbitrages and swaps, a few transfers, but no games, NFTs, ledger writes, data transfers, or anything that is supposedly powered by a decentralized blockchain. Cryptocurrency may enable a new generation of consumer or enterprise products in the future, but I don’t see a clear path to that yet, so I’m holding off until I find one.

Original link

This article references multiple sources of information:https://x.com/0xKaKa03/thread/1944104168802988150,If reprinted, please indicate the source.

ODAILY reminds readers to establish correct monetary and investment concepts, rationally view blockchain, and effectively improve risk awareness; We can actively report and report any illegal or criminal clues discovered to relevant departments.

Recommended Reading
Editor’s Picks