I open-sourced a Binance client for .NET 10. It's up to 33x faster per message than the official Binance Rust SDK, has 43x better p99.9 latency, and allocates zero bytes on the hot path.

Whenever I mention this, someone tells me Rust is fast by default and .NET is the managed, garbage-collected compromise. I've been building .NET systems for 25 years and I've never believed that. So I ran a benchmark that's hard to argue with.

GitHub logo Axitor / Trading.Gateway

Binance client for .NET 10, faster than every major Binance client in .NET and Rust. Zero allocations on the hot path, resilience built in, Native AOT ready. REST, WebSocket API, JSON and SBE streams, user data and local order books.

Axitor.Trading.Gateway

Faster than every major Binance client. In .NET, and in Rust.

A Binance gateway for .NET 10, built for trading bots where the slow message, the dead socket and the ban cost real money. Zero allocations on the hot path. Resilience in the core. Native AOT from day one.

CI .NET 10 Native AOT Hot path License

In numbers

  • 33x lower cost per message than the official Binance Rust SDK. 15x lower than Binance.Net.
  • 1.14 million messages per second on a single connection, on a desktop CPU from 2014. Up to 17x the throughput of the Rust SDK, up to 8.6x Binance.Net, even in its high-performance mode.
  • 43x better p99.9 latency than the Rust SDK, 16x better than Binance.Net, on the busiest stream.
  • 0 bytes, 0 GC on the stream hot path. Binance.Net makes up to 285 collections per run, with GC pauses up to 72 ms.
  • 1,500 candles in 3 KB. Binance.Net needs 1.76 MB, the…

How I tested

I didn't compare pieces of my code to pieces of someone else's. I ran whole clients through their public APIs, the same way a trading bot would use them:

  • Axitor.Trading.Gateway, my client, .NET 10, JIT and Native AOT builds
  • Binance.Net 13.8.0, the standard .NET client, in its default mode and its high-performance mode, with its rate limiters turned off
  • binance-sdk 77.1.0, the official Binance Rust connector
  • nautilus-binance 0.66.0, NautilusTrader's Binance adapter, also in Rust

Every client reads the same recorded Binance mainnet traffic (about 640k book tickers and 98k depth updates across 20 symbols) from the same local exchange stub on the same machine. As a baseline I added a raw socket loop that just reads messages and throws them away.

I look at two numbers:

  • Client cost per message. How much time a client adds on top of that raw socket read. The transport is the same for everyone, so this shows what each client's own code costs.
  • Tail latency at live pace. Frames are replayed with their original timing, and I measure from send to handler.

The box is an Intel Core i7-5820K from 2014 on Windows 10, with .NET 10.0.14 and BenchmarkDotNet 0.15.8. Old hardware makes waste easy to see.

Full method, all tables and the fairness rules are in ADR-0018.

The numbers

Axitor Binance.Net binance-sdk (Rust) Nautilus (Rust)
Cost per depth update 0.97 µs 15.0 µs 32.1 µs 20.3 µs
Book ticker, one connection 1.14M msg/s 291k 129k 181k
Depth, one connection 484k msg/s 62.2k 30.1k 46.7k
Book ticker p99.9 at live pace 237 µs 3,911 µs 10,223 µs 7,042 µs
Memory per book ticker 0 B 1,056 B 3,584 B 1,751 B
1,500 candles over REST 638 µs, 3 KB 5.49 ms, 1.76 MB 8.18 ms, 3.97 MB 3.66 ms, 2.91 MB

Against the official Rust SDK that's 33x faster per message, up to 17x faster throughput, 43x better at p99.9, and 1,270x better on memory for 1,500 candles: 3 KB against 3.97 MB.

Against NautilusTrader's adapter it's 21x, 11x and 30x. Against Binance.Net it's 15x per message and up to 8.6x on throughput, even with Binance.Net in its high-performance mode.

Where the Rust SDK loses time

Rust doesn't have a garbage collector, but allocating still isn't free.

binance-sdk is generated from Binance's OpenAPI spec. For every frame it copies the bytes into a string, parses that into a JSON tree, clones the tree twice and turns every number into its own heap string. One book ticker message ends up with 69 heap allocations. You won't see GC pauses, because there is no GC. You pay with time instead, on every malloc and every free, inside every message.

NautilusTrader's adapter does better at 40 allocations per book ticker, but it still copies every frame and sends it through unbounded queues.

Binance.Net, meanwhile, is the .NET stereotype in action. It creates an object for every message: about 1 KB per book ticker and 6 to 10 KB per depth update. Under load that turns into up to 285 garbage collections per run, Gen1 and Gen2 included, with pauses up to 72 ms.

None of that comes from the runtime. It comes from the design. Here's what I did differently.

What I did differently

Parse in place, into flat structs

