Xpersona
C

Cross Funding Arb

CLAWHUB · Unverified

跨交易所资金费率套利策略。在费率低的交易所做多永续、费率高的交易所做空永续,Delta-neutral 赚取 funding spread。支持 Hyperliquid + Binance,自动扫描机会、稳定性验证、原子开仓、健康检查、自动切仓。适用于资金费率套利、Delta 中性、跨所套利场景。 Skill: Cross Funding Arb Owner: synththoughts Summary: 跨交易所资金费率套利策略。在费率低的交易所做多永续、费率高的交易所做空永续,Delta-neutral 赚取 funding spread。支持 Hyperliquid + Binance,自动扫描机会、稳定性验证、原子开仓、健康检查、自动切仓。适用于资金费率套利、Delta 中性、跨所套利场景。 Tags: latest:2.8.0 Version history: v2.8.0 | 2026-03-31T13:24:16.722Z | user fix: prevent orphan positions from incomplete close; add tick-level reconciliation check v2.7.0 | 2026-03-31T11:46:47.779Z | user feat: ad

62
Rank
84
Safety
982
Downloads

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 982 downloads reported by the source. Last updated 10/11/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Install and run

Setup complexity: low.

clawhub skill install s17ck4tsqe5hd01dsn49q7dac183kd47:cross-funding-arb
  1. Setup complexity is classified as HIGH. You must provision dedicated cloud infrastructure or an isolated VM. Do not run this directly on your local workstation.
  2. Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-synththoughts-cross-funding-arb/snapshot"

Run-check

$0.02 USD

1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.

Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.

Documentation

CLAWHUB

151,411 characters of source documentation, loaded on request.

Extracted files

5 files captured from the source.

SKILL.md

---
name: cross-funding-arb
description: "跨交易所资金费率套利策略。在费率低的交易所做多永续、费率高的交易所做空永续,Delta-neutral 赚取 funding spread。支持 Hyperliquid + Binance,自动扫描机会、稳定性验证、原子开仓、健康检查、自动切仓。适用于资金费率套利、Delta 中性、跨所套利场景。"
license: Apache-2.0
metadata:
  author: SynthThoughts
  version: "2.8.0"
  pattern: "pipeline"
  steps: "5"
  openclaw:
    requires:
      env:
        - HL_PRIVATE_KEY
        - BINANCE_API_KEY
        - BINANCE_SECRET_KEY
      optional_env:
        - HL_VAULT_ADDRESS
        - HL_TESTNET
        - BINANCE_TESTNET
        - DISCORD_CHANNEL_ID
        - DISCORD_BOT_TOKEN
        - TELEGRAM_BOT_TOKEN
        - TELEGRAM_CHAT_ID
        - STATE_DIR
      bins:
        - python3
    primaryEnv: HL_PRIVATE_KEY
    entrypoint: references/cross_funding.py
    os:
      - darwin
      - linux
---

# Cross-Exchange Funding Rate Arbitrage v2

Cron 驱动的跨交易所资金费率套利机器人。核心思路:**在费率低的交易所做多永续合约,在费率高的交易所做空永续合约**,两腿等量 delta-neutral,赚取 funding spread。

数据源:VarFunding API(预计算的跨所套利机会)。执行层:Hyperliquid SDK(EIP-712 私钥签名)+ Binance Futures API(HMAC 签名)。

每个 tick:扫描机会 → 稳定性验证 → 深度验证 → 开仓/维护 → 报告。

## Architecture

```
VarFunding API ──→ Scanner ──→ 稳定性验证 ──→ 深度验证
                                                  │
                        ┌─────────────────────────┘
                        ↓
              CrossFundingEngine
                   /         \
            HLClient       BinanceClient
            (EIP-712)      (HMAC-SHA256)
                |               |
          Hyperliquid       Binance Futures
          (永续合约)        (USDT-M 永续)
```

## Pipeline: Execution Steps

### Step 0: Prerequisites

