Skip to content

Rezzecup/funding-rate-arbitrageur-binance-bybit

Repository files navigation

Funding Rate Arbitrageur (Binance Spot x Bybit Perpetual)

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.

What Is Implemented

Core Engine

  • 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.

Execution Modes

  • paper mode: fully implemented and tested.
  • live mode: intentionally blocked in this public implementation to avoid unsafe execution without full exchange connector hardening.

Logging and Reporting

  • Structured logs to both console and file (logs/funding.log).
  • Per-cycle summary including opened positions, skips, and cycle/total funding PnL.

Testing

  • Unit tests for:
    • configuration loading,
    • APR annualization,
    • cycle execution behavior.

Project Structure

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

Quick Start

1) Install

python3 -m pip install -r requirements.txt

2) Configure

Use the provided default config.yaml or copy from example:

cp config.example.yaml config.yaml

Edit API keys if needed for future connector work. For current public engine behavior, paper mode does not place real orders.

3) Run Paper Mode

Run one or more cycles:

python3 main.py --mode paper --cycles 2

Configuration Reference

config.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: true

Example Output

INFO | 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: ...

Roadmap

Implemented in this version

  • 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.

Next recommended upgrades

  • 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.

Validation Performed

The project has been executed and validated directly in this environment:

  • python3 -m pytest -q -> 3 passed
  • python3 main.py --mode paper --cycles 2 -> successful run with funding PnL output and log generation.

Safety Notes

  • 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.

Contact

About

A delta-neutral bot that shorts futures and buys spot to collect the 8-hour funding fee, targeting 20-50% APR with zero price risk.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages