find_arbitrage_pairs
Identify cryptocurrency arbitrage opportunities by analyzing funding rates, trading volume, and directional stability on Binance.
Instructions
Find arbitrage pairs based on funding rate, volume, and rate direction stability.
Args: min_funding_rate: Minimum funding rate to qualify. min_avg_volume: Minimum 24hr volume in USDT. history_days: How many days of history to analyze. stability_threshold: Minimum proportion of funding rates in same direction.
Returns: List of qualifying arbitrage opportunities.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| min_funding_rate | No | ||
| min_avg_volume | No | ||
| history_days | No | ||
| stability_threshold | No |
Implementation Reference
- binance.py:311-376 (handler)The handler function implementing the 'find_arbitrage_pairs' tool logic. It fetches funding rates and volumes from Binance futures API, filters pairs based on criteria like minimum funding rate, volume, and stability of rate direction, and returns sorted list of opportunities. The @mcp.tool() decorator registers it as an MCP tool.@mcp.tool() def find_arbitrage_pairs( min_funding_rate: float = 0.0005, min_avg_volume: float = 1_000_000, history_days: int = 7, stability_threshold: float = 0.8 ) -> list[dict[str, Any]]: """ Find arbitrage pairs based on funding rate, volume, and rate direction stability. Args: min_funding_rate: Minimum funding rate to qualify. min_avg_volume: Minimum 24hr volume in USDT. history_days: How many days of history to analyze. stability_threshold: Minimum proportion of funding rates in same direction. Returns: List of qualifying arbitrage opportunities. """ current_url = "https://fapi.binance.com/fapi/v1/premiumIndex" history_url = "https://fapi.binance.com/fapi/v1/fundingRate" candidates = [] response = requests.get(current_url) if response.status_code != 200: return [{"error": "Failed to fetch current funding data"}] for pair in response.json(): try: symbol = pair["symbol"] current_rate = float(pair["lastFundingRate"]) if abs(current_rate) < min_funding_rate: continue history_params = { "symbol": symbol, "limit": history_days * 3 } history_resp = requests.get(history_url, params=history_params) if history_resp.status_code != 200: continue rates = [float(x["fundingRate"]) for x in history_resp.json()] same_dir = sum(1 for r in rates if (r > 0 and current_rate > 0) or (r < 0 and current_rate < 0)) stability = same_dir / len(rates) if rates else 0 ticker_url = f"https://fapi.binance.com/fapi/v1/ticker/24hr?symbol={symbol}" ticker_resp = requests.get(ticker_url) if ticker_resp.status_code != 200: continue volume = float(ticker_resp.json().get("quoteVolume", 0)) if volume > min_avg_volume and stability >= stability_threshold: candidates.append({ "symbol": symbol, "current_funding_rate": current_rate, "avg_volume": volume, "stability": round(stability, 2) }) except Exception: continue return sorted(candidates, key=lambda x: -abs(x["current_funding_rate"]))