- Python 3.10+
- `hyperliquid-python-sdk >= 0.21.0`
- `eth-account >= 0.13.7`
- `python-dotenv >= 1.0.0`
- `requests >= 2.31.0`
- Hyperliquid 账户 + 私钥(主账户或 Agent Wallet)
- Binance Futures 账户 + API Key/Secret(需 USDT-M 交易权限)

### Step 1: Price & Rate Scanning

**Goal**: 从 VarFunding API 获取跨所套利机会

**Actions**:
1. 调用 `VarFundingScanner.fetch_opportunities()` 获取 HL × Binance 的套利机会
2. 过滤:估计 APR ≥ `min_apr_pct`,置信度 ≥ `min_confidence`
3. 按 APR 降序排列,取 Top 5

**Gate**:
- [ ] 至少有一个机会满足 APR 和置信度门槛
- [ ] 无机会 → 输出 `action: idle`,等待下一 tick

### Step 2: Stability Verification

**Goal**: 防止瞬时费率波动导致错误开仓

**Actions**:
1. 将 Top 5 机会记录为费率快照(state 中保留最近 20 条)
2. 按币种分组,检查同一币种的快照数 ≥ `stability_snapshots`(默认 3)
3. 计算 spread 的标准差占比 `std/avg`,须 < `stability_max_std_ratio`(默认 0.3)

**Gate**:
- [ ] 存在至少一个币种通过稳定性检查
- [ ] 未通过 → 输出 `action: accumulating`,继续积累快照

### Step 3: Deep Verification

**Goal**: 独立验证两所实际费率 + 价格差 + 往返成本

**Actions**:
1. 分别从 HL 和 Binance 获取实时费率和中间价
2. 计算实际 spread = short_rate − long_rate
3. 计算价格差异 `price_basis_pct = |hl_price − bn_price| / avg_price`
4. 计算净 APR = gross_annual − round_trip_cost_pct

**Gate** (ALL must pass):
- [ ] 实际 spread > 0
- [ ] 价格差异 < `max_price_basis_pct`(默认 0.5%)
- [ ] 净 APR ≥ `min_apr_pct`(默认 10%)
- [ ] 任一失败 → 输出 `action: rejected` + 原因

### Step 4: Atomic Execution

**Goal**: 原子开仓,先 HL 后 Binance,失败自动回滚

**Actions**:
1. 计算 size:`min(hl_budget, bn_budget) × 0.5 × 0.95 ×

README.md

# Cross-Exchange Funding Rate Arbitrage

跨交易所资金费率套利策略。在费率低的交易所做多永续、费率高的做空,Delta-neutral 赚取 funding spread。

## Features

- **自动扫描**:VarFunding API 实时发现 HL × Binance 套利机会
- **稳定性验证**:多次快照确认费率稳定后才开仓,防止瞬时波动
- **原子开仓**:先 HL 后 Binance,失败自动回滚,无单腿裸露风险
- **健康监控**:Delta 偏差 + Spread 监控 + 双腿一致性检查
- **自动切仓**:Spread 不利时平仓,下一 tick 自动寻找新机会
- **多渠道通知**:Discord embed + Telegram markdown,按 tier 分级推送

## Quick Start

### 1. Install

```bash
npx clawhub install cross-funding-arb --force
pip install -r references/requirements.txt
```

### 2. Configure

```bash
# OpenClaw
cp .env.example ~/.openclaw/skills/cross-funding-arb/references/.env
# 编辑 .env,填入 HL_PRIVATE_KEY, BINANCE_API_KEY, BINANCE_SECRET_KEY

# 可选:调整 references/config.json 中的风控参数
```

### 3. Test

```bash
cd ~/.openclaw/skills/cross-funding-arb/references
set -a && . ./.env && set +a

python3 cross_funding.py status    # 查看当前状态
python3 cross_funding.py tick      # 单次 tick
```

### 4. Deploy

```bash
SKILL_DIR=~/.openclaw/skills/cross-funding-arb/references

