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.
SourceErrormeans 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_ofis 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
CalendarSourceis 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§
- Data
Source - 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.
- Fetch
Report - What a book’s fetch asked for and got, key by key.
- FxSpot
- One FX spot as a source publishes it, in either orientation.
- Market
Data - What a source answered: strips, fixings and spots. Anything a demand names and this does not carry is a gap.
- Recipe
Ask - What a recipe source is asked about: the collateral keys a book reads.
- Strip
Key - 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.
- Strip
Quotes - 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.
- Snapshot
Error - Why a snapshot built no market.
- Source
Error - A source itself failed — distinct from a gap, which is a key it does not hold.
- Source
Setting 🔒 - A market’s data source: none set, offline by choice, or a source.
Traits§
- Calendar
Source - A source of business calendars — a session input, ingested with
ingest_calendarsbefore any trade that should roll on them is drafted. - Market
Data Source - A source of market data — per snapshot, one call carrying the whole demand.
- Recipe
Source - 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
demandnames thatdatadoes not carry, sorted. - held_
strip 🔒 - The strip
dataholds ontemplate, 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.