如何测量场外交易(Arbitrage)的加密货币交易所 API 延迟(以及为什么填充质量更为重要)

Every crypto arbitrage trader eventually asks the same question: which exchange API is fastest? The honest answer is that the number most people quote, a ping time, tells you almost nothing about whether your arbitrage orders will actually make money. An exchange can answer a ping in 3 ms and still deliver stale order-book updates, slow acknowledgements at busy moments and fills that land a few ticks away from the price your bot saw.

This guide shows how to measure crypto exchange API latency properly: which five delays matter, how to set up a fair test, how to read the results as a distribution instead of an average, and why fill quality usually decides more than raw speed. It is a measurement method, not a league table. We deliberately publish no per-exchange numbers, because latency depends on where your server sits, which endpoints you use and when you test. The only figures that count are the ones you measure yourself.

If you have not yet built the connection itself (WebSockets, rate limits, signing, order-book sync), start with our guide to 用于套利的加密货币交易所 API 连接 and come back here once data is flowing.

Why a ping time is the wrong number

A ping, or a call to an exchange’s server-time endpoint, measures one thing: how long a tiny request takes to travel to the exchange’s edge and back. Arbitrage depends on a chain of separate delays, and the network round trip is often the smallest and most stable of them. The delays that move your profit and loss are the ones inside the exchange: how quickly the matching engine’s events reach your WebSocket, how long the order gateway takes to accept an order, and how long the fill report takes to come back, especially when the market is moving and everyone else is sending orders too.

The five latencies that matter

  1. Network round trip. Your server to the exchange’s API edge and back. Mostly decided by geography and routing. Stable, easy to measure, rarely the bottleneck once your server is in the right region.
  2. Market-data latency. The time between the exchange’s own event timestamp on a trade or book update and the moment your bot receives it. This decides how fresh your view of the price is, and therefore whether the gap you see still exists.
  3. Order acknowledgement latency. From sending a new order to receiving the exchange’s “accepted” response. This covers the gateway, risk checks and queueing in front of the matching engine.
  4. Fill (execution report) latency. From sending the order to receiving the fill on your private stream. For a taker order this is the number that tells you when you are actually hedged.
  5. Cancel latency. From sending a cancel to receiving confirmation. It matters whenever a resting order must be pulled because the opportunity vanished.
One arbitrage order, five timestamps Measure each gap separately – a single ping hides all of them T0 exchange event time T1 update received T2 order sent T3 ack received T4 fill received market-data latency T1 – T0 (clock-corrected) your reaction T2 – T1 ack latency T3 – T2 fill latency T4 – T2: when you are actually hedged Network round trip sits inside every arrow. Cancel latency is measured the same way as ack latency.
Log five timestamps per order and every latency you care about becomes a simple subtraction.

Set up a fair test before you measure anything

Most latency comparisons you find online are not wrong, they are just measuring something different from what you will trade. Before you trust a number, fix these conditions.

  • Measure from your production location. Latency from a laptop at home says nothing about latency from a server in the exchange’s cloud region. Run the test on the same machine, in the same region, that will run the bot. The server location guide explains how to choose that region.
  • Use the endpoints you will trade through. If your bot sends orders over a WebSocket order API, measure that, not the REST endpoint. Some exchanges route REST and WebSocket orders through different gateways with different queues.
  • Synchronise your clock. Market-data latency compares the exchange’s timestamp with yours, so a clock that is 15 ms off produces a 15 ms error. Run chrony or NTP against good time sources and record the offset alongside your results.
  • Use a monotonic clock for round trips. For ack, fill and cancel latency you only need your own start and end time. Take both from a monotonic high-resolution clock, not wall time, so clock corrections during the test cannot distort results.
  • Test at the times you trade. Quiet Sunday mornings flatter every exchange. Include the US open, major macro releases and fast market moves, because that is when arbitrage gaps appear and when gateways slow down.
  • Collect enough samples. A few dozen pings is anecdote. Aim for thousands of market-data messages and at least several hundred order round trips per exchange before comparing tails.

Measuring market-data latency

Most exchange WebSocket messages carry an event time or transaction time set by the exchange. Record your local receive time the instant the message arrives, before parsing it, and store both. The difference, corrected by your known clock offset, is your market-data latency.

Two refinements make the number trustworthy. First, separate message types: trade prints, top-of-book updates and depth diffs often travel through different internal pipelines and can show very different delays on the same exchange. Second, watch the gaps between messages as well as their age. A feed that normally ticks every 100 ms but sometimes goes silent for two seconds during volatility is more dangerous than one that is consistently 20 ms slower, because the silence is exactly when your bot believes a stale price.

