How ccxt/binance-python works
Project Type and Purpose
• This is an open-source Python SDK for the Binance cryptocurrency exchange. It provides synchronous, asynchronous, and WebSocket (“WS”) access to Binance’s REST and real-time APIs. It vendors the CCXT library internals under binance/ccxt, ships build/packaging scripts, and offers example clients.
High-Level File-Structure Analysis
• Top-level:
• binance/ – the main SDK package
• build/ – TypeScript build and packaging scripts (npm config, templates)
• examples/ – sample code demonstrating sync, async, WS usage
• setup.py, requirements.txt, pypi-packager.ts – packaging to PyPI
• .github/workflows/ – CI/CD pipelines
• Under binance/ccxt/:
• abstract/ – abstract base exchange definitions
• base/ – core types, errors, throttler, ws client, order-book logic
• async_support/ – async variants of base and ws modules
• binance.py in each layer – concrete adapters implementing Binance-specific endpoints
• static_dependencies/ – vendored third-party libs (ecdsa, ethereum, lark, marshmallow, etc.) to avoid external install
• binance/ccxt/pro/ – “pro” edition overrides
• Build artifacts and version file: build/, ccxt_version
Core README Insights
• Supports three usage modes (Sync, Async, WS).
• Underlying design: a unified “CCXT” interface adapted for Binance, plus direct raw endpoint calls.
• Relies on layered inheritance: abstract → base → concrete → sync/async.
1. User Application (examples or third-party app)
2. SDK Public API Layer (binance/__init__.py, BinanceSync, BinanceAsync, BinanceWs)
3. CCXT Core Layer
• Abstract exchange classes
• Base utilities (throttler, ws client, order-book cache)
• Binance-specific adapter classes
• Async subclasses under async_support/
4. Vendored Static Dependencies (ECDSA, Ethereum ABI, Lark parser, Marshmallow, etc.)
5. Build & Packaging Tools (build/ TS scripts → create PyPI wheel)
6. External Services
• Binance REST API Endpoints
• Binance WebSocket Streams
• CI/CD (GitHub Actions)
• User App → SDK Public API → CCXT Core Layer → External REST/WS
• SDK Core uses Static Dependencies for crypto, parsing, serialization
• Build Scripts → Package Artifact → PyPI
• CI/CD → Build & Test → Deploy to PyPI
c. Architectural Patterns & Principles
• Layered Architecture: separation of Public API, Core CCXT logic, static deps
• Adapter/Template Method: abstract exchange definitions overridden by Binance
• Inheritance & Mix-ins: sync vs async variants sharing base code
• Vendor Isolation: bundling third-party libs in static_dependencies/ to ensure consistent behavior
d. Key Technologies & Frameworks
• Python 3.x
• CCXT library internals (vendored)
• AsyncIO for non-blocking calls
• WebSocket client abstraction
• TypeScript & Node.js for build/packager
• GitHub Actions for CI/CD
• setuptools / pip / PyPI