Single Blog

Automating Crypto Arbitrage with Crypto-Pandas and CCXT: A Complete Walkthrough

In crypto trading, inefficiencies across exchanges aren’t mistakes, but opportunities. Having the ability to detect and see these price differences can give traders a clear advantage in competition, especially in arbitrage plays.

In this guide, let’s get our basics right to leverage Python, Crypto-Pandas, and CCXT to analyse and visualise bid-ask spreads across multiple exchanges. This method isn’t theoretical; it’s a practical, repeatable approach that any trader or data analyst can implement to reveal where spreads are widest and opportunities most likely to exist.

Before we get started, it’s well worth mentioning that the libraries we are going to use are thoroughly supported and widely used. The Crypto-Pandas project on GitHub, offering a high-level abstraction over exchange APIs, and the formidable ccxt repository, linking Python apps to hundreds of crypto exchanges with a single API, are the building blocks on which this analysis is based.

Why Visualising Bid-Ask Spreads Matters in Crypto

As compared to traditional markets, where liquidity is proximate, crypto markets are highly decentralised. At a particular moment, a trading pair is priced one way on Binance and another on Bybit, or perhaps differently on Kucoin. Price spread is the difference between the highest price any buyer will pay to take (bid) and the lowest price any seller will take to give (ask), an opportunity for inefficiency that several market players can cash in on.

When developing an arbitrage strategy, monitoring market fragmentation or simply understanding how the liquidity is spread amongst platforms is something you would want to have a strong grasp on. With Python and Crypto-Pandas, you can make this happen and achieve near-real-time visibility into these market inefficiencies.

Step-by-Step Breakdown of the Code

1.Importing the Libraries

We begin by importing the key libraries:

  • CryptoPandas simplifies working with exchange data.
  • CCXT connects to multiple crypto exchanges.
  • Pandas enables data manipulation and analysis.

from crypto_pandas import CCXTPandasExchange
import ccxt
import pandas as pd

These tools form the backbone of our project, making it easy to fetch, structure, and analyse real-time data.

2. Connecting to Exchanges

Next, we establish connections to the exchanges we’ll be comparing. For this example, we use Binance, Bybit, and Kucoin.

# Setup exchanges
binance = CCXTPandasExchange(exchange=ccxt.binance())
bybit = CCXTPandasExchange(exchange=ccxt.bybit())
kucoin = CCXTPandasExchange(exchange=ccxt.kucoinfutures())

Each exchange is initialised using CCXT under the hood, wrapped by Crypto-Pandas for easier data handling. These connections allow us to fetch live bid-ask prices for our analysis.

3. Fetching Bid-Ask Data

This is the beating heart of the analysis. We fetch the bid and ask prices from each exchange.

# Fetch bids and asks
binance_ba = binance.fetch_bids_asks()
bybit_ba = bybit.fetch_bids_asks()
kucoin_ba = kucoin.fetch_bids_asks()

4. Structuring the Data for Analysis

We then group all the data of bid-ask into one pandas DataFrame for ease of analysis.

# Combine and display
data = pd.concat([
binance_ba,
bybit_ba,
kucoin_ba,
])

print(data.dropna(axis=1))

5. Identifying Arbitrage Opportunities

With our consolidated dataset, we prepare to analyse potential spreads between exchanges. This is achieved by merging the DataFrame onto itself, aligning rows by symbol while differentiating the source exchanges.

# Find all combinations and calculate spread
arbitrage = data[[“exchange”, “symbol”, “bid”]].merge(
data[[“exchange”, “symbol”, “ask”]],
on=”symbol”,
suffixes=(“Short”, “Long”)
)

This merge creates pairings between each exchange’s bid price and every other exchange’s ask price for the same symbol. It lays the groundwork for identifying mismatches where buying low and selling high might be feasible.

The suffixes clearly mark which side of the trade we’re analysing:

  • Short: The exchange with the higher bid (where we could sell
  • Long: The exchange with the lower ask (where we could buy)

6. Calculating Absolute and Relative Spreads

Now, we compute two critical metrics:

  • Absolute Spread: The raw price difference between bid and ask.
  • Relative Spread: The spread is expressed as a percentage of the average price, making it comparable across assets of different values.

arbitrage[“spread”] = arbitrage[“bid”] – arbitrage[“ask”]
arbitrage[“spreadRelative”] = arbitrage[“spread”]/arbitrage[[“bid”, “ask”]].mean(axis=1)

These calculations help us understand both the size and the significance of any potential opportunity. A small absolute spread on a high-priced asset might not be worth pursuing, while a significant relative spread can indicate low-effort profit potential.

7. Filtering and Prioritising Opportunities

To ensure realistic analysis, we filter out cases where both bid and ask are from the same exchange. Then we sort the results by the relative spread to prioritise the best opportunities.

# filter for different exchanges for buy/sell
arbitrage = arbitrage.query(“exchangeShort != exchangeLong”).sort_values(“spreadRelative”, ascending=False, ignore_index=True)

This filtration step removes redundancies and highlights genuine cross-exchange inefficiencies. Sorting helps quickly pinpoint where the widest spreads exist.

8. Reviewing the Results

Finally, we inspect the top opportunities using a readable markdown format.

print(arbitrage.head(10).to_markdown(index=False))

Below is a purely illustrative example of how your output might look. These values are arbitrary and do not reflect real-time data.

exchangeShortsymbolbidexchangeLongaskspreadspreadRelative
kucoinETH/USDT1800bybit179550.0027
binanceBTC/USDT30000kucoin29950500.0016

Your actual results will depend on live data, and spreads may be larger or smaller depending on market conditions at the time of fetching

Why This Process Matters for Traders

Visualising bid-ask spreads across crypto exchanges helps spot arbitrage opportunities and reveals liquidity mismatches. This insight is crucial for designing trading strategies, sourcing liquidity, and managing risk. Automated spread analysis enables real-time monitoring and forms the foundation for trading bots and dashboards. For traders and quants, it’s a practical tool with immediate value.

From Data to Edge: Build Smarter with Sigma Quantiphi

Turning raw market information into actual trading insights is where the real benefit lies. Frameworks like CCXT and CryptoPandas allow for finding inefficiencies that others don’t, but the trick now is scaling those insights.
From dashboard creation to quantitative model tuning to systematic strategy building, structured data is a must-have element for faster and better decision-making in the volatile environment of crypto. Sigma Quantiphi provides state-of-the-art analytics solutions with one mission: to transform data into performance. Whether it is custom tooling or AI-driven insights, the platform enables you to walk to outcomes from opportunities.

Search deeper avenues. Build smarter systems. Start with the right base.