README
ΒΆ
OpenXAPI - Open eXchange API
Supported Exchanges | Exchange SDKs
Write APIs by Specification.
One Spec. All Exchanges. Any Language.
OpenXAPI provides standardized OpenAPI and AsyncAPI specifications for cryptocurrency exchanges and DeFi protocols, enabling seamless integration and SDK generation across multiple programming languages.
Specifications
REST API - OpenAPI Specification
OpenXAPI is a Go program that automatically generates OpenAPI Specifications from various cryptocurrency exchange API documentation. It enables automatic SDK generation for multiple programming languages using the generated OpenAPI Specs.
WebSocket API - AsyncAPI Specification
OpenXAPI also maintains AsyncAPI Specifications for cryptocurrency exchanges and DeFi protocols. So that you can use the same specification to generate websocket client SDKs for multiple programming languages.
Features
Everything in one place
- Automatic OpenAPI 3.0 specification generation from exchange API docs
- AsyncAPI specification for exchanges and DeFi protocols
- Multi-language SDK generation support
Full coverage
- Support for multiple cryptocurrency exchanges and DeFi protocols
- Configurable API documentation URL management
- Change detection and automatic spec regeneration
- Version history tracking
- Sample file support for offline development and testing
Supported Exchanges
SDKs
| Exchange | Language | Source Code | Package | REST | Websocket | Production Ready |
|---|---|---|---|---|---|---|
![]() |
Go | Github | β | β | β | |
| Python | Github | β | ||||
| Javascript | Github | β | ||||
| Rust | Github | β |
Project Structure
.
βββ bin/ # Compiled binaries
β βββ openxapi # Main executable
βββ cmd/ # Command-line applications
β βββ openxapi/ # Main application entry point
β βββ main.go
βββ configs/ # Configuration files
β βββ config.yaml # Main configuration file
β βββ exchanges/ # Exchange-specific configurations
β βββ binance/ # Binance exchange configs
β β βββ rest.yaml # REST API configuration
β β βββ websocket.yaml # WebSocket API configuration
β βββ okx/ # OKX exchange configs
β βββ restapi.yaml
βββ generator-configs/ # SDK generator configurations
β βββ binance/ # Binance-specific generator configs
β β βββ asyncapi/ # AsyncAPI generator configs (Go WebSocket SDKs)
β β βββ openapi/ # OpenAPI generator configs (REST SDKs)
β β βββ go/ # Go-specific configurations
β β βββ js/ # JavaScript-specific configurations
β β βββ python/ # Python-specific configurations
β β βββ rust/ # Rust-specific configurations
β βββ okx/ # OKX-specific generator configs
βββ history/ # Version history of generated specs (empty)
βββ images/ # Project images and assets
β βββ binance.jpg # Binance logo
β βββ logo.svg # Project logo
βββ internal/ # Private application code
β βββ config/ # Configuration management
β βββ exchange/ # Exchange-specific implementations
β β βββ binance/ # Binance exchange parsers
β β β βββ rest/ # REST API parsers
β β β βββ websocket/ # WebSocket API parsers
β β βββ okx/ # OKX exchange parsers
β β βββ rest/ # REST API parsers
β β βββ websocket/ # WebSocket API parsers
β βββ generator/ # Specification generation logic
β β βββ asyncapi.go # AsyncAPI 3.0 spec generation
β β βββ openapi.go # OpenAPI 3.0 spec generation
β βββ parser/ # Generic parsing interfaces
β βββ rest/ # REST API parsing interfaces
β βββ websocket/ # WebSocket API parsing interfaces
βββ samples/ # Sample API documentation files
β βββ binance/ # Binance documentation samples
β β βββ rest/ # REST API documentation samples
β β β βββ spot/ # Spot trading samples
β β β βββ umfutures/ # USD-M futures samples
β β β βββ cmfutures/ # COIN-M futures samples
β β β βββ options/ # Options samples
β β β βββ pmargin/ # Portfolio margin samples
β β βββ websocket/ # WebSocket API documentation samples
β βββ okx/ # OKX documentation samples
β βββ rest/ # OKX REST API samples
βββ specs/ # Generated specifications
β βββ binance/ # Binance specifications
β β βββ asyncapi/ # AsyncAPI 3.0 specifications
β β β βββ spot.yaml # Spot WebSocket API
β β β βββ spot-streams.yaml # Spot market streams
β β β βββ umfutures.yaml # USD-M futures WebSocket API
β β β βββ umfutures-streams.yaml # USD-M futures streams
β β β βββ cmfutures.yaml # COIN-M futures WebSocket API
β β β βββ cmfutures-streams.yaml # COIN-M futures streams
β β β βββ options.yaml # Options WebSocket API
β β β βββ options-streams.yaml # Options streams
β β β βββ pmargin.yaml # Portfolio margin WebSocket API
β β β βββ {module}/ # Individual operation specs
β β βββ openapi/ # OpenAPI 3.0 specifications
β β βββ spot.yaml # Spot REST API
β β βββ umfutures.yaml # USD-M futures REST API
β β βββ cmfutures.yaml # COIN-M futures REST API
β β βββ options.yaml # Options REST API
β β βββ pmargin.yaml # Portfolio margin REST API
β βββ okx/ # OKX specifications
β βββ openapi/
β βββ rest.yaml # OKX REST API
βββ templates/ # Template files for SDK generation
β βββ binance/ # Binance-specific templates
β β βββ asyncapi/ # AsyncAPI/WebSocket SDK templates
β β β βββ go/ # Go WebSocket SDK templates (React-based)
β β βββ openapi/ # OpenAPI/REST SDK templates
β β βββ go/ # Go REST SDK templates (Mustache)
β β βββ js/ # JavaScript REST SDK templates (Mustache)
β β βββ python/ # Python REST SDK templates (Mustache)
β β βββ rust/ # Rust REST SDK templates (Mustache)
β βββ okx/ # OKX-specific templates
β βββ openapi/
βββ go.mod # Go module definition
βββ go.sum # Go module dependencies checksum
βββ Makefile # Build and development commands
βββ CLAUDE.md # Development guide and project instructions
βββ LICENSE # Project license
Key Directories and Their Purposes
Core Application
cmd/: Contains the main application entry pointsinternal/: Houses the core application logicconfig/: Manages application configurationexchange/: Exchange-specific implementations and parsersgenerator/: OpenAPI 3.0 and AsyncAPI 3.0 specification generation logicparser/: Generic parsing interfaces for REST and WebSocket APIs
Configuration and Setup
configs/: Configuration files for exchange URLs and settingsexchanges/: Exchange-specific API configuration files
generator-configs/: SDK generator-specific configurations for different languagestemplates/: Template files used in SDK generation- REST SDKs use Mustache templates
- WebSocket SDKs use React templates
Generated Content
specs/: Generated OpenAPI 3.0 and AsyncAPI 3.0 specificationsopenapi/: REST API specificationsasyncapi/: WebSocket API specifications with separate files for API operations and market streams
samples/: Cached webpage samples of exchange documentation for offline developmenthistory/: Version history tracking (currently unused)
Development and Build
bin/: Compiled executable binariesimages/: Project logos and visual assets
Getting Started
Prerequisites
- Go 1.21 or higher
- Git
Installation
- Clone the repository:
git clone https://github.com/openxapi/openxapi.git
cd openxapi
- Install dependencies:
go mod download
- Build the project:
make build
Working with Specifications
OpenXAPI generates two types of specifications for cryptocurrency exchange APIs:
- OpenAPI 3.0 Specifications for REST API endpoints
- AsyncAPI 3.0 Specifications for WebSocket API endpoints
Both specifications are automatically generated from exchange API documentation and can be used to generate SDKs for multiple programming languages.
Generate OpenAPI Specifications (REST APIs)
OpenAPI specifications define REST API endpoints, request/response schemas, authentication methods, and parameter validation rules.
Initial Generation
- Configure exchange API documentation URLs in
configs/exchanges/{exchange}/rest.yaml - Generate specifications for all exchanges:
./openxapi
- Generate specifications for a specific exchange:
make generate-rest-spec EXCHANGE=binance
NOTE: Initial generation scrapes live exchange documentation, which may take several minutes. The process saves documentation samples locally for faster subsequent generations.
Subsequent Generations (Recommended)
Use cached sample files for faster, offline generation:
# Generate all specifications
./openxapi
# Generate specific exchange REST specifications
make generate-rest-spec EXCHANGE=binance
# Generate all specifications for specific exchange
make generate-spec EXCHANGE=binance
Generated Files Structure
specs/
βββ {exchange}/
βββ openapi/
βββ {module}.yaml # Combined specification
βββ {module}/ # Individual endpoint specifications
βββ endpoint1.yaml
βββ endpoint2.yaml
βββ ...
Example for Binance:
specs/binance/openapi/
βββ spot.yaml # Combined Spot REST API
βββ umfutures.yaml # Combined USD-M Futures REST API
βββ cmfutures.yaml # Combined COIN-M Futures REST API
βββ options.yaml # Combined Options REST API
βββ pmargin.yaml # Combined Portfolio Margin REST API
βββ spot/ # Individual Spot endpoints
βββ get_api_v3_account.yaml
βββ post_api_v3_order.yaml
βββ ...
Validation
Validate generated OpenAPI specifications:
# Validate specific exchange REST specifications
make validate-rest-spec EXCHANGE=binance
# Validate using external tools
swagger-codegen validate -i specs/binance/openapi/spot.yaml
Manual Maintenance
When automatic generation produces incorrect specifications:
-
Identify the problematic endpoint:
# Find the specific endpoint file ls specs/binance/openapi/spot/ -
Protect from automatic regeneration: Edit
configs/exchanges/binance/rest.yaml:protected_endpoints: - "DELETE /api/v3/openOrders" -
Manually edit the specification:
# Edit the endpoint specification vim specs/binance/openapi/spot/delete_api_v3_openOrders.yaml -
Regenerate combined specification:
make generate-rest-spec EXCHANGE=binance
Generate AsyncAPI Specifications (WebSocket APIs)
AsyncAPI specifications define WebSocket operations, message schemas, authentication, and real-time event handling for streaming APIs.
WebSocket API Types
OpenXAPI generates two types of WebSocket specifications:
- API Operations: Request/response operations (user data streams, account operations)
- Market Streams: Real-time market data streams (price feeds, order books, trades)
Initial Generation
- Configure WebSocket documentation URLs in
configs/exchanges/{exchange}/websocket.yaml - Generate WebSocket specifications:
# Generate all WebSocket specifications
make generate-ws-spec EXCHANGE=binance
# Generate all specifications (REST + WebSocket)
make generate-spec EXCHANGE=binance
Generated Files Structure
specs/
βββ {exchange}/
βββ asyncapi/
βββ {module}.yaml # API operations specification
βββ {module}-streams.yaml # Market streams specification
βββ {module}/ # Individual operation specifications
βββ operation1.yaml
βββ operation2.yaml
βββ ...
Example for Binance:
specs/binance/asyncapi/
βββ spot.yaml # Spot WebSocket API operations
βββ spot-streams.yaml # Spot market data streams
βββ umfutures.yaml # USD-M Futures WebSocket API
βββ umfutures-streams.yaml # USD-M Futures market streams
βββ cmfutures.yaml # COIN-M Futures WebSocket API
βββ cmfutures-streams.yaml # COIN-M Futures market streams
βββ options.yaml # Options WebSocket API
βββ options-streams.yaml # Options market streams
βββ pmargin.yaml # Portfolio Margin WebSocket API
βββ spot/ # Individual Spot operations
βββ session.logon.yaml
βββ order.place.yaml
βββ userDataStream.subscribe.yaml
βββ ...
WebSocket Specification Features
API Operations ({module}.yaml):
- Authentication methods (HMAC-SHA256, RSA, Ed25519)
- Request/response message schemas
- Account and trading operations
- Error handling and status codes
Websocket Streams ({module}-streams.yaml):
- Market streams and user data streams management
- Real-time price feeds
- Order book updates
- Trade streams
- Kline/candlestick data
- Ticker information
- Market depth streams
Validation
Validate generated AsyncAPI specifications:
# Validate specific exchange WebSocket specifications
make validate-ws-spec EXCHANGE=binance
# Validate using AsyncAPI CLI
asyncapi validate specs/binance/asyncapi/spot.yaml
Configuration Management
REST API Configuration (configs/exchanges/{exchange}/rest.yaml):
name: "binance_spot"
version: "1.0.0"
docs:
- type: "rest"
servers: ["https://api.binance.com"]
url_groups:
- name: "spot_trading"
urls: ["https://developers.binance.com/docs/..."]
protected_endpoints: ["POST /api/v3/order"]
WebSocket API Configuration (configs/exchanges/{exchange}/websocket.yaml):
name: "binance_websocket"
version: "1.0.0"
docs:
- type: "spot"
servers:
mainnet: ["wss://stream.binance.com:9443"]
testnet: ["wss://testnet.binance.vision"]
url_groups:
- name: "spot_websocket"
doc_type: "spot"
urls: ["https://developers.binance.com/docs/..."]
Generate SDKs from Specifications
REST SDK Generation (OpenAPI)
Generate REST SDKs using OpenAPI Generator:
# Generate Go SDK for Binance Spot REST API
make generate-rest-sdk EXCHANGE=binance LANGUAGE=go OUTPUT_DIR=../binance-go/rest
# Generate Python SDK
make generate-rest-sdk EXCHANGE=binance LANGUAGE=python OUTPUT_DIR=../binance-py/rest
# Generate JavaScript SDK
make generate-rest-sdk EXCHANGE=binance LANGUAGE=js OUTPUT_DIR=../binance-js/rest
# Generate Rust SDK
make generate-rest-sdk EXCHANGE=binance LANGUAGE=rust OUTPUT_DIR=../binance-rs/rest
WebSocket SDK Generation (AsyncAPI)
Generate WebSocket SDKs using AsyncAPI Generator:
# Generate Go WebSocket SDK for Binance
make generate-ws-sdk EXCHANGE=binance LANGUAGE=go OUTPUT_DIR=../binance-go/ws
# Generate for specific module
make generate-ws-sdk EXCHANGE=binance MODULE=spot LANGUAGE=go OUTPUT_DIR=../binance-go/ws/spot
Supported Languages and Exchanges
REST SDKs (OpenAPI):
- Languages:
go,python,js,rust - Exchanges:
binance - Template Engine: Mustache
WebSocket SDKs (AsyncAPI):
- Languages:
go(more languages coming soon) - Exchanges:
binance - Template Engine: React with TypeScript
Customizing Generated SDKs
For REST SDKs:
- Edit Mustache templates in
templates/{exchange}/openapi/{language}/ - Regenerate SDK:
make generate-rest-sdk EXCHANGE=binance LANGUAGE=go OUTPUT_DIR=../binance-go/rest
For WebSocket SDKs:
- Edit React templates in
templates/{exchange}/asyncapi/{language}/ - Regenerate SDK:
make generate-ws-sdk EXCHANGE=binance LANGUAGE=go OUTPUT_DIR=../binance-go/ws
SDK Features
REST SDK Features:
- Type-safe request/response models
- Automatic request signing and authentication
- Rate limiting and retry mechanisms
- Comprehensive error handling
- Debug logging and request tracing
WebSocket SDK Features:
- Automatic connection management and reconnection
- Message type safety with generated models
- Authentication handling (HMAC, RSA, Ed25519)
- Stream subscription management
- Event-driven architecture with callbacks
- Built-in error handling and recovery
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Make sure to make format && make test before committing your changes.
License
This project is licensed under the MIT License - see the LICENSE file for details.
