CryptoCMD CryptoCMD

Arbitrage Bots, Gas Spikes and the Self-Liquidation Trap

Your arbitrage bot's biggest threat in a market spike is usually its own leverage, starved of gas while it fights other bots for the same trade.

Sofia Marek · · 10 min read
Arbitrage Bots, Gas Spikes and the Self-Liquidation Trap
Photo: Cafer SEVİNÇ / Pexels

Key takeaways

  • →Arbitrage profits shrink fastest in exactly the moments bots most want to trade: volatility drives up both competition and gas costs.
  • →Failed on-chain transactions still cost gas, so a bot that loses several races in a row can drain its own reserves.
  • →Self-liquidation usually happens because a defensive transaction (repay or top up) couldn't land in time. The arbitrage loss itself is rarely the cause.
  • →Keep a separate gas reserve, give defensive transactions priority over profit-seeking ones, and halt trading at a health-factor floor well above 1.0.
  • →Price every opportunity net of gas, priority bids and the realistic chance of losing the race.

Here's how most leveraged arbitrage bots die. Not from mispricing a trade. The market lurches, gas costs explode, and the one transaction that would've saved the bot sits unconfirmed while a liquidator's goes through first. This guide walks through how that happens, why on-chain latency makes it worse, and how to build guardrails so your bot stops before it turns into someone else's profit.

What an arbitrage agent actually does

Arbitrage is simple: buy an asset where it's cheap, sell it where it's expensive, at nearly the same moment. On-chain, the gaps usually sit between two decentralized exchanges, between a DEX and a centralized exchange, or between a lending protocol's oracle price and the market price.

An autonomous agent automates the whole loop. It watches prices, spots a gap, works out whether the gap beats the cost of closing it, builds a transaction and submits it. Some agents run purely atomic trades: buy and sell inside one transaction, so either both legs succeed or the whole thing reverts. Others hold inventory or borrowed funds so they can move faster or grab gaps that can't be closed atomically.

That second group carries liquidation risk. If your bot borrows against collateral to fund its inventory, it has a debt position. Debt positions get liquidated. Simple as that.

Where on-chain latency comes from

Off-chain trading firms count latency in microseconds. On-chain, the clock is the block. Your transaction doesn't execute when you send it. It executes when a block producer includes it, in whatever order they pick.

So latency on-chain comes in layers:

  • Detection latency: how fast your bot sees a price change, whether from a new block, a pending transaction in the public mempool, or an off-chain price feed.
  • Decision latency: how long it takes to simulate the trade and decide.
  • Inclusion latency: how long until a block producer puts your transaction in a block. This one dominates, and you mostly can't fix it with code.
  • Ordering: even inside the same block, position matters. The first transaction to hit a price gap closes it. Everyone behind it gets a worse price or a revert.

Fast detection helps. But on chains where block producers sort transactions by how much they pay, ordering is bought. Speed alone doesn't win.

MEV competition: you're never alone

Autonomous Arbitrage Agents: On-Chain Latency and Liquidation Risk
Photo: Rafael Minguet Delgado / Pexels

MEV means maximal extractable value: the profit available to whoever controls transaction ordering, or pays the person who does. Arbitrage is the most common form. A price gap between two pools is visible to every bot watching the chain, and they all want it.

On a chain with a public mempool and fee-based ordering, that becomes an auction. Each bot bids a higher priority fee to get ahead. The winner captures the gap. The losers' transactions either revert or execute against a price that's already moved. Revert or not, they paid for the gas they used.

Many ecosystems now route the fight through private channels. Bots send bundles straight to block builders, sometimes with a conditional payment that's only made if the bundle lands in the right spot. That cuts the cost of losing, because a bundle that isn't included typically costs nothing. But the competition doesn't vanish. It just moves the bidding where you can't see it. And what's left for you after you pay the builder can be a small slice of the gross gap.

Rule of thumb: the more obvious and profitable the opportunity, the more of its value goes to whoever orders the block.

Why gas spikes hit when you most need speed

Sudden market moves create the biggest price gaps. They also create the biggest gas spikes. Liquidation bots, arbitrage bots, panicked traders and people rushing to repay loans all hit the chain at once.

On networks with an EIP-1559-style fee market, the base fee rises when blocks run fuller than the target. On Ethereum mainnet, it can rise by up to 12.5% per block. Ten full blocks in a row compounds to roughly 3.2 times the starting base fee, and that's before priority fees. Then every bidder piles a tip on top to jump the queue.

For an arbitrage bot, that's a cruel squeeze:

  • Opportunities get larger, so the bot wants to trade more.
  • Each attempt costs more, and your odds of winning any single race drop as more bots pile in.
  • Gas reserves drain faster than the bot's logic expects, especially if it was tuned during calm conditions.

And this is the very moment its collateral may be losing value.

How a bot liquidates itself

Lending protocols track each position with something like a health factor: collateral value multiplied by a liquidation threshold, divided by debt. Above 1.0, you're safe. At or below 1.0, anyone can repay part of your debt and seize your collateral at a discount. That discount is the liquidation bonus, and you foot the bill.

A self-liquidation usually runs like this:

  1. The market moves sharply against the bot's collateral.
  2. The same move creates arbitrage gaps, so the bot starts bidding aggressively.
  3. It loses several races. Each failed public transaction still burns gas.
  4. Its gas wallet runs low, or its fee settings are now far below what the chain demands.
  5. The health factor slides toward 1.0. The bot (or its operator) tries to repay debt or add collateral.
  6. That defensive transaction is underpriced or stuck behind the bot's own pending trades. Liquidation bots, well funded and bidding hard, get there first.

