|
| 1 | +# Funding Rate Arbitrage Bot 💰📊 |
| 2 | + |
| 3 | +Delta-neutral funding rate arbitrage: **buy spot + short perp** on the Hyperliquid asset with the highest positive funding rate. Collect hourly funding payments while staying market-neutral. |
| 4 | + |
| 5 | +## Strategy |
| 6 | + |
| 7 | +Every hour (matching Hyperliquid's funding interval), the bot: |
| 8 | + |
| 9 | +1. **Scans funding rates** across 13 assets available on both spot and perp markets |
| 10 | +2. **Filters** for positive funding rate (> 0.01%/hr) and minimum volume ($1M 24h) |
| 11 | +3. **Fetches spot orderbook depth** to assess spread and liquidity |
| 12 | +4. **Analyzes candidates via OpenAI** — picks the best asset considering funding magnitude, spot liquidity, spread, and risk |
| 13 | +5. **Opens a delta-neutral position** — 50% spot buy + 50% perp short (1x leverage) |
| 14 | +6. **Monitors hourly** — if funding turns negative, closes everything back to USDC |
| 15 | +7. **Repeats** — waits for the next positive funding opportunity |
| 16 | + |
| 17 | +### Supported Assets |
| 18 | + |
| 19 | +Assets on both Hyperliquid spot and perp markets: |
| 20 | + |
| 21 | +| Spot Ticker | Perp Ticker | Notes | |
| 22 | +|------------|-------------|-------| |
| 23 | +| HYPE | HYPE | Highest liquidity | |
| 24 | +| PUMP | PUMP | High volume | |
| 25 | +| XRP1 | XRP | Major asset | |
| 26 | +| LINK0 | LINK | Major asset | |
| 27 | +| AVAX0 | AVAX | Major asset | |
| 28 | +| AAVE0 | AAVE | Major asset | |
| 29 | +| BNB0 | BNB | Major asset | |
| 30 | +| XMR1 | XMR | Privacy coin | |
| 31 | +| PURR | PURR | HL native | |
| 32 | +| TRUMP | TRUMP | Meme/political | |
| 33 | +| BERA | BERA | Berachain | |
| 34 | +| MON | MON | Monad | |
| 35 | +| ANIME | ANIME | Animecoin | |
| 36 | + |
| 37 | +## Setup |
| 38 | + |
| 39 | +### 1. Configure fintool |
| 40 | + |
| 41 | +```bash |
| 42 | +vim ~/.fintool/config.toml |
| 43 | +``` |
| 44 | + |
| 45 | +Required config: |
| 46 | +```toml |
| 47 | +[wallet] |
| 48 | +private_key = "0x..." |
| 49 | + |
| 50 | +[api_keys] |
| 51 | +openai_api_key = "sk-..." |
| 52 | +``` |
| 53 | + |
| 54 | +### 2. Fund your account |
| 55 | + |
| 56 | +```bash |
| 57 | +fintool deposit USDC --amount 100 --from base |
| 58 | +fintool perp set-mode unified |
| 59 | +``` |
| 60 | + |
| 61 | +### 3. Environment variables (optional overrides) |
| 62 | + |
| 63 | +```bash |
| 64 | +export FINTOOL=/path/to/fintool # default: ./target/release/fintool |
| 65 | +export OPENAI_API_KEY=sk-... # default: from ~/.fintool/config.toml |
| 66 | +``` |
| 67 | + |
| 68 | +### 4. Run (dry run first!) |
| 69 | + |
| 70 | +```bash |
| 71 | +# Dry run — scans and logs what it would do, no trades |
| 72 | +./funding_arb.sh --dry-run |
| 73 | + |
| 74 | +# Live trading |
| 75 | +./funding_arb.sh |
| 76 | + |
| 77 | +# Custom check interval (e.g., every 30 min) |
| 78 | +./funding_arb.sh --interval 1800 |
| 79 | +``` |
| 80 | + |
| 81 | +## Configuration |
| 82 | + |
| 83 | +Tunable parameters at the top of `funding_arb.sh`: |
| 84 | + |
| 85 | +| Parameter | Default | Description | |
| 86 | +|-----------|---------|-------------| |
| 87 | +| `CHECK_INTERVAL` | 3600 | Seconds between checks (1hr = funding interval) | |
| 88 | +| `SLIPPAGE_BPS` | 50 | Limit order buffer in basis points (0.5%) | |
| 89 | +| `MIN_FUNDING` | 0.0001 | Minimum hourly funding rate to enter (0.01%) | |
| 90 | +| `MIN_VOLUME` | 1000000 | Minimum 24h perp volume in USD | |
| 91 | +| `LEVERAGE` | 1 | Perp leverage (1x for delta neutral) | |
| 92 | +| `POSITION_PCT` | 90 | % of available USDC to deploy (10% buffer) | |
| 93 | + |
| 94 | +## Logs |
| 95 | + |
| 96 | +All activity logged to `/tmp/funding_arb.log`. Each cycle logs: |
| 97 | +- Account state (positions, USDC balance) |
| 98 | +- Candidate assets with funding rates and spot liquidity |
| 99 | +- OpenAI analysis and pick reasoning |
| 100 | +- Order execution details |
| 101 | +- Position monitoring results |
| 102 | + |
| 103 | +## How It Works |
| 104 | + |
| 105 | +``` |
| 106 | +┌─────────────────────────────────────────────┐ |
| 107 | +│ Every 1 Hour │ |
| 108 | +├─────────────────────────────────────────────┤ |
| 109 | +│ │ |
| 110 | +│ Has positions? │ |
| 111 | +│ ├─ YES → Check funding rate │ |
| 112 | +│ │ ├─ Still positive → HOLD ✅ │ |
| 113 | +│ │ └─ Turned negative → CLOSE ALL → USDC │ |
| 114 | +│ │ │ |
| 115 | +│ └─ NO → Scan all 13 assets │ |
| 116 | +│ ├─ Filter: funding > 0, vol > $1M │ |
| 117 | +│ ├─ Fetch spot depth & spread │ |
| 118 | +│ ├─ OpenAI picks best candidate │ |
| 119 | +│ └─ Open: buy spot + short perp │ |
| 120 | +│ │ |
| 121 | +└─────────────────────────────────────────────┘ |
| 122 | +``` |
| 123 | + |
| 124 | +## Risk |
| 125 | + |
| 126 | +This is a **delta-neutral** strategy — you're not betting on price direction, just collecting funding. However: |
| 127 | + |
| 128 | +- **Spot-perp basis risk** — prices can diverge temporarily; forced unwind during dislocation = loss |
| 129 | +- **Spot liquidity** — perp markets are much deeper; spot slippage is the main cost |
| 130 | +- **Funding is variable** — rates change hourly and can flip quickly |
| 131 | +- **Rotation cost** — switching assets costs spread + fees on 4 orders (spot sell + perp close + spot buy + perp open) |
| 132 | +- **Smart contract risk** — Hyperliquid is onchain; standard DeFi risks apply |
| 133 | +- This is NOT financial advice |
0 commit comments