Latency Comparison Between Exchanges
Overview
This tutorial shows how to measure and compare data latency across exchanges using CoinAPI’s Market Data WebSocket.
By the end, you will build a Node.js script that:
- connects to the WebSocket stream
- subscribes to real-time data from multiple exchanges
- calculates latency per message using:
time_exchange(when the event happened at the exchange)time_coinapi(when CoinAPI processed it)
- aggregates latency per exchange
- displays:
- latest latency
- average latency
- min / max latency
What latency means in this context
Each message includes:
time_exchange→ timestamp from the exchangetime_coinapi→ timestamp when CoinAPI processed the data
Latency calculation:
Latency = time_coinapi - time_exchange
This measures:
- exchange → CoinAPI ingestion delay
- normalization / processing delay
👉 It does NOT include your local network latency.
What you will build
You will compare latency across exchanges for BTC:
BINANCE_SPOT_BTC_USDTOKEX_SPOT_BTC_USDTBYBIT_SPOT_BTC_USDT
These are highly active markets, which makes them ideal for observing latency behavior.
Prerequisites
- Node.js installed
- CoinAPI API key
- Terminal access
WebSocket endpoint:
Step 1 — Create project folder
Step 2 — Create package.json
Step 3 — Install dependencies
Step 4 — Create .env
Step 5 — Create index.js
Step 6 — Run the script
Step 7 — Sample output
Step 8 — What this shows
Using BTC improves:
- message frequency (more data points)
- stability of averages
- clearer comparison between exchanges
You can now easily see:
- which exchange has the lowest latency
- which has spikes (max latency)
- which is most consistent
Step 9 — Optional improvements
You can extend this by:
- adding latency percentiles (p95, p99)
- plotting latency over time
- detecting spikes automatically
- comparing different data types (
trade,quote,book)
Congratulations!
You now have a real-time BTC-based latency comparison tool.
You were able to:
- stream high-frequency BTC trade data
- calculate latency using timestamps
- aggregate metrics per exchange
- compare performance across venues
This is especially useful for:
- evaluating data quality
- monitoring exchange performance
- identifying latency anomalies