Skip to main content

Module source

Module source 

Expand description

Fetching a market through a source: the port an external system implements.

A book already says what it is priced against — every trade’s RiskFactors, the market’s curve recipes, every reset already set. MarketContext::demand folds that into one Demand; a MarketDataSource answers it in one call; MarketContext::with_market_data builds a new market from the answer or refuses naming every gap. A book’s fetch_market_data is those three in order, from the DataSource its market carries — given with MarketContext::with_data_source, or the process default set_data_source copied when the market was built.

§The contract a source keeps

  • Absence is a gap, never a value. A source answers only what it holds. It never pads a strip, interpolates a pillar or repeats yesterday’s mark to keep a calibration alive: a market that prices, and prices wrong, with nothing to see is the failure this port exists to remove. An empty strip is absent.
  • A failure is not a gap. SourceError means the source itself failed — transport, authentication, a payload it could not read.
  • Stamp from the source’s clock. Each strip and spot carries the date it was observed; one after the market’s as_of is refused.
  • One call per snapshot. The whole demand crosses at once — a source that batches by vendor endpoint does so on its own side.
  • Calendars before trades. A CalendarSource is a session input: ingest its calendars before drafting the trades that should roll on them, because a trade keeps the calendar it was drafted on.

The ports are synchronous on purpose. An asynchronous connector — Python’s asyncio, an HTTP client — runs between MarketContext::demand and MarketContext::with_market_data on its own side, so nothing here drives another runtime’s event loop.

Structs§

DataSource
Where a market fetches its missing data from: market data, and optionally recipes. Cheap to clone — both are shared.
Demand
Everything a book needs from outside, derived from what its trades declare and the market’s recipes. Sorted and de-duplicated, so two equal books on one market demand equal things.
FetchReport
What a book’s fetch asked for and got, key by key.
FxSpot
One FX spot as a source publishes it, in either orientation.
MarketData
What a source answered: strips, fixings and spots. Anything a demand names and this does not carry is a gap.
RecipeAsk
What a recipe source is asked about: the collateral keys a book reads.
StripKey
One quote strip a snapshot needs: the template it is quoted on and the collateral key whose recipe names it. A recipe is topology, so the strip — every pillar the source publishes on the template — is the key, never one pillar.
StripQuotes
One strip as a source publishes it: the template, the date it was observed, and its pillars in the template’s own units.
Unresolved
A curve a book reads that the snapshot cannot build, and why.

Enums§

Gap
One thing a snapshot needed and did not get.
SnapshotError
Why a snapshot built no market.
SourceError
A source itself failed — distinct from a gap, which is a key it does not hold.
SourceSetting 🔒
A market’s data source: none set, offline by choice, or a source.

Traits§

CalendarSource
A source of business calendars — a session input, ingested with ingest_calendars before any trade that should roll on them is drafted.
MarketDataSource
A source of market data — per snapshot, one call carrying the whole demand.
RecipeSource
A source of curve recipes — per snapshot, layered between the caller’s overlay and the shipped base.

Functions§

conventional 🔒
The base of a pair in conventional quotation: the higher-ranked currency is the base (EURUSD, GBPUSD, USDJPY); a currency ranked nowhere quotes against USD with USD as base (USDKRW), and two unranked currencies take the alphabetically first as base.
data_source
The process-wide default data source, if one is set.
default_slot 🔒
The process-wide default source.
discount_keys 🔒
Every discount key the book’s trades declare, sorted.
gaps_in 🔒
Everything demand names that data does not carry, sorted.
held_strip 🔒
The strip data holds on template, if it holds a non-empty one.
out_of_scope_inputs 🔒
The non-curve inputs a trade declares that no source serves yet.
pair_order 🔒
refuse_future_stamps 🔒
Refuses the first strip or spot observed after as_of.
set_data_source
Sets the process-wide default data source — or, with None, clears it.