Skip to content

Commit 7271225

Browse files
author
Serha
committed
Release v4.2.0: Backtesting support and platform documentation
New Features: - BacktestingClientBuilder for running strategies against historical data - Playback control (pause/resume/seek) via IPlaybackControllable interface - Disk and memory caching for repeated backtest runs - File-based offline backtesting (no API key required) - Code parity: same strategy code works for live and backtest Documentation: - Clarified platform support: Windows x64 (NuGet), Linux/macOS (build from source) - Added detailed build instructions for Linux and macOS - Added docs/backtesting_reference.md with complete guide - Updated README.md with backtesting section - Updated Readme_For_Coding_Agents.md with backtesting info - Updated downloads badge to 9.1K
1 parent 903a29d commit 7271225

19 files changed

Lines changed: 3856 additions & 27 deletions

README.md

Lines changed: 133 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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)
368441
dotnet 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
```
374486
databento-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

Readme_For_Coding_Agents.md

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
> **For AI coding agents**: This document is optimized for programmatic consumption by agentic code tools (Claude Code CLI, Cursor, GitHub Copilot Workspace, etc.). Use this as your primary reference when working with the Databento.Client library.
44
5-
**Library**: `Databento.Client` v4.1.1
5+
**Library**: `Databento.Client` v4.2.0
66
**Package**: `dotnet add package Databento.Client`
77
**Runtime**: .NET 8.0 / 9.0
8-
**Platforms**: Windows x64, Linux x64, macOS x64/ARM64
8+
**Platforms**: Windows x64 (NuGet) | Linux/macOS (build from source)
99

1010
---
1111

@@ -21,6 +21,10 @@ What do you need to do?
2121
├─► Query historical market data
2222
│ └─► Use HistoricalClient
2323
24+
├─► Run backtests with identical code to live
25+
│ ├─► From historical API → Use BacktestingClientBuilder.WithTimeRange()
26+
│ └─► From DBN file (offline) → Use BacktestingClientBuilder.WithFileSource()
27+
2428
├─► Get reference data (security master, corporate actions)
2529
│ └─► Use ReferenceClient
2630
@@ -36,12 +40,13 @@ What do you need to do?
3640
## Essential Namespaces
3741

3842
```csharp
39-
using Databento.Client.Builders; // All client builders
43+
using Databento.Client.Builders; // All client builders (including BacktestingClientBuilder)
4044
using Databento.Client.Models; // Record types, enums, Schema, SType
41-
using Databento.Client.Live; // ILiveClient, ILiveBlockingClient
45+
using Databento.Client.Live; // ILiveClient, ILiveBlockingClient, IPlaybackControllable
4246
using Databento.Client.Historical; // IHistoricalClient
4347
using Databento.Client.Reference; // IReferenceClient
4448
using Databento.Client.Resilience; // RetryPolicy, ResilienceOptions
49+
using Databento.Client.DataSources; // PlaybackSpeed, PlaybackController (for backtesting)
4550
using Databento.Client.Dbn; // DbnFileReader, DbnFileWriter
4651
using Databento.Client.Metadata; // ITsSymbolMap, IPitSymbolMap
4752
```
@@ -80,6 +85,25 @@ var client = new ReferenceClientBuilder()
8085
.Build();
8186
```
8287

88+
### BacktestingClient (Historical API)
89+
```csharp
90+
var start = new DateTimeOffset(2025, 1, 15, 9, 30, 0, TimeSpan.FromHours(-5));
91+
var end = start.AddHours(6.5);
92+
93+
await using var client = new BacktestingClientBuilder()
94+
.WithKeyFromEnv()
95+
.WithTimeRange(start, end)
96+
.WithDiskCache() // Cache for repeated runs (optional)
97+
.Build();
98+
```
99+
100+
### BacktestingClient (File-Based, Offline)
101+
```csharp
102+
await using var client = new BacktestingClientBuilder()
103+
.WithFileSource("/path/to/data.dbn") // No API key needed
104+
.Build();
105+
```
106+
83107
---
84108

85109
## Common Operations
@@ -120,7 +144,35 @@ await foreach (var record in client.GetRangeAsync(
120144
}
121145
```
122146

123-
### 3. Symbol Mapping (CRITICAL PATTERN)
147+
### 3. Backtesting (Same Code as Live)
148+
149+
```csharp
150+
// Strategy code works identically with live or backtest clients
151+
async Task RunStrategy(ILiveClient client)
152+
{
153+
await foreach (var record in client.StreamAsync())
154+
{
155+
if (record is TradeMessage trade)
156+
ProcessTrade(trade);
157+
}
158+
}
159+
160+
// Backtest mode
161+
var start = new DateTimeOffset(2025, 1, 15, 9, 30, 0, TimeSpan.FromHours(-5));
162+
var end = start.AddHours(6.5);
163+
164+
await using var client = new BacktestingClientBuilder()
165+
.WithKeyFromEnv()
166+
.WithTimeRange(start, end)
167+
.WithDiskCache() // Cache for repeated runs
168+
.Build();
169+
170+
await client.SubscribeAsync("EQUS.MINI", Schema.Trades, new[] { "NVDA" });
171+
await client.StartAsync();
172+
await RunStrategy(client); // Same code as live!
173+
```
174+
175+
### 4. Symbol Mapping (CRITICAL PATTERN)
124176

125177
**Live clients receive `SymbolMappingMessage` records. Historical API does NOT.**
126178

@@ -691,6 +743,7 @@ var factors = await client.AdjustmentFactors.GetRangeAsync(
691743
## See Also
692744

693745
- [README.md](README.md) - User-facing documentation
746+
- [Backtesting Reference](docs/backtesting_reference.md) - Complete backtesting guide with playback control
694747
- [API_REFERENCE.md](API_REFERENCE.md) - Quick API reference
695748
- [API_Classification.md](API_Classification.md) - Complete API signatures
696749
- [Databento Docs](https://databento.com/docs/) - Official documentation

0 commit comments

Comments
 (0)