Cross-Exchange Crypto Arbitrage with Inventory Rebalancing
Summary
This code example monitors the best bid and ask on two exchanges and compares the two possible buy-on-one, sell-on-the-other spreads. It estimates a trade size from displayed order quantities and available balances, then proceeds only when the spread exceeds an estimate based on trading fees and a configurable coefficient. The paired orders are submitted at the observed prices, and the program polls their statuses, logs completed trade profit, and cancels orders after repeated delays.
After a trade, a separate balancing routine checks whether either exchange has relatively more inventory or cash. It may wait for a price condition before selling or buying to replenish that exchange. The example therefore illustrates both spread capture and inventory management, but provides no backtest or evidence of realized profitability. Its calculations use top-of-book snapshots and do not account fully for latency, changing liquidity, partial fills, transfer constraints, or all fee and operational costs. The code also includes complex order retry and cancellation behavior that would need careful review before deployment.
Key ideas
- The strategy checks both directions of the price spread between two exchanges.
- It sizes paired trades using top-of-book quantity and available balances.
- A fee-based threshold is used to decide whether a quoted spread is large enough to trade.
- Order status polling and cancellation attempt to manage slow or incomplete fills.
- A post-trade routine seeks to restore cash and coin balance across venues.
- The example gives no performance evidence and leaves execution and operational risks unresolved.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.