Book a free call

How to Build a Crypto Arbitrage Trading Bot

A crypto arbitrage bot buys a coin cheap on one exchange and sells it higher on another. This guide covers the strategies, the parts you need, and the build steps.

Hertiv engineering teamReviewed by a senior engineer
8 min read
How to Build a Crypto Arbitrage Trading Bot
On this page

Short answer

A crypto arbitrage trading bot is software that watches prices for the same coin on two or more exchanges and trades automatically when the price gap is large enough to cover fees. It buys where the coin is cheaper and sells where it is dearer, then repeats the loop while the gap lasts.

What is a crypto arbitrage trading bot?

A crypto arbitrage trading bot is software that buys a coin on one exchange and sells the same coin on another exchange at a higher price, keeping the difference as profit. It watches order books on several exchanges at once and acts in seconds, far faster than a person checking prices by hand.

The gap it chases is usually small, often a fraction of a percent. The bot makes money by repeating the trade many times, not by one large win. That is why fees, speed and the size of each trade matter more than the size of the price gap on its own.

Strategy How it earns Main risk
Cross-exchange Buy low on one exchange, sell high on another Transfer time and withdrawal limits
Triangular Trade three pairs on one exchange in a loop One leg of the loop moves first
Spot and futures basis Buy spot, sell the future at a premium Funding rates and margin calls
Statistical Trade when a pair drifts from its usual spread The spread may not return

Arbitrage is not the same as ordinary trading. A normal trading bot bets on the direction of the market. An arbitrage bot bets that the price of the same coin on two venues will meet again soon, and it closes the trade as soon as the gap closes. For a plain definition of the idea behind it, see what crypto arbitrage is.

Which arbitrage strategies can a bot run?

A bot can run cross-exchange, triangular, spot-and-futures and statistical arbitrage, and each one needs different data, balances and speed.

Cross-exchange arbitrage is the simplest to understand. The bot holds funds on two exchanges, buys the coin where it is cheaper and sells it where it is dearer, at the same time. Holding funds on both sides removes the need to move coins between exchanges, which is usually the slowest step.

Triangular arbitrage stays on one exchange. The bot trades three pairs in a loop, for example BTC to ETH, ETH to USDT and USDT back to BTC, and keeps the loop when the round trip ends with more than it started with. It needs no transfers, but it needs three order books to move in its favour at the same moment.

Spot-and-futures arbitrage buys the coin on the spot market and sells a futures contract for the same coin at a higher price. The profit is the gap between the two prices, minus funding costs. Statistical arbitrage watches pairs that usually move together and trades when the gap between them grows wider than usual, on the bet that it will narrow again.

What does the bot need to work?

A crypto arbitrage bot needs exchange accounts with API keys, funds on each venue it trades on, live price feeds, and a server close enough to the exchanges to act before the gap closes.

API keys are the bot's hands. Each exchange gives you a key and a secret that let the bot read prices and place orders. Keep the keys limited: allow trading, block withdrawals, and tie them to a fixed IP address where the exchange supports it. A key that can withdraw funds is a key that can empty your account.

Funds must sit on every venue the bot trades on, because moving coins between exchanges takes minutes and the gap usually lasts seconds. That means your capital is split across exchanges, and each slice can only trade the gaps it sees on its own venue.

The bot also needs a reliable price feed and a place to run. A small virtual server in a data centre near the exchanges is the usual choice. Running the bot on a home laptop is a poor fit: a restart, a slow connection or a closed lid can leave orders open with no one watching them.

How to build a crypto arbitrage trading bot

You build a crypto arbitrage trading bot by picking one strategy, connecting to two exchanges, writing the price check and the trade rule, and testing with small amounts before scaling up.

  1. Pick one strategy. Start with cross-exchange arbitrage on one coin pair. It is the easiest to reason about and the easiest to test.
  2. Open accounts and set up API keys. Verify your identity on both exchanges, create API keys with trading permission only, and store the secrets outside the code, for example in environment variables.
  3. Connect to the price feeds. Use the exchanges' websocket feeds for live prices. Polling the REST API every few seconds is too slow for most gaps.
  4. Write the gap check. For each pair, compare the best ask on the cheap exchange with the best bid on the dear one, subtract both trading fees and the expected slippage, and trade only when the result is positive.
  5. Write the order logic. Place both legs as limit orders, check that both filled, and log every fill. If one leg fails, the bot must stop and flag the open position instead of trading on.
  6. Add safety limits. Cap the size of each trade, cap the number of trades per hour, and add a daily loss limit that stops the bot and alerts you.
  7. Test small, then scale. Run in paper mode first, then with the smallest real amounts for a week. Scale up only when the logs show the bot behaves as designed.

Keep the first version small. A bot that does one strategy well on one pair is worth more than a bot that tries four strategies and fails quietly on all of them. A general Python trading bot covers similar ground in a different way, as shown in how to build a crypto trading bot with Python.

