Binance / OKX Cross-Exchange Spot Spread Hedging Strategy
Binance / OKX Cross-Exchange Spot Spread Hedging Strategy
Notice: This strategy is provided only as a reference for strategy design and code testing. A cross-exchange price gap does not guarantee realizable profit. Asset-transfer routes must be verified and the full workflow should be tested with small live positions before production use.
1. Core Idea: Capture Spread Convergence Between Two Markets
The strategy monitors the Binance and OKX spot markets simultaneously. It buys the same asset on the lower-priced exchange and sells it on the higher-priced exchange, then reverses both legs when the two prices move closer together.
Before entry, three conditions must be confirmed: the asset can be bought on the lower-priced exchange, inventory is available for sale on the higher-priced exchange, and both legs can ultimately be exited. Identical asset names do not guarantee cross-exchange transferability. Different supported networks or asset mappings can cause a spread to persist and prevent an arbitrage cycle from being completed through an ad-hoc transfer.
2. Market Scanning and Entry
The strategy uses GetMarkets() to retrieve spot markets from both exchanges and keeps instruments that are supported by both sides and settled in the selected quote asset. It then uses GetTickers() to retrieve best bid and ask prices in batches and calculates executable spreads in both directions: “Binance higher” and “OKX higher.”
Candidates are ranked from the largest spread to the smallest, with the top ten displayed by default. The table includes both exchanges' quotes, the proposed trading direction, estimated turnover and risk warnings. Instruments above the abnormal-spread threshold or below the turnover threshold remain visible, but are not treated as automatic recommendations.
After selecting an instrument, the user sets the entry spread, exit spread, notional amount per leg and batch size. When the entry condition is reached, the strategy sells in batches on the higher-priced exchange and buys in batches on the lower-priced exchange.
Discover common markets → Compare executable quotes → Rank top spreads → Verify the cause → Set parameters → Enter both legs in batches
Spot assets cannot be sold without available inventory. Before entry, the asset must be pre-positioned on the exchange that may become the higher-priced side, while quote currency must be available on the lower-priced side.
3. Position Management and Exit
During the holding period, the strategy continuously displays the current entry spread, exit spread, filled quantity on each exchange, asset balances, matched position size and live notional value.
If one leg fills while the other does not, the strategy prioritizes the lagging leg to reduce unhedged exposure. After both legs are matched, the plan enters position monitoring. When the exit spread falls to the configured threshold, the strategy sells on the original lower-priced exchange and buys back on the original higher-priced exchange.
There is no fixed holding deadline. The user can force an immediate exit, pause a plan or resume it. Plans are stored persistently. If the strategy restarts during entry or exit, the affected plan is paused until account balances are reviewed.
4. Main Parameters
| Parameter | Default | Purpose |
|---|---|---|
| Quote asset | USDT | Scans common spot instruments settled in this asset |
| Ranking size | 10 | Displays the ten largest executable spreads |
| Scan interval | 3000 ms | Refreshes quotes, plan states and position tables |
| Default entry spread | 3% | Starts entry when the spread reaches this value |
| Default exit spread | 0.5% | Starts exit when the spread falls to this value |
| Default notional per leg | 100 USDT | Planned amount on each exchange leg |
| Default batch size | 20 USDT | Controls each batch order size |
| Limit-price buffer | 0.2% | Improves the probability of limit-order execution |
| Maximum active plans | 5 | Limits concurrently managed instruments |
| Turnover warning level | 100,000 USDT | Flags low-turnover instruments without hiding them |
| Abnormal-spread warning | 50% | Flags unusually large spreads without hiding them |
Actual order size remains subject to balances, minimum quantity, minimum notional, price precision and amount precision on both exchanges. Entry and exit thresholds do not automatically deduct fees, so fee and execution allowances must be included when setting them.
5. Validation Status
The current version has passed JavaScript syntax checks and offline tests covering spread direction, top-ten ranking, interactive parameter parsing and position-quantity calculations. The status tables, market APIs and interactive buttons are implemented for a full FMZ live strategy.
A complete small-size live entry-to-exit cycle on Binance and OKX has not yet been completed. Exchange-specific minimum order rules, account modes, API limits, partial-fill recovery and final costs still require live validation. The strategy currently displays live notional exposure, which is not equivalent to net profit after all costs.
/*
* Binance / OKX 跨所现货价差完整策略(FMZ JavaScript)
* exchanges[0]:Binance 现货;exchanges[1]:OKX 现货。
*
* GetMarkets 取共同市场 -> GetTickers 扫描 -> 显示价差前十
* -> 点击品种设置参数 -> 自动分批开仓 -> 持仓监控 -> 自动分批平仓。
*
* 现货套利需要预先在两边放好资产。程序不会跨链转币,也不会凭空做空现货。
*/
// 未在策略界面添加同名参数时使用这些默认值。
var Quote_currency = typeof Quote_currency === 'undefined' ? 'USDT' : Quote_currency- 1