An exchange cannot say what a pair was priced at last month #48
Labels
No labels
kind
bug
kind
enhancement
kind
refactor
workflow
needs-info
workflow
needs-triage
workflow
ready-for-agent
workflow
ready-for-human
workflow
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
rosa/lucre#48
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Exchangestores one quotation per pair and no time. An invoice dated lastmonth has to be restated at the price in effect then, and the table cannot
answer that. Feeds carry the moment of the quotation, so the information exists
and is dropped: the
Quotationdeserializer already skips anas_offield.Proposal
A
HistorybesideExchange, holding every quotation a table has held, eachfiled under the
Timestampit was made at. Reading a history at a moment givesa plain
Exchange.Depends on #55, which adds
Timestamp.Settled in triage
Historysits besideExchangerather than replacing it, so the plain tablestays as simple as it is now. It also means #47's triangulation lands once,
on
Exchange, and a history inherits it.moment is the caller's policy.
Quotationgains no field. A timestamp on it would change equality,ordering, and the wire format for callers who have no use for one, and would
undo the compatibility ADR 0002 kept.
nothing at all before the earliest.
Exchange.ship. This is what finally reads the
as_offield.Exchange, which does.CONTEXT.mddefines History and Timestamp.Out of scope
Triangulation (#47), the provider trait (#49), and two-sided quotes (#50).
Exchange::convertfails on a pair it could derive #47Agent Brief
Category: enhancement
Summary: Add
History, a table of every quotation a pair has held overtime, which reads at a moment as a plain
Exchange.Blocked on #55, which adds
Timestamp. Do not start until that lands.Current behavior:
Exchangeholds one quotation per currency pair, keyed by the two currenciessorted, so either direction names the same entry. Nothing records when a
quotation was made. A caller restating a month-old invoice has to keep a
separate table per date themselves. The
Quotationdeserializer documents thatit skips fields it does not know, naming a time field as the example, so a feed
document's
as_ofis read and discarded.Desired behavior:
lucre::exchange::Historyholds many quotations per pair, each filed under theTimestampit was made at. Its lookups take a moment and answer with what wasin effect then: the newest quotation at or before that moment, and nothing at
all for a moment before the pair's earliest. A moment with no quotation for
that pair is not an error, just an absence — a weekend reads Friday's price.
Reading a history at a moment gives an owned
Exchangeholding, for each pair,the quotation in effect then. Pairs with nothing yet quoted are absent from it.
Key interfaces:
History— same derivesExchangecarries. Entries key on the pair's twocurrencies sorted, together with the moment, so a quotation over
EUR/USDdisplaces one over
USD/EURat the same moment.exact moment, as
Exchange's setter does. Setting never fails.Exchange.Exchangehas: one giving thequotation as stored, one giving the price for the asked direction as a
one-way quotation. Both return
Option.Exchangegained in#6 and #9. Iteration order should be pair order, then moment.
Extend,FromIterator, andFrom<[_; N]>over(Timestamp, Quotation)tuples, matching what #6 gave
Exchangeover anythingInto<Quotation>.SerializeandDeserializebehind theserdefeature, in the crate'ssingle serde module. The wire shape is a flat list of entries, each naming
the moment alongside the pair and its price or prices:
{"as_of": "...", "base": "USD", "quote": "EUR", "rate": "0.9"}. A list, not a map, because apair appears many times. Reuse the private reader that already reads a
quotation's fields rather than writing a second one.
Quotationdeserializer's doc calls the field it skips "the time of thequote".
CONTEXT.mdreserves quote for the currency alone, so reword it tosay the moment the price was made. Whether
Quotationstill skips the fieldis unchanged — it does.
Acceptance criteria:
quotation, and answers a moment between them with the earlier one.
None, for bothlookups.
displaced quotation; setting at a new moment hands back
None.EUR/USDand one overUSD/EURat the same moment areone entry, and the second displaces the first.
Exchangethat converts, iterates, andserializes exactly as one built by hand from the same quotations.
names
as_ofon every entry produces the expected history.Exchangeis unchanged, andQuotationgains no field and no method.mise run cipasses. Clippy and the tests run twice, with no featuresand with all of them.
docs/agents/codebase-map.mdlists the new module.Out of scope:
History. Callers read it at a moment and convertthrough the
Exchangethat comes back.Exchange's wire format, which stays a map keyed by pair.forward with an expiry.
A rate table cannot say what the rate was on a given dateto An exchange cannot say what a pair was priced at last monthI changed my mind about #55, I will just use the
timecrate as part of the public API.Exchange::convertfails on a pair it could derive #47