Getting started
In this tutorial you add the library to a .NET project, make a few Variant values and
define a first executor.
Install
The library is published to a private NuGet feed as a single package per project:
# Configure the private feed (one-time)
dotnet nuget add source https://nuget.haenerconsulting.com/api/packages/virtufin/nuget/ \
--name virtufin
# Add the packages you need
dotnet add package Virtufin.Core
dotnet add package Virtufin.Base # depends on Core
dotnet add package Virtufin.Data # depends on Core + Base
For a strategy worker that needs the execution algebra and the EAV primitives:
<ItemGroup>
<PackageReference Include="Virtufin.Core" />
<PackageReference Include="Virtufin.Base" />
</ItemGroup>
Target framework
The library targets net11.0. Set your consumer project's TargetFramework accordingly:
<PropertyGroup>
<TargetFramework>net11.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
Hello, Variant
using System.Collections.Generic;
using Virtufin.Data;
// Implicit construction from primitives
Variant v1 = 42; // Int32
Variant v2 = "hello"; // String
Variant v3 = true; // Bool
Variant v4 = new Dictionary<string, IVariant> {
["price"] = (Variant)100.5,
["symbol"] = (Variant)"BTC_USDT",
}; // Dictionary
// Pattern matching to extract: Variant is a C# 15 union over C# types
string result = v1 switch {
int i => $"int: {i}",
string s => $"str: {s}",
_ => "other",
};
Every kind, the getters and the conversions: Variant Type. Reading a variant from a FlatBuffers buffer: FlatBuffers.
Look up a value
An entity's values come from value providers that you add to a registry.
using Virtufin.Core;
var lastTrade = new Attribute<double, string>("last-trade");
var btc = new EntityIdentifier<string>("BTC_USDT");
var registry = new Registry();
registry.AddValueProvider(new DictionaryValueProvider(
new EntityAttributeValueTypeSpecifier<double>(lastTrade))
.Add(btc, lastTrade, 64_250.5));
double? price = registry.GetValue(btc, lastTrade); // 64250.5
How the registry chooses a provider: Core EAV.
Define an executor
using Virtufin.Base.Events.Trade;
using Virtufin.Base.Execution;
public sealed class LimitPriceExecutor
: DeterministicExecutorBase<DeterministicState, RichTradeAction, TradeEvent>
{
public override DeterministicState Initial => DeterministicState.Instance;
protected override (DeterministicState, TradeEvent) Process(
DeterministicState state, RichTradeAction action)
{
// case-by-case fill logic on RichTradeAction
// ...
}
}
For a working example, see the Architecture page or the test projects in the repository.
Next steps
- Architecture — project boundaries, dependency direction, the trait/concrete split
- Core EAV —
IAttribute<V>,IValueProvider, provider combinators, theRegistry - Variant Type — the
Variantdiscriminated union in depth - API Reference — full public API surface