Skip to content


📁 Strategy folder

📝 Summary

This strategy monitor prices in two different trading pairs and executes offsetting buy and sell orders in both markets in order to capture arbitrage opportunities with profitability higher than min_profitability, net of transaction costs.

đŸĻ Exchanges supported

spot exchanges

👷 Maintenance

  • Release added: 0.3.0 by CoinAlpha
  • Maintainer: Open

🛠ī¸ Strategy configs

Config map

Parameter Type Default Prompt New? Prompt
primary_market string True Enter your primary spot connector
secondary_market string True Enter your secondary spot connector
primary_market_trading_pair string True Enter the token trading pair you would like to trade on [primary_market]
secondary_market_trading_pair string True Enter the token trading pair you would like to trade on [secondary_market]
min_profitability decimal 0.3 True What is the minimum profitability for you to make a trade?
use_oracle_conversion_rate bool True Do you want to use rate oracle on unmatched trading pairs?
secondary_to_primary_base_conversion_rate decimal 1 False Enter conversion rate for secondary quote asset value to primary base asset value
secondary_to_primary_quote_conversion_rate decimal 1 False Enter conversion rate for secondary quote asset value to primary quote asset value

📓 Description

Trading logic

Approximation only

The description below is a general approximation of this strategy. Please inspect the strategy code in Trading Logic above to understand exactly how it works.


The strategy constantly scans for any arbitrage opportunity by comparing the order books on two markets that are trading equivalent assets (e.g. WETH-USDC vs. ETH-USD). Whenever it finds any price dislocation between the two markets (i.e. it's profitable to buy from one and sell to the other), it would calculate the optimal order size to do the arbitrage trade, and trades away the price difference by sending opposing market orders to both markets.

Here's a high level view of the logic flow inside the built-in arbitrage strategy.

Figure 1: Arbitrage strategy flow chart

There are a few major parts to the arbitrage strategy in terms of its logic flow:

  1. Sanity checks, before scanning for arbitrage opportunities
  2. Scanning for profitable arbitrage trades
  3. Calculating the optimal arbitrage size
  4. Executing the arbitrage orders

Sanity Checks

Before the strategy looks at the two markets for profitable trades, it needs to check whether it is safe to do any trades first.

There are a few conditions that the strategy would check for at every tick, before proceeding to looking at the market order books:

  1. Are both markets connected and ready?

    If any of the left or right markets is not ready, or is disconnected; then no arbitrage trade is possible.

  2. Are there pending market orders on the markets that are still being processed?

    If there are outstanding market orders still being processed in the markets, then no further arbitrage trade is possible.

  3. Has there been a recent arbitrage trade within the cooldown period?

    If an arbitrage trade has happened recently, within the cooldown period (the next_trade_delay_interval init argument in arbitrage.pyx), then no arbitrage is possible for this tick. This wait is needed because asset balances on markets often need some delay before they are updated, after the last trade.

Scanning For Profitable Arbitrage Trades

After the sanity checks have passed, the strategy would look at the top of the two markets' order books to see if any profitable arbitrage is possible. This is only possible if one of the following happens:

  1. The price of the bid order book on the left market is higher than the price of the ask order book on the right market; or
  2. The price of the bid order book on the right market is higher than the price of the ask order book on the left market.

In either case, the arbitrage strategy would be able to sell into the higher bid book and buy from the lower ask book. If none of the above is true at the current tick, then the arbitrage strategy would wait for the next tick and repeat the same process.

The profitable arbitrage check logic can be found in the function c_calculate_arbitrage_top_order_profitability() inside arbitrage.pyx.

Calculating the Optimal Arbitrage Size

After an arbitrage opportunity is found, the next step is to calculate the optimal order size for the arbitrage trade.

Figure 2: Calculating the optimal arbitrage size

Arbitrage opportunities are always limited in size - as you buy higher and higher into the ask book and sell lower and lower into the bid book, the amount of profit decreases for every increment of order size. Eventually, the price you buy and sell into the two books would become the same and you would no longer make more money by increasing the order size further. So the arbitrage strategy would calculate the maximum order size you can make by examining the order books on the two markets.

Another thing the arbitrage strategy takes into account is the transaction fee of the markets. Some markets has a fixed or semi-fixed fee for every trade, s.t. you'd need a certain minimum order size for the arbitrage before it would make any profit. The arbitrage strategy would try to take that into account and calculate the correct order size that produces the most profits.

Finally, the arbitrage strategy will look at the balance of assets available for trading in both the left and right markets - the arbitrage order size cannot exceed the amount of assets that can be traded.

The optimal arbitrage size calculation logic can be found in the functions c_find_best_profitable_amount() and c_find_profitable_arbitrage_orders() inside arbitrage.pyx.

Executing the Arbitrage Orders

If the calculated arbitrage size is greater than 0, then the arbitrage strategy would send both the market buy and market sell orders to the two markets simultaneously. Arbitrage opportunities are usually rare and are quickly exploited by traders, and so it is important to send both orders out without any wait.

The order execution logic can be found in the function c_process_market_pair_inner() inside arbitrage.pyx.

ℹī¸ More Resources

What is Arbitrage?: The concept of arbitrage is fairly simple: Arbitrage is the purchase and sale of an asset in order to benefit from a difference in the price of the asset between markets.

How to Spot Market Making and Arbitrage Opportunities?: Learn how to optimize the arbitrage strategy for different opportunities.

Check out Hummingbot Academy for more resources related to this strategy and others!