Skip to content

Commit f918e8b

Browse files
committed
Document integration with History-Vault.Net and provide examples for seamless data conversion and backtesting workflow.
1 parent c35b3bb commit f918e8b

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,104 @@ await engine.RunAsync(splitData, cts.Token);
163163
164164
---
165165

166+
## Integration with History-Vault.Net
167+
168+
This library works seamlessly with [History-Vault.Net](https://github.com/islero/History-Vault.Net) - a high-performance historical market data storage solution. Both libraries use identical data structures (`SymbolDataV2`, `TimeframeV2`, `CandlestickV2`) with the same properties, differing only in namespaces:
169+
170+
| Library | Namespace |
171+
|---------|-----------|
172+
| **Backtest.Net** | `Backtest.Net.SymbolsData`, `Backtest.Net.Timeframes`, `Backtest.Net.Candlesticks` |
173+
| **History-Vault.Net** | `HistoryVault.Models` |
174+
175+
### Converting Between Types
176+
177+
The easiest way to convert between the two libraries' types is using JSON serialization:
178+
179+
```csharp
180+
using System.Text.Json;
181+
using Backtest.Net.SymbolsData;
182+
183+
// Convert from History-Vault.Net to Backtest.Net
184+
public static List<SymbolDataV2> ConvertFromHistoryVault(List<HistoryVault.Models.SymbolDataV2> historyVaultData)
185+
{
186+
var json = JsonSerializer.Serialize(historyVaultData);
187+
return JsonSerializer.Deserialize<List<SymbolDataV2>>(json)!;
188+
}
189+
190+
// Convert from Backtest.Net to History-Vault.Net
191+
public static List<HistoryVault.Models.SymbolDataV2> ConvertToHistoryVault(List<SymbolDataV2> backtestData)
192+
{
193+
var json = JsonSerializer.Serialize(backtestData);
194+
return JsonSerializer.Deserialize<List<HistoryVault.Models.SymbolDataV2>>(json)!;
195+
}
196+
```
197+
198+
### Complete Workflow Example
199+
200+
```csharp
201+
using Backtest.Net.Engines;
202+
using Backtest.Net.SymbolsData;
203+
using Backtest.Net.SymbolDataSplitters;
204+
using System.Text.Json;
205+
using HistoryVault;
206+
using HistoryVault.Configuration;
207+
using HistoryVault.Models;
208+
using HistoryVault.Storage;
209+
210+
// Configure the vault (paths are auto-detected based on OS and scope)
211+
var options = new HistoryVaultOptions
212+
{
213+
DefaultScope = StorageScope.Local
214+
};
215+
216+
await using var vault = new HistoryVaultStorage(options);
217+
218+
// Save candlestick data
219+
var symbolData = new SymbolDataV2
220+
{
221+
Symbol = "BTCUSDT",
222+
Timeframes = new List<TimeframeV2>
223+
{
224+
new TimeframeV2
225+
{
226+
Timeframe = CandlestickInterval.M1,
227+
Candlesticks = candlesticks // Your candlestick list
228+
}
229+
}
230+
};
231+
232+
// Load candlestick data
233+
var loadOptions = LoadOptions.ForSymbol(
234+
"BTCUSDT",
235+
new DateTime(2025, 1, 1),
236+
new DateTime(2025, 1, 31),
237+
CandlestickInterval.M1
238+
);
239+
240+
var historyData = await vault.LoadAsync(loadOptions);
241+
242+
// 2. Convert to Backtest.Net types via JSON
243+
var json = JsonSerializer.Serialize(historyData);
244+
var backtestData = JsonSerializer.Deserialize<List<SymbolDataV2>>(json)!;
245+
246+
// 3. Run backtest
247+
var splitter = new SymbolDataSplitterV2(daysPerSplit: 30, warmupCandlesCount: 100);
248+
var splitData = await splitter.SplitAsyncV2(backtestData);
249+
250+
var engine = new EngineV10(warmupCandlesCount: 100);
251+
engine.OnTick = async (symbolData) =>
252+
{
253+
// Your strategy logic
254+
};
255+
256+
await engine.RunAsync(splitData);
257+
```
258+
259+
> [!NOTE]
260+
> JSON conversion is the recommended approach as it cleanly handles namespace differences without requiring manual mapping or shared assemblies.
261+
262+
---
263+
166264
## Benchmarks
167265

168266
Performance benchmarks run on Apple M3 Max with .NET 10.0, processing **4 million candlesticks** (1 symbol × 4 timeframes × 1,000,000 candles each):

0 commit comments

Comments
 (0)