How aoki-h-jp/funding-rate-arbitrage works
Project type and purpose
• It is an open-source Python library (packaged via setup.py) whose core function is to fetch funding rates and commission data from multiple CEXs, compute divergences/revenue, and provide display utilities.
• It is not a web service or database-backed app; instead it interacts with external APIs of exchanges.
File structure (mapping to logical components)
• funding_rate_arbitrage/
• frarb.py → contains the FundingRateArbitrage class: public API methods (fetch_all_funding_rate, get_commission, fetch_funding_rate_history, display_*).
• __init__.py → package entry point.
• examples/
Contains standalone Python scripts that import the library and demonstrate usage.
• requirements.txt / setup.py
Declare dependencies (e.g., ccxt or similar) and package metadata.
• .github/
CI formatting checks (not part of runtime).
• img/
Illustrations for README (not part of runtime).
README for insights
• Lists supported CEXs (binance, bybit, OKX, gate.io, CoinEx, Bitget).
• Demonstrates three types of operations:
a. Fetching raw data (funding rates & commissions)
b. Fetching historical data
c. Computing/displaying large divergences (single/multi-exchange)
Main components
A. User / Example scripts
– Entry point (e.g. examples/fetch_funding_rate.py)
B. Library Core (funding_rate_arbitrage package)
1. API Adapter Layer
– Adapters or wrappers for each exchange’s REST/WebSocket API (likely via ccxt under the hood).
2. Data Retrieval Module
– Methods that call adapters to fetch funding rates & commissions.
3. Processing Module
– Business logic: calculate divergences, revenue, sorting.
4. Presentation / CLI Module
– display_large_divergence_* and display_one_by_one_* methods that format & print results.
C. External Services
– CEXs: Binance, Bybit, OKX, Gate.io, CoinEx, Bitget.
D. Packaging / CI
– setup.py, requirements.txt for build & distribution; .github/workflows for linting/formatting.
Relationships & data flow
• Example script → invokes → Library Core (FundingRateArbitrage)
→ calls → API Adapter Layer
→ sends HTTP requests → External Exchange APIs
→ returns JSON responses → Data Retrieval Module
→ passes raw data → Processing Module
→ produces computed results → Presentation Module
→ outputs to console (or returns to user code).
• CI Workflow is separate: triggers Formatter.yaml on code pushes.
Architectural patterns & design principles
• Adapter Pattern for exchange integrations (each exchange behind the same interface).
• Single Responsibility: separate retrieval, processing, and display.
• Modular Packaging: one top-level package, clear public API.