Look at what happened. The arbitrage strategy might have been right about every price. It still died, because it spent its scarcest resource, block space, on offense when it needed defense.

Oracle lag adds another twist. Lending protocols liquidate on their oracle price, not the live DEX price. If the oracle updates in a big jump, your health factor can fall from comfortable to liquidatable in one update. No smooth slide, no time to react.

A worked example (hypothetical numbers)

Every figure below is made up for illustration.

A bot deposits $20,000 of a volatile token as collateral and borrows $12,000 in stablecoins to hold as arbitrage inventory. The protocol's liquidation threshold is 80%.

ScenarioCollateral valueHealth factor
Starting point$20,00020,000 × 0.8 ÷ 12,000 = 1.33
Token falls 15%$17,00013,600 ÷ 12,000 = 1.13
Token falls 25%$15,00012,000 ÷ 12,000 = 1.00 (liquidatable)

A 25% drop is all it takes. In a sharp spike, that can happen within minutes.

Now add the arbitrage. During the drop, the bot spots a gap worth $300 gross. In calm markets, the transaction would cost about $5 in gas. Mid-spike, the bot bids a $250 priority fee to compete. It loses three races in a row; each reverted public transaction costs it $40 in gas. On the fourth try, it wins.

  • Gross profit: $300
  • Priority fee on the winning trade: $250
  • Three failed attempts: $120
  • Net: a $70 loss

Meanwhile its gas wallet, which held $200, is nearly empty. The token hits the 25% drop. A liquidator repays $6,000 of the bot's debt (half, a common cap) and takes $6,000 worth of collateral plus a 5% bonus: $6,300. So the bot eats $300 in liquidation bonus on top of the $70 arbitrage loss, plus whatever the forced sale costs in price impact.

The bot chased a $300 opportunity and paid more than $300 for it. Ouch.

Step-by-step: building guardrails that actually hold

  1. Split your wallets. Keep a dedicated gas reserve the trading logic can't touch, used only for defensive transactions like repaying debt or adding collateral. Size it for a worst-case spike, not an average day.
  2. Calculate your liquidation price before you trade. Work out exactly what collateral price makes your health factor 1.0. Write it down. If a 20% move gets you there, you're running too hot for a volatile asset.
  3. Set a hard health-factor floor well above 1.0. Something like 1.5 for volatile collateral. When the bot crosses it, all new arbitrage stops and the bot's only job becomes reducing debt.
  4. Cap gas spend per opportunity as a share of expected profit. Factor in your realistic win rate. Win one race in four? Your expected cost is the winning bid plus three losing attempts. Skip anything that doesn't clear that with margin.
  5. Prefer submission methods where losing is free. Private bundles or relays that don't include failed attempts stop you paying for races you lose. Where you must use the public mempool, add tight slippage checks so a losing trade reverts early and cheaply.
  6. Simulate against the latest state every time. Run each transaction against the newest block before sending. If the gap has closed, don't send.
  7. Give defense priority over offense. Defensive transactions should carry higher fee caps than any arbitrage trade and should replace or cancel pending trades that could block them. Consider keeping repay logic ready so it fires automatically.
  8. Add circuit breakers. Pause trading after a set number of consecutive reverts, when gas exceeds a threshold, or when oracle and DEX prices diverge beyond a set percentage.
  9. Backtest on ugly history. Replay the most volatile blocks you can find, then run live with small size before scaling up.
  10. Keep a manual kill switch. Some way to stop the bot and unwind the position by hand, from a separate device, with its own gas.

Common mistakes

  • Tuning in calm markets. Fee settings and win rates measured on a quiet day mean nothing during a spike.
  • Ignoring the cost of losing. Count only the gas on winning trades and you've hidden the real expense. Reverts add up fast.
  • One wallet for everything. If trading and defense share a balance, trading spends the defense money first.
  • Nonce blocking. On account-based chains, transactions from one address execute in order. A stuck, underpriced trade can block your repay transaction behind it.
  • Trusting the DEX price for risk. Liquidations follow the oracle, which can lag and then jump.
  • Treating flash-loan success as proof of safety. An atomic strategy can't be liquidated, but bolt on a leveraged inventory leg and the risk changes completely.
  • Running someone else's bot blind. If you can't explain its liquidation price and gas logic, you're not running a strategy. You're placing a bet you can't see.

FAQ

Are flash-loan arbitrage bots safe from liquidation?

A pure flash-loan arbitrage borrows and repays inside one transaction, so there's no open debt to liquidate. If it fails, it reverts. The risk there is gas: a public transaction that reverts still costs you. Liquidation risk only shows up once the bot holds a debt position between blocks.

Do layer-2 networks or fast chains solve this?

They change the numbers, not the shape of the problem. Cheaper gas makes losing races less painful, and faster blocks shrink inclusion latency. But competition moves to whatever the chain uses for ordering, whether that's sequencer priority, fees or raw speed, and congestion during spikes still happens. Liquidations on fast chains can also unfold faster than you can react manually.

Is running an arbitrage bot closer to trading or gambling?

Depends on whether you can measure your edge. A bot with known costs, a real win rate and hard risk limits is a trading system. A bot you switched on because a dashboard showed big returns, with leverage you haven't stress-tested, behaves a lot more like a bet. And the house is whoever orders the blocks.

So before any bot goes live, skip the question of how much it can make on a good day. Ask what happens to its last transaction on the worst day, and whether that transaction can still get into a block.

Keep learning