11# databento-dotnet
22
3- [ ![ NuGet] ( https://img.shields.io/badge/NuGet-v4.1.1 -blue )] ( https://www.nuget.org/packages/Databento.Client )
4- [ ![ Downloads] ( https://img.shields.io/badge/Downloads-6.4K -blue )] ( https://www.nuget.org/packages/Databento.Client )
3+ [ ![ NuGet] ( https://img.shields.io/badge/NuGet-v4.2.0 -blue )] ( https://www.nuget.org/packages/Databento.Client )
4+ [ ![ Downloads] ( https://img.shields.io/badge/Downloads-9.1K -blue )] ( https://www.nuget.org/packages/Databento.Client )
55[ ![ .NET] ( https://img.shields.io/badge/.NET-8.0%20%7C%209.0-purple )] ( https://dotnet.microsoft.com/ )
66[ ![ License] ( https://img.shields.io/badge/License-Apache%202.0-blue.svg )] ( LICENSE )
77
@@ -13,6 +13,7 @@ A high-performance .NET client for [Databento](https://databento.com) market dat
1313- [ Quick Start] ( #quick-start )
1414- [ Features] ( #features )
1515- [ Symbol Mapping] ( #symbol-mapping )
16+ - [ Backtesting] ( #backtesting )
1617- [ API Reference] ( #api-reference )
1718- [ Building from Source] ( #building-from-source )
1819- [ Troubleshooting] ( #troubleshooting )
@@ -26,7 +27,7 @@ dotnet add package Databento.Client
2627
2728** Requirements:** .NET 8.0 or .NET 9.0
2829
29- ** Platforms:** Windows ( x64), Linux (x64), macOS (x64/ARM64 )
30+ ** Platforms:** Windows x64 (NuGet package) | Linux/macOS ( [ build from source ] ( #building-from-source ) )
3031
3132## Quick Start
3233
@@ -96,11 +97,11 @@ await foreach (var record in client.GetRangeAsync(
9697| ---------| -------------|
9798| ** Live Streaming** | Real-time market data with async/await and IAsyncEnumerable |
9899| ** Historical Queries** | Time-range queries with efficient streaming |
100+ | ** Backtesting** | Run strategies against historical data with identical code to live |
99101| ** Auto-Reconnect** | Configurable retry policies with exponential backoff |
100- | ** All Record Types** | Full support for all 16 DBN record types |
102+ | ** All Record Types** | Full support for all 20 DBN record types |
101103| ** Symbol Mapping** | Resolve InstrumentId to ticker symbols |
102104| ** Reference Data** | SecurityMaster, CorporateActions, AdjustmentFactors |
103- | ** Cross-Platform** | Windows, Linux, macOS |
104105| ** High Performance** | Built on databento-cpp with native P/Invoke |
105106
106107### Supported Schemas (20)
@@ -228,6 +229,81 @@ await foreach (var record in client.GetRangeAsync(
228229}
229230```
230231
232+ ## Backtesting
233+
234+ Run your trading strategies against historical data using the same code you use for live trading.
235+
236+ ### Historical API Backtesting
237+
238+ ``` csharp
239+ using Databento .Client .Builders ;
240+ using Databento .Client .Models ;
241+
242+ var start = new DateTimeOffset (2025 , 1 , 15 , 9 , 30 , 0 , TimeSpan .FromHours (- 5 ));
243+ var end = start .AddHours (6 . 5 ); // Full trading day
244+
245+ await using var client = new BacktestingClientBuilder ()
246+ .WithKeyFromEnv ()
247+ .WithTimeRange (start , end )
248+ .WithDiskCache () // Cache for repeated runs
249+ .Build ();
250+
251+ await client .SubscribeAsync (" EQUS.MINI" , Schema .Trades , new [] { " NVDA" , " AAPL" });
252+ await client .StartAsync ();
253+
254+ await foreach (var record in client .StreamAsync ())
255+ {
256+ if (record is TradeMessage trade )
257+ Console .WriteLine ($" {trade .Timestamp }: {trade .PriceDecimal }" );
258+ }
259+ ```
260+
261+ ### File-Based Backtesting (Offline)
262+
263+ ``` csharp
264+ // No API key needed - use pre-downloaded DBN files
265+ await using var client = new BacktestingClientBuilder ()
266+ .WithFileSource (" /path/to/historical_data.dbn" )
267+ .Build ();
268+
269+ await client .StartAsync ();
270+
271+ await foreach (var record in client .StreamAsync ())
272+ {
273+ if (record is TradeMessage trade )
274+ Console .WriteLine ($" {trade .PriceDecimal }" );
275+ }
276+ ```
277+
278+ ### Code Parity with Live Trading
279+
280+ ``` csharp
281+ // Your strategy works identically with live or backtest clients
282+ async Task RunStrategy (ILiveClient client )
283+ {
284+ await foreach (var record in client .StreamAsync ())
285+ {
286+ if (record is TradeMessage trade )
287+ ProcessTrade (trade );
288+ }
289+ }
290+
291+ // Backtest mode
292+ await using var backtestClient = new BacktestingClientBuilder ()
293+ .WithKeyFromEnv ()
294+ .WithTimeRange (start , end )
295+ .Build ();
296+ await RunStrategy (backtestClient );
297+
298+ // Live mode - same strategy code!
299+ await using var liveClient = new LiveClientBuilder ()
300+ .WithKeyFromEnv ()
301+ .Build ();
302+ await RunStrategy (liveClient );
303+ ```
304+
305+ > ** See [ Backtesting Reference] ( docs/backtesting_reference.md ) ** for playback control, caching options, and complete examples.
306+
231307## API Reference
232308
233309### LiveClient
@@ -351,30 +427,66 @@ await using var client = new LiveClientBuilder()
351427
352428## Building from Source
353429
354- ### Prerequisites
430+ > ** Note: ** The NuGet package includes pre-built native libraries for ** Windows x64 only ** . Linux and macOS users must build from source.
355431
356- - .NET 8 SDK or later
357- - CMake 3.24+
358- - C++17 compiler (VS 2019+, GCC 9+, Clang 10+)
432+ ### Windows
359433
360- ### Build
434+ ``` powershell
435+ # Prerequisites: .NET 8 SDK, CMake 3.24+, Visual Studio 2019+
361436
362- ``` bash
363437# Full build (native + .NET)
364- ./build/build-all.ps1 -Configuration Release # Windows
365- ./build/build-all.sh --configuration Release # Linux/macOS
438+ .\build\build-all.ps1 -Configuration Release
366439
367440# .NET only (if native library already built)
368441dotnet build -c Release
369442```
370443
444+ ### Linux
445+
446+ ``` bash
447+ # Prerequisites
448+ sudo apt-get update
449+ sudo apt-get install -y cmake build-essential libssl-dev libzstd-dev
450+
451+ # Clone and build
452+ git clone https://github.com/Alparse/databento-dotnet.git
453+ cd databento-dotnet
454+
455+ # Build native library
456+ ./build/build-native.sh --configuration Release
457+
458+ # Build .NET
459+ dotnet build -c Release
460+
461+ # Native library output: src/Databento.Interop/runtimes/linux-x64/native/libdatabento_native.so
462+ ```
463+
464+ ### macOS
465+
466+ ``` bash
467+ # Prerequisites
468+ brew install cmake openssl@3 zstd
469+
470+ # Clone and build
471+ git clone https://github.com/Alparse/databento-dotnet.git
472+ cd databento-dotnet
473+
474+ # Build native library
475+ ./build/build-native.sh --configuration Release
476+
477+ # Build .NET
478+ dotnet build -c Release
479+
480+ # Native library output: src/Databento.Interop/runtimes/osx-*/native/libdatabento_native.dylib
481+ ```
482+
371483### Project Structure
372484
373485```
374486databento-dotnet/
375487├── src/
376488│ ├── Databento.Client/ # High-level .NET API
377- │ ├── Databento.Interop/ # P/Invoke layer
489+ │ ├── Databento.Interop/ # P/Invoke layer + runtimes/
378490│ └── Databento.Native/ # C++ wrapper (CMake)
379491├── examples/ # 25+ working examples
380492└── docs/ # Additional documentation
@@ -384,11 +496,14 @@ databento-dotnet/
384496
385497### DllNotFoundException
386498
387- The NuGet package includes all dependencies. If you still see this error:
499+ The NuGet package includes native libraries for ** Windows x64 only** .
500+
501+ ** On Windows:**
502+ 1 . Try ` dotnet restore --force `
503+ 2 . Install [ VC++ 2022 Redistributable] ( https://aka.ms/vs/17/release/vc_redist.x64.exe )
388504
389- 1 . Ensure you're on a supported platform (Windows x64, Linux x64, macOS x64/ARM64)
390- 2 . Try ` dotnet restore --force `
391- 3 . On Windows, install [ VC++ 2022 Redistributable] ( https://aka.ms/vs/17/release/vc_redist.x64.exe )
505+ ** On Linux/macOS:**
506+ - You must [ build from source] ( #building-from-source ) - native libraries are not included in the NuGet package
392507
393508### Connection Issues
394509
0 commit comments