Messages go straight from the UTF-8 bytes in the socket buffer into a flat struct with public fields. There's no JSON tree, no strings and no reflection anywhere. I wrote the readers by hand, and prices go through an exact fast-path decimal parser (Clinger's fast path). Even the symbol is packed into one UInt128, so BTCUSDT never becomes a string.

public struct BookTickerModel { public Symbol Symbol; public long UpdateId; public long EventTime; public long TransactionTime; public double BidPrice; public double BidQuantity; public double AskPrice; public double AskQuantity; } 

It's a plain struct with public fields, so there are no property getters or defensive copies, and the GC has nothing to track.

No virtual calls on dispatch

Your handler is a readonly struct, and so is the dispatcher. It's generic over both the parser and the handler:

internal readonly struct BinanceDepthDispatcher<TParser, THandler> : IWsStreamDispatcher where TParser : struct, IBinanceDepthParser where THandler : struct, IBinanceDepthHandler { private readonly THandler _handler; private readonly long[] _lastUpdateIds; private readonly DepthLevel[]?[] _bids; private readonly DepthLevel[]?[] _asks; [MethodImpl(MethodImplOptions.AggressiveInlining)] public WsDispatchResult Dispatch(int subscription, ReadOnlySpan<byte> data) { ref DepthLevel[] bids = ref _bids[subscription]!; ref DepthLevel[] asks = ref _asks[subscription]!; if (!TParser.TryParse(data, out DepthUpdateHeader header, ref bids, out int bidCount, ref asks, out int askCount)) { return WsDispatchResult.Unreadable; } ref long lastUpdateId = ref _lastUpdateIds[subscription]; if (header.FinalUpdateId <= lastUpdateId) { return WsDispatchResult.Handled; } lastUpdateId = header.FinalUpdateId; _handler.OnData(subscription, in header, bids.AsSpan(0, bidCount), asks.AsSpan(0, askCount)); return WsDispatchResult.Handled; } } 

When the type arguments are structs, .NET doesn't share generic code between them. The JIT (or the AOT compiler, ahead of time) builds a separate copy of this method for your exact parser and handler. In that copy OnData is a direct call to a known method, and if it's small it gets inlined right into the receive loop. The parser is a static abstract interface member, so there's no parser object either, just a static call resolved at compile time.

The interfaces are there for the compiler to check. At runtime nothing goes through them: no events, no delegates, no virtual calls.

Zero allocations per message

Level buffers are created once per subscription and reused. The order book uses a seqlock, so any thread can read the best price or the whole book without taking a lock and without slowing down the receive loop. Each stream message costs 0 bytes, and the GC simply never runs on the hot path.

Native AOT from the start

The build enforces trimming and AOT compatibility, so reflection is a compile error instead of a surprise in production. The AOT build actually has the best p50 and p99 on every stream I measured: 84 µs and 198 µs on book ticker at live market pace.

Why I care most about the tail

At the median every client looks okay. The network and the kernel cost everyone the same, so the gap there is just 1.2x to 2x.

Bursts are a different story. When the market moves fast, messages come in clumps, and your tail latency is roughly the time per message multiplied by the size of the burst. If a client handles each message 10x faster, it clears a burst 10x faster. That's why at p99.9 on the busiest stream the gap grows to 16x to 43x.

Trading bots rarely lose money on the average message. They lose it on the slow one, and the slow one tends to show up right when the price is moving.

So is Rust slow?

No, and that's not what I'm saying. Rust is a great language. What I'm saying is that the language doesn't decide how fast your code is. Your design does.

A Rust client that allocates 69 times per message will lose to a C# client that allocates nothing. Modern .NET gives you everything you need for that kind of code: structs, spans, generic specialization, static abstract members, InlineArray, SearchValues and Native AOT. Write C# this way and you don't have to settle for "close to Rust". In this benchmark it beat both Rust clients by more than an order of magnitude.

Speed is only half of it

The other half is surviving the failures no benchmark will show you. The gateway has a watchdog that catches sockets that look alive but carry no data, one network gate shared by REST, the WebSocket API and reconnects, and make-before-break connection rotation. On top of that there's a rate limiter that can't get your IP banned, and orders can't be sent twice by accident. I wrote up every one of these decisions as an ADR: the problem, what I decided, what it costs and what I rejected.

Try it

The benchmarks are reproducible. Record your own mainnet data with the recorder in bench/tools, build the Rust competitors, and run one script.

⭐ If you liked this, star the repo

Seriously, it's the best way to help. Stars are how other .NET and trading folks find the project, and they tell me to keep going. Next up: the rest of the Binance API, FIX, and more exchanges on the same core.

👉 Star Axitor.Trading.Gateway on GitHub

I'm Daniel Lebedev, a Principal .NET Architect with 25+ years in low-latency and high-load systems. I make .NET systems faster and more reliable, and I'm open to remote roles and contracts. LinkedIn