How fees and speed decide whether it earns

Fees and speed decide whether an arbitrage bot earns, because the price gap is usually smaller than the cost of trading twice.

Every trade pays a fee on the buy side and a fee on the sell side, and many exchanges charge a withdrawal fee as well. If the gap is 0.3% and each side charges 0.1%, the fees take 0.2% and leave 0.1% before slippage. A thin order book can eat that remainder: a market order that walks through several price levels pays a worse average price than the top of the book suggests.

Speed matters because other bots see the same gap. A gap that lasts ten seconds on a quiet pair may last less than a second on a busy one. The bot that acts first gets the trade, and the others get a filled order at a price that no longer makes sense. That is why the bot checks the gap after fees, not before, and why it cancels stale orders fast.

Some exchanges offer lower fees for high volume or for holding their token. Those discounts change the maths, so the bot should read the fee schedule for each venue and use the real fee in its gap check, not a round number from memory.

Example (hypothetical): a two-exchange spread

Example (hypothetical): a trader runs a cross-exchange bot on BTC with 1 BTC of capital on each of two exchanges. On exchange A the best ask is $60,000. On exchange B the best bid is $60,300. The gap is $300, or 0.5%.

Each exchange charges a 0.1% trading fee. The buy on A costs $60 in fees, and the sell on B costs $60.30 in fees, for a total of $120.30. The gross gain is $300, so the net gain after fees is $179.70 on that trade.

If the bot finds ten such gaps in a day, the net gain is 10 times $179.70, which is $1,797 for the day, before server costs of a few dollars a day. If the gap narrows to $150 instead, the gross gain is $150, the fees stay near $120, and the net gain falls to about $30, which shows how quickly a shrinking gap eats the profit.

The same trade can go wrong. If the sell leg fails while the buy leg fills, the bot holds 1 BTC it did not plan to hold, and the price can fall before it sells. That is why the bot must check both fills and stop when one leg fails.

What are the common mistakes?

The most common mistakes with arbitrage bots are ignoring fees in the gap check, trading with one leg unfilled, and leaving a bot running with no loss limit.

  • Forgetting fees. A gap that looks profitable before fees can lose money after both sides pay. Always subtract fees and slippage first.
  • Moving coins between exchanges mid-trade. Transfers take minutes and the gap closes in seconds. Keep funds on both sides instead.
  • No check that both legs filled. A half-filled trade is an open position, not an arbitrage. The bot must stop and report it.
  • Trading with withdrawal-enabled API keys. A leaked key with withdrawal rights can drain the account. Trading-only keys limit the damage.
  • Scaling up after one good day. A quiet market can produce gaps that vanish in a busy one. Run small for at least a week before adding capital.
  • Ignoring exchange rules. Some exchanges limit how often you can place orders or ban certain trading patterns. Breaking the rules can freeze the account.

Key takeaways

  • An arbitrage bot earns the gap between two prices, not a market move
  • Fees and slippage come out of the gap before any profit is counted
  • Funds must sit on each exchange, because transfers are slower than gaps
  • Both legs of a trade must fill, or the bot must stop and report it
  • Test with small amounts for a week before adding capital

Frequently asked questions

What is the simplest arbitrage strategy to build first?

Cross-exchange arbitrage on one coin pair is the simplest start. The bot buys the coin where it is cheaper and sells it where it is dearer, at the same time. It needs funds on both exchanges and a gap check that subtracts fees before deciding to trade.

How much money do I need to run an arbitrage bot?

There is no fixed minimum, but the bot needs enough capital on each exchange to place trades worth more than the fees they pay. Small trades often lose money after fees, so most builders start with enough to make each trade at least several times the combined fee.

Do arbitrage bots work in a falling market?

They can, because arbitrage earns from the price gap between venues, not from the price going up. A falling market can even create larger gaps. The risk is different: a failed leg leaves an open position that falls with the market.

How is an arbitrage bot different from a normal trading bot?

A normal trading bot bets on the direction of the market, buying low and hoping the price rises. An arbitrage bot bets that the price of the same coin on two venues will meet again soon, and it closes the trade as soon as the gap closes.

Can I run an arbitrage bot on my own computer?

You can, but it is a poor fit for live trading. A home computer can restart, lose its connection or go to sleep, leaving orders open with no one watching. A small virtual server near the exchanges is the usual choice for a bot that runs all day.

Is crypto arbitrage legal?

In most places, buying on one exchange and selling on another is legal trading, but the rules vary by country and by exchange. Some exchanges limit order frequency or ban certain patterns. Check the rules of each exchange and the law where you live before running a bot.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building a trading bot and want the exchange side handled? Talk to Hertiv.

A senior engineer replies within one business day. Or see our Crypto Exchange service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call