Cross-Market Arbitrage Execution with Balance and Profitability Checks
Summary
This document explains a software component for executing arbitrage between two markets or exchanges. The proposed workflow validates that the selected markets have compatible trading pairs, tracks the buy and sell orders, and estimates profitability after transaction costs. It proceeds only when estimated profitability exceeds a configured minimum. Before creating an executor, the surrounding strategy checks that sufficient balances are available on the buying and selling venues.
The example describes configuring two venues, a trading pair on each, an order amount, and a minimum profitability threshold. It is framed as an implementation overview rather than a trading study: no measured returns, latency data, fill analysis, or historical tests are included. Simultaneous orders and fee-aware checks can help structure execution, but the description does not detail how it handles partial fills, price movement between legs, transfer or network costs, or venue-specific constraints. Those omissions limit what can be concluded about realized arbitrage performance.
Key ideas
- The executor is designed to buy and sell corresponding assets across two markets.
- It validates that the proposed trading pairs are compatible and tracks both orders.
- Profitability estimates account for transaction costs and are compared with a minimum threshold.
- The strategy checks venue balances before creating an executor.
- The example does not provide performance evidence or explain partial-fill and execution risks.
Tags
Full text
# Parameters
**ArbitrageExecutor:** Specialized in controlling profitability between two markets, such as between centralized exchanges (CEX) and decentralized exchanges (DEX), optimizing for arbitrage opportunities.
The [ArbitrageExecutor](https://github.com/hummingbot/hummingbot/blob/master/hummingbot/strategy_v2/executors/arbitrage_executor/arbitrage_executor.py) class is a specialized component within Hummingbot designed for capitalizing on price discrepancies between different markets or exchanges by automating the process of simultaneously executes buy and sell orders on two distinct markets, aiming to exploit arbitrage opportunities for profit.
- **Efficiency**: Automates the complex process of identifying and executing arbitrage opportunities.
- **Speed**: Executes buy and sell orders simultaneously to capture fleeting arbitrage opportunities.
- **Risk Management**: Calculates transaction costs to ensure profitable trades post-fees.
- **Flexibility**: Can be configured for various arbitrage strategies across different markets and exchanges.
### Workflow
Upon initialization, the `ArbitrageExecutor` performs the following actions:
1. **Validation**: Ensures that the proposed arbitrage is valid, with interchangeable trading pairs.
2. **Order Tracking**: Maintains `TrackedOrder` instances for buy and sell orders to monitor their statuses.
3. **Profitability Calculation**: Assesses potential profit, accounting for transaction costs, and executes trades if profitability exceeds the minimum threshold.
### Sample Script
Below, we show illustrative code patterns for `ArbitrageExecutor`. For the current implementation, see [arbitrage_executor.py](https://github.com/hummingbot/hummingbot/blob/master/hummingbot/strategy_v2/executors/arbitrage_executor/arbitrage_executor.py) and the [arbitrage_controller](https://github.com/hummingbot/hummingbot/blob/master/controllers/generic/arbitrage_controller.py) in the repo.
You can define the two markets to arbitrage, the order amount, and the arbitrage profitability threshold.
```python
class ArbitrageWithSmartComponent(ScriptStrategyBase):
# Parameters
exchange_pair_1 = ExchangePair(exchange="binance", trading_pair="MATIC-USDT")
exchange_pair_2 = ExchangePair(exchange="uniswap_polygon_mainnet", trading_pair="WMATIC-USDT")
order_amount = Decimal("50") # in base asset
min_profitability = Decimal("0.004")
```
The `create_arbitrage_executor` method is responsible for creating a new `ArbitrageExecutor`. First, it checks available balances on the buying and selling exchanges to ensure there's enough capital to execute the arbitrage. If so, it creates `ArbitrageExecutor` instances based on the settings above.
```python
def create_arbitrage_executor(self, buying_exchange_pair: ExchangePair, selling_exchange_pair: ExchangePair):
...
arbitrage_config = ArbitrageConfig(
buying_market=buying_exchange_pair,
selling_market=selling_exchange_pair,
order_amount=self.order_amount,
min_profitability=self.min_profitability,
)
```Shown in full with attribution under the source's licence. Licence: Apache-2.0
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.