DpExchange.Core.CanonicalPair (DpExchangeCore v0.1.4)

Copy Markdown View Source

The generic, venue-agnostic symbol normaliser.

Canonical form is BASE-QUOTE, uppercase, dash-separated (BTC-USD). This module holds no venue-specific knowledge — it converts given a mapping that each venue package declares inside itself. That split is what keeps Core free of venue facts: the venue supplies its separator, quote list and asset aliases; the string surgery lives here, once.

Mapping

%{
  sep: "-" | "",                 # native separator
  quotes: ["USDC", "USD", ...],  # known quote assets, LONGEST-FIRST
  asset_aliases: %{"XBT" => "BTC"} # exchange base code → canonical (optional)
}

Invariant

to_canonical(m, to_exchange(m, p)) == p for every pair. The conformance suite asserts this against each venue's own mapping, so a venue whose two directions disagree fails before it ships.

Summary

Functions

Exchange-native symbol → canonical BASE-QUOTE, per the connector's mapping. Unparseable / already-dashed input → uppercased input (never dropped).

Canonical BASE-QUOTE → exchange-native, per the connector's mapping.

Types

mapping()

@type mapping() :: %{
  :sep => String.t(),
  :quotes => [String.t()],
  optional(:asset_aliases) => %{optional(String.t()) => String.t()}
}

Functions

to_canonical(mapping, native)

@spec to_canonical(mapping(), String.t()) :: String.t()

Exchange-native symbol → canonical BASE-QUOTE, per the connector's mapping. Unparseable / already-dashed input → uppercased input (never dropped).

to_exchange(mapping, canonical)

@spec to_exchange(mapping(), String.t()) :: String.t()

Canonical BASE-QUOTE → exchange-native, per the connector's mapping.