If an exchange’s timestamps are coarse, for example rounded to whole milliseconds or set late in its pipeline, treat market-data latency as approximate and lean more on the order round-trip numbers below.

Measuring order round trips safely

You cannot measure order latency without sending orders, but you can do it without taking market risk. The standard method is a post-only limit order placed far enough from the market that it cannot fill, followed by an immediate cancel. You record the send time, the acknowledgement time and the cancel confirmation time, which gives you ack latency and cancel latency on every cycle.

  • Use the exchange’s minimum order size and a price well outside the spread.
  • Stay comfortably inside the documented rate limits and order-to-trade expectations. A latency test that triggers a rate-limit ban or a warning from the exchange has measured the wrong thing.
  • Read the exchange’s API terms. Test orders are normal practice, but spamming orders that are never meant to trade can breach some venues’ rules, so keep the volume modest and spread over time.

Fill latency needs real fills. The cleanest way is to record it from your genuine small trades, or from a short series of minimum-size taker orders on a liquid pair, measuring from send time to the fill message on your private stream. Do not assume the ack time equals the fill time: on some venues the fill report arrives noticeably later than the acknowledgement, and your hedge leg should be timed off the fill.

Read the distribution, not the average

An average hides the only part of the latency profile that hurts arbitrage: the slow tail. If 99 orders take 8 ms and one takes 900 ms, the average is about 17 ms and looks fine, yet that one slow order is the one that leaves you legged during a spike. Report every measurement as percentiles.

  • p50 (median): the typical case. Useful for comparing regions and endpoints.
  • p95 and p99: what happens on a busy day. This is where exchanges differ most.
  • Max and timeouts: count separately how often a request never got a reply within your timeout. A venue with a good p99 but frequent timeouts is not a fast venue.
  • Jitter: the spread between p50 and p99. Low jitter makes your hedging logic predictable; high jitter forces wide safety margins that eat the edge.
Same median, very different tail (illustrative) Order acknowledgement latency, share of orders per bucket 0-5 5-10 10-20 20-50 50-100 100-250 250-500 500 ms+ milliseconds Venue A: p50 7 ms, p99 60 ms Venue B: p50 8 ms, p99 520 ms Average ping would call them equal. For arbitrage, B’s tail is the risk. Illustrative shapes, not measurements of any real exchange.
Illustrative example: two venues with near-identical medians. The orange tail is where legged trades and missed hedges come from.

Fill quality: the metric that actually pays

Latency is a means, not the goal. What you are really buying with speed is better fills: getting the price you saw, in the size you wanted, without rejections. Two venues with similar latency can produce very different results because of matching-engine behaviour, book depth, self-trade rules or how their gateways behave under load. Track these alongside latency, per exchange and per pair:

  • Fill ratio: the share of intended taker orders that filled completely. Partial fills and IOC orders that expire unfilled both count against it.
  • Slippage versus signal price: the difference between the price your bot saw when it decided to trade and the average fill price, in basis points or ticks. This single number combines market-data staleness, reaction time, order latency and book depth.
  • Reject and timeout rate: orders refused for rate limits, price bands, insufficient balance or internal errors, plus orders with no response in time. Each one is a potential legged trade on a two-exchange strategy.
  • Effective edge: gross gap captured, minus fees, minus slippage, per trade. This is the number to compare venues by.
Faster is not always better (illustrative) Basis points per trade on the same 20 bp gross gap Venue A – p99 40 ms +20 -6 fees -9 slip +5 net fill ratio 82%, frequent partials Venue B – p99 70 ms +20 -6 fees -3 slip +11 net fill ratio 97%, deeper book Illustrative numbers. Compare venues on effective edge after fees and slippage, not on latency alone.
Illustrative: the slower venue nets more than twice the edge per trade because its fills are cleaner.

This is the trade-off the people searching for “platforms that balance latency and fill quality” are really asking about. In cross-exchange arbitrage, the right venue is the one with the best effective edge at your trade size, and latency is one input into it, not the answer.

A scorecard for comparing exchanges

Put your measurements into one table per exchange and pair, refreshed weekly. It keeps decisions based on data rather than reputation.

