Backtesting Bitcoin Arbitrage Bots with Realistic Fees and Slippage

Best practices for simulating withdrawal costs, network gas, and market impact to generate trustworthy performance metrics before live deployment.

Best practices for simulating withdrawal costs, network gas, and market impact to generate trustworthy performance metrics before live deployment.

Backtesting Bitcoin Arbitrage Bots with Realistic Fees and Slippage

Authoritative guide for crypto traders, financial analysts, and developers seeking trustworthy performance metrics before live deployment.

---

Table of Contents

1. [What Is Bitcoin Arbitrage?](#what-is-bitcoin-arbitrage)

2. [Why Realistic Fee Modeling Matters](#why-realistic-fee-modeling-matters)

3. [Simulating Withdrawal Costs and Network Gas](#simulating-withdrawal-costs-and-network-gas)

4. [Incorporating Market Impact and Slippage](#incorporating-market-impact-and-slippage)

5. [Designing a Robust Backtesting Engine](#designing-a-robust-backtesting-engine)

6. [Interpreting Backtest Results](#interpreting-backtest-results)

7. [From Simulation to Live Trading](#from-simulation-to-live-trading)

8. [FAQ](#faq)

---

What Is Bitcoin Arbitrage?

Bitcoin arbitrage exploits price differentials for the same asset across independent trading venues. An arbitrage opportunity exists when the price of Bitcoin on Exchange A exceeds the price on Exchange B after accounting for transaction costs. The classic arbitrage cycle consists of three steps:

1. Buy Bitcoin on the cheaper exchange.

2. Transfer the asset to the more expensive exchange.

3. Sell Bitcoin at the higher price and capture the spread.

The profit margin is the spread minus all operational costs. Arbitrage strategies can be spatial (cross‑exchange) or temporal (price lag within a single exchange). Spatial arbitrage is the most common form for retail traders because it leverages the fragmented nature of the crypto market.

Why Realistic Fee Modeling Matters

Every Bitcoin transaction incurs multiple layers of fees:

If a backtest excludes any of these costs, the simulated profit will be overstated. An arbitrage bot that appears profitable on paper can become unprofitable when the cumulative fee load exceeds the raw spread. Accurate fee modeling is therefore the foundation of trustworthy backtesting.

Simulating Withdrawal Costs and Network Gas

1. Quantifying Withdrawal Fees

Withdrawal fees are deterministic for a given exchange and wallet type. To simulate them, create a fee table that maps each exchange to its current withdrawal fee in BTC. Update the table daily because exchanges adjust fees in response to network congestion.

`

withdrawal_fees = {

"Binance": 0.0005, # BTC

"Kraken": 0.0004,

"Coinbase": 0.0006,

"Gemini": 0.00045

}

`

During each simulated trade, subtract the fee from the transferred amount before the asset reaches the destination exchange.

2. Modeling Bitcoin Network Gas

Bitcoin’s network fee is not a static percentage; it depends on transaction size (in bytes) and the prevailing fee market. A practical approach is to model the fee as a piecewise function based on the fee‑per‑byte market rate:

Historical fee data can be sourced from public APIs such as mempool.space or blockchain.info. Incorporating a stochastic element—randomly selecting a congestion level according to observed probabilities—adds realism to the simulation.

3. Time Delay and Confirmation Risk

Network latency influences the risk of price movement while the transfer is pending. Model the confirmation time as a random variable that follows a truncated normal distribution with a mean of 10 minutes and a standard deviation of 4 minutes. Use this delay to retrieve the destination exchange’s price at the expected arrival time rather than the departure time.

Incorporating Market Impact and Slippage

1. Understanding Slippage

Slippage occurs when the execution price deviates from the quoted price due to order size, order book depth, and latency. In high‑frequency Bitcoin arbitrage, slippage can erode 0.05 % to 0.2 % of the trade value, especially on smaller exchanges.

2. Order‑Book‑Based Slippage Model

A realistic slippage model queries the order‑book depth of each exchange at the time of the simulated trade. Suppose an exchange’s order book shows the following bid ladder for Bitcoin (price in USD, volume in BTC):

| Price | Volume |

|-------|--------|

| 60,100 | 0.12 |

| 60,095 | 0.25 |

| 60,090 | 0.50 |

| 60,080 | 1.00 |

If the bot intends to buy 0.8 BTC, it will consume the first three depth levels, resulting in an average execution price of:

\[

\frac{0.12 \times 60{,}100 + 0.25 \times 60{,}095 + 0.43 \times 60{,}090}{0.8} \approx 60{,}092\text{ USD}

\]

The slippage is therefore (60 100 – 60 092) / 60 100 ≈ 0.013 %, or 13 bps.

Implement the same calculation for the sell side of the arbitrage loop. The net slippage is the sum of buy‑side and sell‑side slippage.

3. Market‑Impact Coefficient

For larger trades that move the market, introduce a market‑impact coefficient (MIC) derived from empirical studies. A common approximation is:

\[

\text{Impact\%} = \text{MIC} \times \sqrt{\frac{\text{Trade\_Size}}{\text{24h\_Volume}}}

\]

Empirical analysis of Bitcoin markets suggests MIC values between 0.3 and 0.6 for midsized exchanges. Capture the 24‑hour volume from exchange API endpoints and apply the formula to each trade in the backtest.

Designing a Robust Backtesting Engine

1. Data Requirements

A reliable backtest demands high‑resolution market data:

Data vendors such as Kaiko, CoinAPI, and CryptoCompare provide the necessary granularity.

2. Architecture Overview

A modular backtesting engine separates concerns into distinct layers:

1. Data Ingestion Layer – Normalizes and stores exchange feeds in a time‑series database (e.g., InfluxDB).

2. Simulation Layer – Executes the arbitrage algorithm, applying fee, gas, and slippage models.

3. Analytics Layer – Calculates performance metrics (Sharpe ratio, maximum drawdown, win‑rate).

4. Reporting Layer – Generates visual dashboards and exportable CSV files.

Use Python’s pandas and numpy libraries for vectorized calculations, and asyncio to simulate concurrent transfers.

3. Sample Pseudocode

`python

for timestamp in simulation_range:

1. Fetch best bid/ask from both exchanges

price_A = get_best_ask('Exchange_A', timestamp)

price_B = get_best_bid('Exchange_B', timestamp)

2. Compute raw spread

raw_spread = price_B - price_A

3. Estimate fees

fee_A = exchange_fee('Exchange_A', 'taker')

fee_B = exchange_fee('Exchange_B', 'maker')

gas_fee = simulate_bitcoin_gas(timestamp)

4. Estimate slippage using order book depth

slippage_buy = estimate_slippage('Exchange_A', size, timestamp, side='buy')

slippage_sell = estimate_slippage('Exchange_B', size, timestamp, side='sell')

5. Net profit per BTC

net_profit = raw_spread \

if net_profit > profit_threshold:

execute_trade(size, timestamp)

`

The pseudocode illustrates how each cost component is subtracted from the raw spread before the profitability decision is taken.

4. Performance Metrics

When evaluating the backtest, capture the following metrics:

Interpreting Backtest Results

1. Detecting Overfitting

A backtest that shows a dramatically higher Sharpe ratio than the underlying market’s Sharpe ratio is likely overfitted. Overfitting arises when the algorithm exploits noise rather than genuine price inefficiencies. Mitigate overfitting by:

2. Real‑World Constraints

Even a backtested strategy with a 0.2 % net spread can be impractical if the required capital exceeds exchange limits. Verify that the bot respects:

3. Sensitivity to Network Congestion

Run scenario analyses where network gas fees increase by 200 % to mimic peak periods (e.g., during a major market rally). Observe how the net profit curve responds. If profitability collapses under high‑congestion scenarios, the strategy should either incorporate a congestion filter or reduce trade size.

From Simulation to Live Trading

1. Deploying with Caution

Transitioning from backtesting to live deployment requires a phased approach:

ArbitrageRadar PRO on the App Store · arbitrageradarpro.com

Related guides

All guides · Coins · Exchanges

ArbitrageRadar PRO on the App Store · arbitrageradarpro.com