# OpenClaw cron
openclaw cron add \
  --name "cross-funding-tick" \
  --cron "*/5 * * * *" \
  --session main \
  --system-event "cd $SKILL_DIR && set -a && . ./.env && set +a && python3 cross_funding.py tick"

# 或系统 crontab
*/5 * * * * cd $SKILL_DIR && set -a && . ./.env && set +a && python3 cross_funding.py tick >> /tmp/cross_funding.log 2>&1
```

## Commands

| Command | Description |
|---|---|
| `tick` | 主循环:扫描 → 验证 → 开仓/维护 |
| `report` | 日报:持仓、PnL、余额、费率 |
| `status` | 当前状态(优先读缓存) |

## Risk Controls

| Control | Description |
|---|---|
| 稳定性验证 | 3+ 快照 + std_ratio < 0.3 |
| 深度验证 | 实时费率 + 价格差 < 0.5% + 净 APR ≥ 10% |
| 保守预算 | min(两所) × 50%,budget=0 自动读取账户余额 |
| 滑点 0.1% | 远低于常规 5%,保护套利利润 |
| HL Margin 重试 | size 减半最多 3 次 |
| 原子回滚 | BN 失败 → 自动平 HL |
| 熔断器 | 连续 5 错 → 冷却 1h |

## Prerequisites

- Python 3.10+
- Hyperliquid 账户 + 私钥
- Binance Futures 账户 + API Key(USDT-M 交易权限)
- 两所均需存入保证金(策略自动检测账户余额)

## License

Apache-2.0

_meta.json

{
  "ownerId": "kn77stv4k3dgdhawvv873dh7w9837caa",
  "slug": "cross-funding-arb",
  "version": "2.8.0",
  "publishedAt": 1774963456722
}

references/config.json

{
  "shared": {
    "max_consecutive_errors": 5,
    "cooldown_after_errors": 3600,
    "min_order_usd": 10
  },
  "cross_funding": {
    "enabled": true,
    "hl_budget_usd": 0,
    "bn_budget_usd": 0,
    "min_apr_pct": 30.0,
    "min_hold_apr_pct": 15.0,
    "min_confidence": "medium",
    "leverage": 1,
    "stability_snapshots": 12,
    "stability_max_std_ratio": 0.2,
    "close_spread_threshold": 0.0003,
    "switch_threshold_apr": 15.0,
    "max_price_basis_pct": 0.5,
    "round_trip_cost_pct": 0.25,
    "max_breakeven_days": 0.5,
    "min_hold_ticks": 96,
    "pnl_stop_loss_pct": -1.0,
    "delta_exit": {
      "enabled": true,
      "neutral_threshold_pct": 2.0,
      "max_defer_ticks": 12,
      "force_close_delta_pct": 15.0
    }
  }
}

references/funding-arb-algorithm.md

# 跨交易所资金费率套利算法详解

## 核心原理

永续合约通过资金费率(Funding Rate)锚定现货价格。不同交易所的费率由各自市场供需决定,经常出现显著差异。本策略利用这个差异:

```
策略 = 在费率低的交易所做多 + 在费率高的交易所做空
净收益 = (short_rate − long_rate) × 3次/天 × 365天 × 名义价值 − 往返成本
```

## 1. 机会扫描

### VarFunding API

VarFunding(varfunding.xyz)是第三方服务,预计算各交易所间的套利机会:

```
GET /api/funding?exchanges=hyperliquid,binance
```

返回的每个 market 包含:
- `baseAsset`:币种(如 FET, RENDER)
- `variational.rate`:参考交易所的费率
- `comparisons[].rate`:对比交易所的费率
- `arbitrageOpportunity`:计算好的方向、spread、估计 APR、置信度

### 过滤规则

```python
if estimated_apr >= min_apr_pct          # 默认 10%
   and confidence >= min_confidence:     # 默认 medium
    # 保留这个机会