指标How to measureGood signRed flag
Network RTTTCP connect or server-time call, p50Low single-digit ms from the right regionTens of ms: wrong region or routing
Market-data latencyReceive time minus event time, clock-correctedStable p99, no long silencesMulti-second gaps during volatility
Ack latencyPost-only far limit order, send to ackTight p50 to p99 spreadp99 many times p50, timeouts
Fill latencyTaker order, send to fill on private streamClose to ack latencyFill reports lag acks noticeably
Cancel latencyCancel sent to cancel confirmedSimilar to ack latencyCancels slow down under load
Fill ratioFilled size / intended sizeAbove 95% at your sizeFrequent partials or IOC expiries
Slippage vs signalFill price minus decision price, bpSmall and stableGrows sharply in fast markets
Reject / timeout rateRejected or unanswered / total ordersWell under 1%Rate-limit or internal-error rejects at peaks

Common measurement mistakes

  • Timing after parsing. If you record receive time after JSON decoding and book updates, you measure your own code. Timestamp first, process second. Measure your processing separately, as reaction time.
  • Testing one region and trading from another. Even a few hundred kilometres change the picture, and exchanges behind global CDNs can route you to different edges from different places. Our hop-by-hop latency breakdown shows how much of a round trip is outside your control.
  • Ignoring the queue. Your order waits behind everyone else’s at busy moments. That queueing is real latency, which is why quiet-hour tests mislead.
  • Comparing REST against WebSocket. A REST request may pay connection or TLS overhead that a persistent WebSocket session does not. Compare like with like.
  • Trusting one week of data. Exchanges change infrastructure, endpoints and limits. Keep the measurement running continuously and alert when p99 or reject rate drifts.

Step by step: build your own latency and fill-quality benchmark

  1. Deploy the probe where the bot will run. Same server, same region, same network path.
  2. Sync the clock. 运行 chrony 或 NTP,记录偏移量,并为所有往返传输使用单调时间。
  3. Record market-data latency. 每条交易和预订消息,均可在各个渠道中查看交易交换活动的开始时间和本地接收时间。
  4. Run safe order round trips. Post-only, minimum-size, far-from-market orders plus cancels, at a modest steady rate within the limits, recording send, ack and cancel times.
  5. Log real fills. 对于实时或小型测试交易,记录决策价格、发送时间、填充时间、填充价格和手数。
  6. Summarise as percentiles. p50, p95, p99, max and timeout count per metric, per exchange, per hour of day.
  7. Rank by effective edge. Combine fees, slippage and fill ratio into net basis points per trade at your size, and review the scorecard weekly.

Once you have the numbers, the decisions follow naturally: which venue to use for the hard-to-fill leg, which pairs to drop, where to move your server, and how wide your safety margins must be. For the bigger picture of running a bot across several venues, see our 跨交易所加密货币套利机器人指南.

常见问题解答

ping 是否是比较加密货币交易所 API 的好方法?

Only as a first check that your server is in the right region. Ping measures the network round trip to the exchange’s edge, not market-data freshness, order acknowledgement, fill timing or behaviour under load, which are what decide arbitrage results.

加密货币套利的最佳 API 延迟是多少?

不存在统一的标准。这取决于策略、交易的空缺规模以及竞争对手的速度。稳定的 p99 远比中位水平低的重要性更大,而真正的考验在于您的有效优势是否在费用和滑点方面保持正值。

WebSocket 的订单处理速度是否比 REST 更快?

通常情况下,由于持久的 WebSocket 会话可以避免请求级连接和身份验证的开销,但并非每次都会实现这种效果。在选择之前,请从自己的服务器端测量这两个端点,并在繁忙的条件下进行比较,而不要仅局限于安静的状况。

我如何能测量订单延迟时间而不承担市场风险?

Place minimum-size, post-only limit orders far from the market and cancel them immediately, recording send, acknowledgement and cancel times. Keep the rate modest, stay inside documented limits and check the exchange’s API terms.

我需要多少份样本?

在安静和繁忙的时间段,市场数据消息数千条,交换双方至少有数百次订单往返操作。由于样本较少,p99的大部分都是噪音。

为什么我的填充物与我的机器人看到的价格不同?

信号价格与填仓价格之间的差距综合了陈旧的市场数据、您的反应时间、订单延迟以及有限的订单深度。分别衡量每个部分即可确定需要修复的环节:服务器位置、代码、端点选择或交易规模。

作者简介

或者加入我们的 Telegram 社区
加入 @hftarbitrage
Comments
0 Comments
Comments will be displayed after approval by the administrator