The official .NET connector for Binance APIs, designed for backend applications and services written in C# and other .NET languages.
The connector is a collection of NuGet packages, one per Binance product (for example Binance.Spot
or Binance.Wallet). Each package provides typed REST API, WebSocket API and WebSocket Streams
clients built on the shared Binance.Common library, which handles configuration, request signing,
errors, logging and connection management.
For source code, issues, and release notes, see the binance-connector-dotnet repository on GitHub. The generated API reference is available at binance.github.io/binance-connector-dotnet.
Upgrading from 4.x?
Binance.Spot5.x replaces the previous HttpClient-based connector. See the Migration Guide.
Supported environments
- .NET 8 or newer (the packages target
net8.0andnet10.0) - Backend .NET applications and services
- Platforms:
win-x64,win-x86,win-arm64,linux-x64,linux-arm64,linux-arm,linux-musl-x64,linux-musl-arm64,osx-x64andosx-arm64
The platform library (libbinance_c) ships inside the packages. On an unsupported platform,
creating the first client throws a BinanceLibraryException.
This connector is intended for server-side usage only.
Package structure
Every product is a separate NuGet package (Binance.<Product>), so you install only what you need.
Binance.Common is pulled in automatically.
Each package has up to three modules, depending on what the product offers: RestApi,
WebSocketApi and WebSocketStreams. Every module has factories for its environments:
Production, Testnet and, where available, Demo.
Every package is versioned independently and follows Semantic Versioning. A connector gets a new version when its API changes.
The optional Binance.Common.DependencyInjection package registers any client with
Microsoft.Extensions.DependencyInjection.
Typical use cases
- Backend services interacting with Binance REST APIs
- Applications consuming WebSocket Streams for real-time data
- Applications using WebSocket APIs for request-response communication
- Trading, account and wallet automation in existing .NET systems
Key features
- Support for Binance REST APIs, WebSocket APIs and WebSocket Streams
- Request signing with HMAC-SHA256, RSA or Ed25519 keys
- Automatic WebSocket connection management: reconnects with backoff, session renewal and restored subscriptions
- Strongly typed request and response models, with exact
decimalvalues - Asynchronous calls with
CancellationTokensupport; stream events are exposed as aChannelReader<T> - Proxies, private CAs and certificate pinning
- A single exception hierarchy (
BinanceException) carrying the Binance error code - Logging through
Microsoft.Extensions.Logging - Trimming and Native AOT support
- One runnable example per endpoint
Getting started
Install the package for the product you need:
Code
Create a client and send a request:
Code
Place a signed order on the Spot testnet (create testnet keys at testnet.binance.vision):
Code
To sign with a private key instead of an HMAC secret, set
PrivateKeyFile = "/path/to/ed25519-private-key.pem" (or PrivateKeyPem) in place of ApiSecret.
Subscribe to a market data stream (public, no credentials):
Code
Dependency injection and logging
Code
BinanceLogging.Configure(loggerFactory) sends the (process-wide) log to ILogger.
Examples
The repository has one runnable example for every endpoint, named after the operation, under
examples/Binance.<Product>.Examples/. For instance, run the Spot klines example with:
Code
Without an argument, the project lists the available examples. The example projects target
net10.0, so running them needs the .NET 10 SDK.
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; REST responses expose the rate-limit headers
- Use testnet environments when developing and validating integrations
- Dispose clients (
using/await using) to release connections