```

## 2. 稳定性验证

防止瞬时费率异常导致错误开仓。

### 快照积累

每个 tick 记录 Top 5 机会的快照到 state.rate_snapshots(最多保留 20 条):

```json
{
  "ts": "2026-03-25T10:00:00Z",
  "coin": "FET",
  "spread": 0.0006,
  "estimated_apr": 66.5,
  "long_exchange": "hyperliquid",
  "short_exchange": "binance"
}
```

### 稳定性检查

按币种分组后,对同一币种的所有快照:

```python
count = len(snapshots)        # 需要 >= stability_snapshots (3)
spreads = [s["spread"] for s in snapshots]
avg = mean(spreads)
std = stdev(spreads)
std_ratio = std / abs(avg)    # 需要 < stability_max_std_ratio (0.3)
```

含义:费率差在多个 tick 间保持稳定(变异系数 < 30%),不是偶发异常。

## 3. 深度验证

VarFunding 数据可能滞后,需要独立验证。

### 实时费率

分别从 HL 和 Binance 获取实时 funding rate 和 mid price:

```python
hl_rate = hl_client.get_funding_rate("FET")    # 8h 费率
bn_rate = bn_client.get_funding_rate("FET")
hl_price = hl_client.get_mid_price("FET")
bn_price = bn_client.get_mid_price("FET")
```

### 计算

```python
# 实际 spread(做空方费率 − 做多方费率)
actual_spread = rate_map[short_exchange] - rate_map[long_exchange]

# 年化 APR
gross_annual = actual_spread × 3 × 365 × 100    # 8h 费率 × 3次/天 × 365天

# 价格差异(影响 delta 中性)
price_basis_pct = |hl_price - bn_price| / avg_price × 100

# 净 APR
net_apr = gross_annual - round_trip_cost_pct     # 默认扣 0.12%
```

### 拒绝条件

- `actual_spread <= 0` → 方向反转
- `price_basis_pct > 0.5%` → 两所价格差异过大
- `net_apr < 10%` → 扣成本后不够

## 4. 仓位计算

### Size 计算

```python
budget = min(hl_budget, bn_budget)
conservative = budget × 0.5          # 保守系数 50%(HL 分级保证金对小币要求高)
effective = conservative × 0.95       # 预留 5% 手续费
raw_size = effective × leverage / price

# 两所分别按精度向下取整,取较小值
hl_rounded = hl.round_size(coin, raw_size)
bn_rounded = bn.round_size(coin, raw_size)
final_size = min(hl_rounded, bn_rounded)
```

### 为什么保守系数 50%?

HL 的分级保证金对小币(如 FET, RENDER)要求远高于标准保证金。
budget $300 × leverage 3 = $900 名义,但 HL 可能只允许 $400-500 名义。
预留 50% 安全余量,失败后自动减半重试。

## 5. 原子开仓

### 执行顺序

```
1. HL 设杠杆(cross margin)
2. Binance 设杠杆
3. HL 下单(LIMIT IOC, 滑点 0.1%)
   └→ Insufficient margin? → size ÷ 2,重试(最多 3 次)
4. 等待 1s(防止 rate limit)
5. Binance 下单(LIMIT IOC, 滑点 0.1%)
   └→ 失败? → 回滚 HL(close_position)
```

### 为什么先 HL?

- HL 分级保证金限制更严,更容易失败
- HL 失败时还没开 Binance,损失仅手续费(~$0.05)
- 反过来:先 Binance 成功后 HL 失败,需要平 Binance 多花一次手续费

### 滑点为什么是 0.1%?

套利策略对成本极度敏感。常规交易 5% 滑点在这里会吞噬大部分利润。
0.1% 在流动性好的币上足够成交,同时保护利润。

## 6. PnL 计算

### 基于实际余额

```python
entry_total = entry_hl_balance + entry_bn_balance    # 

Sponsored

Ads related to Cross Funding Arb and adjacent AI workflows.