Skip to content

Build names with the naming library

C

using Virtufin.Naming;

// Composes virtufin.core plus every fragment embedded in this assembly
// and the assemblies it references.
var names = NameRegistry.Load(typeof(MyWorker).Assembly);
var book = names.GetEntity("virtufin.venue.binance/orderbook");
var pair = CurrencyPair.Parse("BTC_USDT");

book.Topic("changed", World.Act, pair);   // act.exchange.binance.orderbook.changed.BTC_USDT
book.Key(World.Act, pair);                // act.exchange.binance.orderbook.BTC_USDT
book.Subject(pair);                       // currency_pair/BTC_USDT
book.CeType("changed");                   // com.virtufin.exchange.binance.orderbook.changed

names.TryParseTopic("act.exchange.binance.orderbook.gap.BTC_USDT", out var parsed);
// parsed.Entity.Id == "virtufin.venue.binance/orderbook", parsed.Event == "gap"

names.TryParseCeType("com.virtufin.exchange.binance.candle.closed", out var type);
// type.Event == "closed", type.Bindings: venue = binance (a type names no world or pair)

Python

from virtufin_naming import ACT, CurrencyPair, NameRegistry

names = NameRegistry.load()  # core + fragments of installed packages
book = names.entity("virtufin.venue.binance/orderbook")
pair = CurrencyPair.parse("BTC_USDT")

book.topic("changed", ACT, pair)   # act.exchange.binance.orderbook.changed.BTC_USDT
book.key(ACT, pair)                # act.exchange.binance.orderbook.BTC_USDT
names.parse_topic("act.exchange.binance.orderbook.gap.BTC_USDT").event  # "gap"
names.parse_ce_type("com.virtufin.exchange.binance.candle.closed").bindings  # venue=binance

TypeScript

import { ACT, CurrencyPair, FragmentDocument, NameRegistry } from "@virtufin/naming";

const names = NameRegistry.compose([FragmentDocument.parse(marketYaml), FragmentDocument.parse(binanceYaml)]);
const book = names.entity("virtufin.venue.binance/orderbook");
book.topic("changed", ACT, CurrencyPair.parse("BTC_USDT"));

TypeScript has no fragment discovery: a package that owns fragments exports their YAML text, and the caller composes them. @virtufin/domain-devkit exports virtufin.worlds (NAMING_FRAGMENTS); @virtufin/marketdata-devkit exports the market and venue fragments and composes all of them for you:

import { marketRegistry } from "@virtufin/marketdata-devkit";

const names = marketRegistry(); // core, virtufin.worlds, virtufin.market, every venue
names.entity("virtufin.venue.binance/orderbook").topic("update", ACT, CurrencyPair.parse("BTC_USDT"));

Builders validate their arguments: a lowercase pair, a missing world or an unknown event throws NamingException / NamingError in the caller's process. Infrastructure (api, WorkManager, the WebSocketFeed worker) passes names through unchanged and never validate them.

The model the names follow: Naming; the rules: Naming rules.