How I use AI to find spreads and run arbitrage: my workflow

A code editor and a spread chart side by side on a dark screen, joined by a blue line

AI never places my orders. It writes my trading code, mines fill logs for spreads and reviews the order code; the orders on the server come from compiled programs that never call an AI while trading.

I use an AI coding tool: I describe what I need in plain language, and it reads and writes the code and data in the project directly. I had no programming experience, and over the last three months AI co-wrote 93% of the commits in my trading projects. This guide covers my workflow, the mistakes AI caught for me and the mistakes AI made. Signals and entry parameters stay private.

What does AI do in my arbitrage workflow?

StageWhat AI doesWhat I do
Finding spreadsReads fill logs and order book recordings, runs backtests, evaluates new exchanges and symbolsDecide whether anything goes live
Writing the execution codeWrites order sending, fill confirmation, reconciliation, unhedged-leg repair, watchdogs and circuit breakersAuthorize every test that uses real money, each time
ReviewA second model reads the change and hunts for bugs that lose moneyDecide what to fix and whether to deploy
Daily reportQueries the database read-only and summarizes each day’s PnL and anomaliesRead the report and decide tomorrow’s changes

Every question gets its own ticket, and AI writes the data, the steps and the conclusion into it. My main arbitrage project has collected 731 tickets since it started, one for each study, bug or feature, so every decision can be traced back to the data behind it.

Why not let AI place the orders?

  • Too slow: spreads often last only a few hundred milliseconds. A fast exchange answers my orders in a median of about 7 ms (see the cross-exchange spread guide); a language model usually takes seconds to answer once
  • Not reproducible: the same input does not always give the same answer from a model. Order logic has to be replayable, backtestable and traceable when something breaks
  • The cost of a mistake: a coding bug can be caught by tests and review before it goes live; a model misjudging a trade in the moment has nobody to stop it

So AI works before and after the trade: writing code, reading data, reviewing and reporting.

How do I use AI to find spreads?

I hand AI a question such as “should we add the three new pairs the scanner suggests?” and have it read the recorded order books and live fills, then work out what is left after fees and slippage. Three real examples:

  • A scanner can rank, not predict profit: the scanner’s theoretical leader, estimated from 1-minute candles, showed +366 bps a day, yet it lost 3 bps per trade live. The pair that worked was a different one: in about 24 hours it sent 4,003 orders and filled 3,183 (80%), earning +1.94 bps per trade before slippage. Pairs filling under 10% or turning negative after fees were excluded
  • Not adding an exchange back: replaying about 5 weeks of fills, the lowest net taker fee was still 1.0 bps, a net loss of 0.22 to 0.40 bps per dollar of notional, so it stayed out
  • Maker orders with a hedge leg: resting orders on one centralized exchange and hedging with taker orders elsewhere, replaying 3,000 maker fills per group across 2 trading days and 3 symbols, each fill lost 0.6 to 0.9 bps net without filtering. The sample was small and queue position was not modeled, so it never went live

AI research can be wrong too. For one US stock perp pair, the backtest assumed 6 bps of extra delay cost per fill on one side, 24.43 bps round trip in total; all 5,400 trades in 45 minutes of backtest lost money, and AI ruled the pair out. I then ran it live with small size for 45 minutes: measured slippage was 0.1 and 0.0 bps on the two sides, so the real round trip was 3.43 bps, an order of magnitude lower, and the verdict flipped.

Since then my rule is that backtests only rank and eliminate; anything going live first gets a small live run to calibrate the costs.

How do I use AI to write the execution code?

AI writes the whole execution chain: sending orders to two exchanges at once, confirming fills (the exchange response, the private stream and an order query, whichever arrives first), reconciling on a schedule, repairing a leg when one side did not fill, and halting when an order book goes stale or errors keep coming. The compiled program runs on the server around the clock.

AI got things wrong. All 3 incidents below happened in the first few days:

WhenWhat happenedLossProtection added
Day 1 liveThe config had two account addresses swapped; orders went through, but position queries always returned 0, so the bot thought it was flat and kept hedgingA small one-sided position, closed by hand at a small profitAt startup the bot compares the two addresses and refuses to start if they match
Day 3 liveA test AI ran closed positions using the whole account’s size and sold the live bot’s entire longThe live bot rebuilt it within 15 seconds, at a very small costTests may only close their own fills, and I authorize every real-money test each time
Day 5 liveRepeated rejects from one exchange counted as consecutive errors and halted the whole bot56 minutes of downtimeOnly that exchange pauses for 60 seconds; the others keep trading

None of these came from AI writing nonsense. They were edge cases nobody thought of: AI does what the request literally says, and it may not check situations the request never mentioned. After each incident I added a rule to the project’s decision log, so every later change follows it.

Adversarial review: let a second AI find faults

Every change that touches orders or funds is reviewed by a second AI model, deliberately a different one from the model that wrote the code. Each finding must name the file, the line and a concrete failure scenario, and a “looks fine” without evidence does not count. 455 of the 731 tickets mention review findings.

One example: a review found that when one exchange’s order API returned an “outcome unknown” error code, the code treated it as a definite reject. If that order had actually filled, the bot would think it had not and hedge the other side, leaving an unhedged position in the account. The case had not happened yet, and it was fixed before deploying. The same batch of fixes went through 3 more rounds: rounds 2 and 3 were ruled “do not deploy”, and round 4 passed.

Review is noisy too. Many rounds come back with nothing that must be fixed, a few findings are wrong, and I make the final call.

How can you start?

  1. Have AI work out the fee wall first: give it the exchanges’ official fee pages and API docs and have it add up the opening and closing costs on both sides; a spread below that number is not worth trading (how the fee wall works)
  2. Record data before backtesting: have AI write an order book recorder, record a few days, then backtest. Use backtests only to rank and eliminate
  3. Calibrate with small live trades: the slippage and delay a backtest assumes are often far from reality, so run the minimum order size for a while before scaling up
  4. Fail on missing data: require the code AI writes to stop when it cannot fetch a balance, fee or position, never to fall back on a default; my first incident above was exactly that
  5. Review with a different model: the model that wrote the code tends to agree with itself, so hand order and fund changes to another model to find faults
  6. No withdrawal rights on keys: the bot’s API keys only get trading permission; withdrawals and transfers are handled separately

Your fee tier decides how small a spread you can trade, so compare fees on the exchange overview before opening an account.

Never done arbitrage? Where do you learn?

Start with the beginner path, from opening an account and depositing to your first funding rate arbitrage, then come back to see how AI tools help find spreads.

Sources