Skip to main content

Arbitrage Finder

Goal: Create a script that compares the price of a single asset (e.g., TON) on xRocket with another external exchange to find potential arbitrage opportunities.

Key xRocket API Features Used:

  • Public Market Data Endpoint: GET /api/v1/ticker/24h
  • External Exchange APIs: Using requests to fetch data from another platform (e.g., Binance, OKX).
danger

Automated arbitrage execution carries significant financial risk. Network latency, withdrawal processing times, and sudden price swings can turn a profitable opportunity into a loss. Start with notification-only mode and thoroughly test before enabling any automated trading.

Workflow:

  1. Data Fetching: The script fetches the current price for TON-USDT from the xRocket API and the corresponding pair from the external API simultaneously.
  2. Price Comparison: It compares the "ask" price on one exchange with the "bid" price on the other.
  3. Opportunity Calculation: Calculates the potential profit margin, factoring in withdrawal fees from the sending exchange and trading fees on both sides.
  4. Notification (or Execution): If the calculated profit margin exceeds a preset threshold (e.g., >1%), it sends a notification to the developer (or potentially triggers an automated trade, which is advanced and risky).
warning

Always account for all costs: trading fees on both exchanges, withdrawal fees, deposit confirmation times, and potential slippage. A spread that looks profitable on paper may not cover these costs in practice.