The official C++ connector for Binance APIs, designed for backend applications and services written in modern C++.
The connector is a collection of auto-generated CMake components, one per Binance product (for
example spot or wallet). Each component provides typed REST API, WebSocket API and WebSocket
Streams clients built on the shared binance::common library, which handles request signing, HTTP,
WebSocket connection management, errors and utilities.
For source code, issues, and release notes, see the binance-connector-cpp repository on GitHub. The generated API reference is available at binance.github.io/binance-connector-cpp.
Supported environments
- C++20 compiler: GCC 12+, Clang 15+, Apple Clang 15+ or MSVC 19.34+ (Visual Studio 2022 17.4)
- CMake 3.24 or newer and Ninja
- vcpkg with
VCPKG_ROOTset (installs Boost.Asio, Boost.Beast, Boost.JSON, OpenSSL 3 and zlib)
This connector is intended for server-side usage only.
Package structure
Every product is a separate CMake component and target (binance::spot, binance::wallet, ...), so
you build and link only what you need. binance::common is pulled in automatically.
When installing with vcpkg, each product is a feature named like the product with hyphens instead of
underscores (for example copy-trading builds the copy_trading component). Name the connectors
you need, or all for every connector: without features, only binance::common is built.
Typical use cases
- Low-latency trading and execution services
- High-throughput market data ingestion
- Backend services managing accounts, balances, and orders
- Applications consuming WebSocket APIs or WebSocket Streams for real-time updates
Key features
- Support for Binance REST APIs, WebSocket APIs and WebSocket Streams
- Built-in request signing (HMAC, RSA and Ed25519 keys) for authenticated endpoints
- Automatic WebSocket connection management: reconnects with backoff, session renewal, and restored subscriptions
- Strongly typed request and response models
- Support for production, testnet and (where available) demo environments
- One runnable example program per endpoint
Getting started
The repository ships a vcpkg port. Use it as an overlay port after checking out the release you want:
Code
Alternatively, build from source and install only the products you need:
Code
Link it from your CMake project:
Code
Or build it as part of your project with FetchContent (or add_subdirectory). Your project then
provides the dependencies, for example by listing boost-asio, boost-beast, boost-json,
openssl and zlib in its own vcpkg.json:
Code
vcpkg is not required: Boost 1.86+ (Asio, Beast, JSON), OpenSSL 3 and zlib from your system package manager also work. An installed SDK requires at least the Boost version it was built with, and should be used with that same version.
Include only the module you use (rest_api.hpp, websocket_api.hpp or websocket_streams.hpp) to
keep compile times down; <binance/spot/spot.hpp> includes every client of a connector. Each module
has factories for its environments: production, testnet and, where available, demo.
Send a signed request on the Spot testnet (order_test validates the order without placing it):
Code
The example above uses an API secret. Ed25519/RSA keys are also supported by setting
cfg.private_key = common::PrivateKey::from_file("key.pem") instead.
Refer to the examples in the repository (examples/<connector>/) for product-specific REST,
WebSocket API and WebSocket Streams usage.
Notes and best practices
- Store API keys securely using environment variables or a secrets manager
- Prefer WebSocket APIs or Streams for real-time data instead of polling REST endpoints
- Monitor rate limits and endpoint weights when building high-throughput services
- Use testnet environments when developing and validating integrations