feat!: Quote both directions of a pair with a single Quotation #51

Merged
rosa merged 13 commits from feat/two-sided-market into main 2026-08-20 17:41:11 +00:00
Owner

An Exchange held each direction of a pair as its own entry, so a table could
quote USD/EUR at 0.80 beside EUR/USD at 1.30 and pay for a round trip. Both
directions now share one Quotation: it holds the pair, the price from base to
quote, and an optional second price the other way. Leaving the second price out
says no price for that direction was offered; stating it makes the quotation
two-sided, and the low price can never sit above the high one.

docs/adr/0002-a-quotation-holds-an-optional-reverse-price.md records the
decision and what it rejected, including why ADR 0001's objection to folding
one-way and two-way prices together does not apply once the reverse price is
optional.

Closes #50.

Breaking changes

  • ExchangeRate is replaced by Quotation, and ExchangeRateError and
    InvertError by QuotationError.
  • Quotation::convert returns Result<Money, ConvertError> rather than a
    Result wrapped around an Option. A direction it cannot price is an error
    variant, not an absence.
  • Exchange keys entries on the two currencies sorted rather than on a Pair,
    so a stored key is never a pair nobody quoted.
  • IntoRates and Rates are now IntoQuotations and Quotations.
  • The exchange types are no longer re-exported from the crate root. Reach them
    through lucre::exchange::*.
  • Every price a quotation holds must be above zero and below 2e28. An
    ExchangeRate used to accept a rate at or above 2e28 and then refuse to
    invert it.

Also in here

  • Fifteen Extend, FromIterator, and From<[T; N]> impls on Exchange
    collapse into three blanket ones over Into<Quotation>.
  • A pair and its parsing move into src/exchange/pair.rs.
  • The property suites share one strategy module rather than four copies of it,
    and the round-trip property no longer rounds both sides before comparing.
  • CONTEXT.md lists "market" under the words to avoid; the glossary, the
    README, and the module docs all follow the single price type.

mise run ci passes.

An `Exchange` held each direction of a pair as its own entry, so a table could quote USD/EUR at 0.80 beside EUR/USD at 1.30 and pay for a round trip. Both directions now share one `Quotation`: it holds the pair, the price from base to quote, and an optional second price the other way. Leaving the second price out says no price for that direction was offered; stating it makes the quotation two-sided, and the low price can never sit above the high one. `docs/adr/0002-a-quotation-holds-an-optional-reverse-price.md` records the decision and what it rejected, including why ADR 0001's objection to folding one-way and two-way prices together does not apply once the reverse price is optional. Closes #50. ## Breaking changes - `ExchangeRate` is replaced by `Quotation`, and `ExchangeRateError` and `InvertError` by `QuotationError`. - `Quotation::convert` returns `Result<Money, ConvertError>` rather than a `Result` wrapped around an `Option`. A direction it cannot price is an error variant, not an absence. - `Exchange` keys entries on the two currencies sorted rather than on a `Pair`, so a stored key is never a pair nobody quoted. - `IntoRates` and `Rates` are now `IntoQuotations` and `Quotations`. - The exchange types are no longer re-exported from the crate root. Reach them through `lucre::exchange::*`. - Every price a quotation holds must be above zero and below `2e28`. An `ExchangeRate` used to accept a rate at or above `2e28` and then refuse to invert it. ## Also in here - Fifteen `Extend`, `FromIterator`, and `From<[T; N]>` impls on `Exchange` collapse into three blanket ones over `Into<Quotation>`. - A pair and its parsing move into `src/exchange/pair.rs`. - The property suites share one strategy module rather than four copies of it, and the round-trip property no longer rounds both sides before comparing. - `CONTEXT.md` lists "market" under the words to avoid; the glossary, the README, and the module docs all follow the single price type. `mise run ci` passes.
rosa added 11 commits 2026-08-18 19:14:18 +00:00
An `Exchange` held each direction of a pair as its own entry, so a table
could quote USD/EUR at 0.80 beside EUR/USD at 1.30 and pay for a round
trip. Both directions now share one `Quotation`, which is either a
one-way `ExchangeRate` or a two-way `Market` whose low price can never
sit above its high.

Closes #50
The table filed each entry under a `Pair`, which names two currencies in a
fixed order, so the stored key was often a pair nobody quoted. It now files
under the two currencies alone, sorted. Fifteen `Extend`, `FromIterator`,
and `From<[T; N]>` impls collapse into three blanket ones over
`Into<Quotation>`, and the property suites share one strategy module rather
than four copies of it.

The round-trip property no longer rounds both sides before comparing, so it
shows what it claims: a market that charges a spread returns no more than it
was given, from either currency, and a flat market's gain stays inside what
rounding can reach.
The ADR put the gain from a round trip at a last digit. It reaches further:
a `Decimal` holds 28 decimal places, and the multiplication after the
rounded division scales whatever the rounding left. The bound now written
down is the one the property test asserts.

The Market glossary entry also defined the type with a word its own Avoid
list names, so it now reads as the type's documentation does.
fix: Divide by a market's high price rather than inverting it
All checks were successful
ci/woodpecker/push/test Pipeline was successful
50e909d3ee
refactor: Draw the pair suite's strategies from the shared module
All checks were successful
ci/woodpecker/push/test Pipeline was successful
fdc8e63b1d
Rename the two-way fixtures away from "market", which the glossary now
lists under the words to avoid, and document the borrowed conversion.
Closes #53
fix: Refuse an exchange entry that names a pair
All checks were successful
ci/woodpecker/push/test Pipeline was successful
2aed01b7dd
An entry is filed under its pair, so a base or a quote in the value states a
pair the key already gives. Both were read and then overruled by the key.

Closes #54
rosa merged commit b02aafb091 into main 2026-08-20 17:41:11 +00:00
rosa deleted branch feat/two-sided-market 2026-08-20 17:41:11 +00:00
Sign in to join this conversation.
No description provided.