A production-style, extensible Python project for building and validating a delta-neutral funding-rate arbitrage workflow.
This repository now includes a complete, runnable implementation focused on:
- deterministic paper-mode simulation,
- configurable opportunity scanning,
- position opening logic for delta-neutral exposure,
- funding settlement simulation and PnL accounting,
- test coverage and reproducible CLI execution.
- Config-driven strategy with strict schema validation.
- Opportunity scan across tracked assets using:
- minimum funding threshold,
- minimum annualized APR filter,
- maximum spot/perp spread filter.
- Position opening with:
- reserve capital handling,
- max-per-asset limits,
- no duplicate openings for already-open symbols.
- Funding settlement cycle:
- recalculates latest funding rates,
- applies funding income to open notional exposure,
- tracks cumulative realized funding PnL.
papermode: fully implemented and tested.livemode: intentionally blocked in this public implementation to avoid unsafe execution without full exchange connector hardening.
- Structured logs to both console and file (
logs/funding.log). - Per-cycle summary including opened positions, skips, and cycle/total funding PnL.
- Unit tests for:
- configuration loading,
- APR annualization,
- cycle execution behavior.
funding-rate-arbitrageur-binance-bybit/
├── arbitrageur/
│ ├── __init__.py
│ ├── config.py # YAML parsing + validation
│ ├── engine.py # strategy and cycle execution
│ ├── exchange.py # exchange gateway + mock market data
│ ├── models.py # domain dataclasses
│ └── reporting.py # logger setup + time helpers
├── tests/
│ ├── test_config.py
│ └── test_engine.py
├── config.example.yaml
├── config.yaml
├── main.py
├── pyproject.toml
├── requirements.txt
└── .gitignore
python3 -m pip install -r requirements.txtUse the provided default config.yaml or copy from example:
cp config.example.yaml config.yamlEdit API keys if needed for future connector work. For current public engine behavior, paper mode does not place real orders.
Run one or more cycles:
python3 main.py --mode paper --cycles 2config.yaml:
exchanges:
binance:
api_key: "CHANGE_ME"
api_secret: "CHANGE_ME"
market_type: "spot"
bybit:
api_key: "CHANGE_ME"
api_secret: "CHANGE_ME"
market_type: "linear"
strategy:
mode: "paper"
funding_rate_threshold: 0.01
min_apr_estimate: 12.0
max_spread_pct: 0.05
hedge_ratio_tolerance: 0.005
settlement_interval_hours: 8
capital:
total_usdt: 10000
max_per_asset_pct: 30
reserve_pct: 10
assets:
tracked:
- "BTC/USDT"
- "ETH/USDT"
- "SOL/USDT"
- "BNB/USDT"
- "ARB/USDT"
logging:
log_file: "logs/funding.log"
console_output: true
cycle_summary: trueINFO | Funding Rate Arbitrageur started | 2026-04-14 08:38:23 UTC
INFO | Mode=paper | Assets=BTC/USDT, ETH/USDT, SOL/USDT, BNB/USDT, ARB/USDT
INFO | ---- Cycle 1/2 ----
INFO | OPEN ETH/USDT qty=... notional=... funding(8h)=...
INFO | Funding realized this cycle: ...
INFO | Funding realized total: ...
- Complete paper-mode cycle engine.
- Config validation and deterministic mock data gateway.
- Capital allocation constraints and cumulative PnL tracking.
- Test suite and execution-ready CLI.
- Real exchange adapters (CCXT or native APIs) with robust retry and idempotency.
- Partial-fill and leg-failure recovery logic.
- Risk controls: drawdown guard, exposure caps by volatility regime.
- Backtesting module using historical funding and basis data.
- Alerting (Telegram/Discord) and dashboard/API service layer.
The project has been executed and validated directly in this environment:
python3 -m pytest -q->3 passedpython3 main.py --mode paper --cycles 2-> successful run with funding PnL output and log generation.
- This repository is educational and research-oriented.
- Funding-rate strategies can lose money due to slippage, spread widening, liquidation mechanics, exchange outages, or failed hedge execution.
- Do not run real capital until live connectors, execution guards, and risk controls are fully audited.
- GitHub: @Rezzecup