Scroll down for the English version.
在上一篇,我已经提到,我的大部分利润来自于在 @edgeX_exchange 跨所价差套利。在这里我想再次强调:跨所价差套利不是交易所的 bug,而是只有在交易所做得足够好的情况下才会出现的 feature。只有当一个交易所具备:
足够的流动性
足够的订单簿深度
稳定快速的撮合系统
套利的机会才真正“可被捕捉”。
大家常说币安是宇宙第一所,但事实也是——即使我在多个中心化交易所都有负手续费的做市商账户,币安仍然是我套利交易量最高的交易所。所以,在 edgeX 上套利并不是一个 bug,而是一个 feature。
这篇文章是为各种不同背景的朋友介绍 跨所价差套利。如果你看到我大篇幅地解释一些你觉得非常简单的概念,请谅解。
一、基础策略与本质
虽然“程序化套利”是一个非常广泛的领域,但几乎所有套利的本质都是一样的: 利用短暂的价格偏离,捕捉随后确定性的回归。
我在 edgeX 执行的是 跨所合约价差套利
什么是跨所合约价差套利?
在两个不同交易所之间,寻找同一标的永续合约价格的偏差,同时建立仓位:
A 所:做多
B 所:做空
形成一个 delta ≈ 0 的对冲组合,等价差回归后平仓锁定收益。
实例:
下面的截图中是两个交易所在同一时间 ETH 的订单簿截图,其中左边黑色的是 edgeX,右边白色的是另一交易所,我们暂时称它为 交易所B。
可以看到 edgeX 的买一价为 3178.27,交易所B的卖一价为3177.00,两者的差价为 1.27,那么套利者可以:
- 在 edgeX 做空 ETH
- 在 交易所B 做多 ETH
这样建立一个 对冲组合,整体 Delta ≈ 0,不吃价格的方向性风险。当两个交易所的价格靠近,比如下面这种情况,价差变为 0.1:
| edgeX | 3170.10 |
| 交易所B | 3170.00 |
如果这时候平仓,你就赚了这 合约价差的缩小部分,也就是1.27 - 0.1 = 1.17。
二、如何找到价差?
想找到有效的价差,不仅要看“价差本身”,更要看 价差的变化。
如果 ETH 在两个交易所永远相差 $2,这个价差没有套利价值。但如果有时相差 $2,有时相差 $1,那么在 $2 时开仓、$1 时平仓,就能赚确定性价差回归。
比如下面的这张图,通过可视化历史价差数据可以很清楚的看到这两个交易所之间价差的波动。
而要做到这些,需要:
1. 写代码实时监控订单簿(不是K线)
K线每秒一次的数据远远不够。
价差套利一定要监控订单簿的 每次 变化,并持续记录、分析、清洗数据。几乎没有交易所会提供订单簿的历史数据,因此,你需要写代码监控各个交易所的订单簿并花一定的时间来记录并导出数据。导出数据时的格式也非常重要,需要考虑到后期的数据分析,以及各个交易所数据之间的拼接。
2. 合约的底层资产必须完全一致
价差的来源有很多,比如流动性、交易结构差异、合约费率、用户结构不同,等等。在做价差套利时,底层资产一定要相同。比如有些交易所用的是USDT,而有些交易所是用USDC,这种情况下,你看到的价差也许只是 USDT 和 USDC 的价差,而不是跨所的价差。
三、什么时候开仓?什么时候平仓?(最能区分策略水平的维度)
我们知道,“价差大的时候”该开仓,“价差收敛的时候该平仓”,但多少是“大”,怎么样有算是“收敛”了呢?
其实 开仓/平仓 的决策逻辑,非常像“麦穗择取问题”:
有有限的资金
只能看到当前,不知道未来
必须实时决策
一旦开仓后,又开始新一轮择时:何时平仓?
更复杂的是,价差套利比起麦穗择取问题多了一个维度:时间。
举例:1 小时赚 1% vs 10 小时赚 2%,前者可能更优,因为 9 个小时里可能再做两次 1%,总收益反而更高。但也有可能后者更优,因为剩余的 9 个小时里可能不再出现套利的机会。
这就是价差套利最难的核心:开仓和平仓的时机。
在设计开仓和平仓算法时,最直接可参考的就是前一步所收集的历史价差数据。除此之外,还可以纳入以下因素来优化决策:
合约费率
价格波动率(短周期与长周期的波动分布)
市场整体趋势
四、怎样保证实际成交价格接近预期?(执行架构的核心)
分为交易策略和基础两部分:
1. 交易策略(挂单 vs 吃单的组合)
挂单便宜但不保证成交,吃单一定成交但会滑点。
常见的三种执行方式:
方式A:先挂单 A 成交 → 立即在 B 吃单
方式B:先挂单 A 成交 → B 尝试挂单 → 若不成交就切换吃单
方式C:A/B 同时挂单 → 若一边成交另一边未成交 → 立刻取消并吃单
这几种不同的成交方式各有利弊,执行的难度也不同。选择使用哪种成交方式,和交易所的这三点的特性息息相关:
- 交易所的流动性:决定了挂单时的成交速度
- 订单簿的深度:决定了吃单时的滑点
- 交易手续费:决定了策略的行为,吃单/挂单
以 edgeX 为例,
edgeX 的流动性非常好,这一点我相信用过我的对冲脚本的朋友都有体会,比起其他交易所,在edgeX 挂在盘口的订单更容易也更快成交。
edgeX 的订单簿深度非常好,btc和eth的深度可以说是整个市场里最好的,这也是edgeX团队一直在关注的一个重点。
edgeX 的挂单交易手续在所有交易所中是偏低的,使用我的邀请码再加上10%的反佣后的挂单手续费只有0.009%,且根据交易量拿到更高的vip等级后有更低的手续费率。
因此,edgeX 对于上文提到的三种成交方式都适配,给套利提供了很大的空间和灵活性。
2. 基础设施(如何保证执行稳定)
如果想要认真做程序化套利的,必须使用云服务器来保证低延迟与稳定性。
我在这里推荐使用 日本东京地区的AWS,非常不建议用国内公司的服务器(如阿里云、腾讯云)。原因是绝大多数的交易所的服务器都是在东京,且不少交易所用的就是 AWS,能够保证延迟最低且稳定。对于需要设置colocation的更专业的用户来说,也更加友好。
五、风险与对策
在跨所套利中,风险不可避免,但大部分都可以通过系统化的监控与机制来降低。主要包括以下几类:
1. 代码 Bug 导致的对冲风险敞口
这是所有程序化交易者都躲不开的问题,没有人能保证代码没有 bug。我的应对方式是:
- 每次交易完成后自动检查仓位是否一致
- 如发现异常,立即触发警报 + 人工介入
2. 交易所服务器异常 / 数据错误
例如:实际 BTC 价格是 120000,但 API 却返回 119000,可能会导致程序错开、错平仓。
我的防范措施分两层:
若连续超出阈值 → 立即暂停程序 + 警报
若出现非正常亏损 → 警报 + 人工检查
3. 极端行情下的保证金风险
极端行情时,两边仓位需要快速补保证金,而保证金调拨速度完全依赖交易所体验。
edgeX 在这方面表现得非常好:
- 存取款速度极快,基本都是秒到
- 有手机 App,应急调仓比其他 DEX 方便非常多
这对套利者来说重要性非常高。
4. 云服务器安全风险
尽管绝大多数 API 默认不支持提款,但黑客仍可通过自成交洗单的方式盗走资金。
因此必须做到:
- 启用 IP 白名单
- 只使用密钥登录(禁用密码登录)
只要做好这两点,云服务器被攻破的风险几乎趋近于零。
此外我自己写了一个 telegram bot,能够获取实时信息,实时监控,这对于减少风险也非常有帮助。具体功能有:
1. 每一笔成交的实时推送
2. 查看当前仓位信息,包括账户余额、仓位、价格、清算价格,等等
3. 统计过去 x 小时/天 的收益,收益率,交易量,订单数等等
4. 一键减仓(适用于极端行情时维持保证金)
5. 暂停/开启脚本
六、我的交易架构(实际配置)
套利程序在 AWS 东京区的ec2服务器上运行,所有的数据储存在AWS dynamoDB,用 AWS lambda 自动整理每天的数据,并将每天整理的数据汇总并储存回AWS dynamoDB。我通过telegram获取实时信息或是明天整理统计后的数据。
由于我的资金量相对比较大($七位数),目前用多个账号运行三个不同的开仓和关仓的策略,以此减小下单时对订单簿的压力,避免过大的。
目前程序同时监测多个交易所,在下单时,edgex主要以 maker 单为主,因为我在cex有负费率的做市商账户,所以下单比较灵活。
由于时间和安全的考量,我目前只做btc和eth,如果以后有时间,会慢慢地增加其他交易对。
七、遇到的挑战
唯一的挑战就是:edgeX 的 API rate limit 对高频交易者来说稍微有点紧
如果未来 edgeX 能针对高频用户开放更灵活的限频等级、或提供专用的高速通道,整个策略的上限会被进一步打开。
我也相信以 edgeX 团队的节奏,这块一定迟早会优化。
衷心感谢所有认真阅读完这两篇文章的朋友。欢迎任何的意见、建议、批评、探讨、问题、交流。
English Version
In my previous article, I mentioned that most of my profit came from cross-exchange spread arbitrage on @edgeX_exchange. I want to emphasize this again: cross-exchange arbitrage is not a bug, but a feature—a feature that only appears when a trading venue is doing an extremely good job.
You only get real arbitrage opportunities when an exchange has:
strong liquidity
deep order books
a stable and fast matching engine
Only then can spread opportunities be captured in the first place.
People often call Binance “the No.1 exchange in the universe,” and to be fair—
even though I have maker accounts with negative fees on several centralized exchanges, Binance is still the exchange where I generate the most arbitrage volume. So it is not a bug, but a feature.
This article is written for readers from different backgrounds. If you see me explaining concepts that seem very basic to you, please bear with me.
1. The Core Idea Behind the Strategy
Although “algorithmic arbitrage” covers many different strategies, the essence of almost all arbitrage is the same:
Capture a temporary price deviation, and profit from the subsequent mean reversion.
On edgeX, I primarily execute cross-exchange perpetual futures spread arbitrage.
What is Cross-Exchange Perpetual Futures Spread Arbitrage?
It means identifying price discrepancies of the same perpetual futures contract across two exchanges and opening positions like:
Long on Exchange A
Short on Exchange B
This forms a delta-neutral hedged position, which locks in profit when the price spread converges.
Example
Below is the order book from two exchanges at the same time.
The left (black background) is edgeX.
The right (white) is another exchange—let’s call it Exchange B.
When edgeX shows a best bid at 3178.27, and Exchange B shows a best ask at 3177.00, the spread is 1.27.
An arbitrageur can:
short ETH on edgeX
long ETH on Exchange B
This forms a delta ≈ 0 hedged pair with no directional price risk.
When the spread narrows—for example, to 0.10:
| edgeX | 3170.10 |
| Exchange B | 3170.00 |
The profit is 1.27 – 0.10 = 1.17.
2. How to Find Spread Opportunities?
To find meaningful spreads, you must look not only at the spread itself, but more importantly: the change in the spread.
If the spread between ETH on two exchanges stays at $2 forever, it has no value.
But if sometimes it is $2 and sometimes $1, you can open at $2 and close at $1 to capture deterministic mean reversion.
Visualizing historical spread data makes this very clear.
To do this well, you need to:
1. Monitor order books in real time (not candles)
Candles update once per second—they are completely insufficient.
Spread arbitrage requires monitoring every order book update, storing data, cleaning data, and analyzing the distribution of spread movement.
Most exchanges do not provide historical order book data, so you must record it yourself.
Even the format of the exported data matters a lot for later analysis and cross-exchange stitching.
2. The underlying assets must be fully identical
Spread can arise from:
liquidity differences
fee structures
funding rate differences
user base structure
or simply USDT vs USDC pricing
If one exchange uses USDT and another USDC, the “spread” you see may just be the stablecoin premium, not a real arbitrage opportunity across exchanges.
3. When to Open? When to Close? (The part that truly separates good strategies from average ones)
The logic behind opening and closing positions is very similar to the classic “Secretary Problem” or “Wheat-Stalk Picking Problem”:
Limited capital
You can only see the current “stalk” (current spread)
Must decide in real time
After entering, the clock resets—you must again decide the best time to exit
But spread arbitrage adds another dimension: Time efficiency.
Example:
1% profit in 1 hours
2% profit in 10 hours
The first may be better, because you might capture two more 1% opportunities in the remaining nine hours. But sometimes the second is better, if opportunities don’t reappear.
This is why:
Timing of entry and exit is the single most difficult, and most differentiating factor in spread arbitrage.
When designing these algorithms, I primarily rely on:
historical spread data
fee structure
short/long-term volatility
overall market regime and trend
4. How to Ensure Actual Execution Matches Expected Price? (The core of execution architecture)
This consists of two parts:
trade execution logic and infrastructure stability.
1. Trade execution (maker vs taker combinations)
Maker orders are cheap but uncertain.
Taker orders always fill but with slippage.
Common execution patterns:
Method A: Maker on A → once filled, taker on B
Method B: Maker on A → maker on B → fallback to taker if not filled
Method C: Maker both sides → whichever fills first triggers immediate taker on the other side
Which method performs best depends heavily on:
liquidity
order book depth
fee structure
Why edgeX is especially suitable for arbitrage (based on real usage)
Liquidity is excellent — maker orders fill faster than on most DEXs
Order book depth (BTC/ETH) is among the best across all perp DEXs
Fees are low — with my referral + 10% rebate → maker fee is 0.009%
Matching engine stability is outstanding
Because of these characteristics:
All three execution methods work well on edgeX, making it extremely flexible and friendly for arbitrage systems.
2. Infrastructure (ensuring stable execution)
If you are serious about arbitrage, you must use cloud servers for low latency and reliability.
I strongly recommend AWS Tokyo.
Most exchanges host their matching engines in Tokyo—some even directly on AWS.
5. Risks & How to Mitigate Them
Arbitrage carries unavoidable risks, but most can be controlled with proper systems.
1. Code bugs causing unhedged exposure
No developer can guarantee zero bugs. My solution:
- verify position after every trade
- trigger alerts + manual intervention on mismatch
2. Exchange API errors / incorrect market data
Example: real BTC is 120000 but API returns 119000.
Mitigation:
- monitor deviation between expected vs actual execution price
- monitor rolling PnL over the past X minutes
abnormal loss → alert + pause
3. Margin risk during extreme volatility
During extreme moves, both sides may require additional margin.
edgeX performs exceptionally well here:
- deposits/withdrawals are extremely fast (often instant)
- mobile app makes emergency margin management much easier
This matters a lot for arbitrage.
4. Cloud server security
Even if APIs don’t support withdrawals, attackers can still steal funds via wash-trading/self-trading.
To eliminate this risk:
- enable IP whitelisting
- use key-based login only (no passwords)
Do these two things, and compromise risk is almost zero.
Telegram monitoring bot
I also built a custom TG bot helps reduce risk by providing:
- real-time trade notifications
- real-time account metrics (balance, positions, liquidation price, etc.)
- PnL/ROI/trade count/volume statistics for any time window
- one-click reduce-position during extreme markets
- start/pause scripts
6. My Actual Trading Architecture
execution: AWS Tokyo EC2
database: DynamoDB
daily data processing and reporting: AWS Lambda
notifications: Telegram bot
Because I am trading with 7-figure capital, I run three different open/close algorithms across multiple accounts to reduce slippage and distribute order book impact.
The system monitors multiple exchanges simultaneously.
On edgeX, the majority of my orders are maker.
Currently I only trade BTC & ETH due to time and security considerations. More pairs may be added in the future.
7. Challenges Encountered
The only real challenge is:
edgeX’s API rate limits are a bit tight for high-frequency traders.
If edgeX introduces higher rate limits for active traders, the ceiling for this type of strategy would increase significantly.
With edgeX’s current iteration speed, I’m confident this will eventually be improved.
Thank you sincerely to everyone who read both parts of this series.
I welcome any feedback, questions, critiques, or discussion.