Convert between currencies with exchange rates #5
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/exchange-rates"
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?
Rates are live data rather than a standard, so nothing here quotes one for you.
ExchangeRatestates a quote you already have, andExchangekeeps a set ofthem to look up by currency pair.
Converting
ExchangeRate::newrefuses a multiplier of zero or less, so a rate noexchange takes place at cannot be built.
convertrestates aMoneyin the currency a rate prices it in, keepingevery digit multiplying reached — rounding waits until the amount is due.
cross_withcomposes two quotes meeting at a shared currency into onespanning both legs, which is how a pair nobody quotes directly gets priced.
Exchangesays so or not.ExchangeRate::identitynames that rate outright.them separately, and a fresh quote displaces the last.
Exchange::quoteshands back every quote a table holds.Serializing
Under the
serdefeature, a quote states the pair it spans and the multiplierbetween them, and a table is a rate per pair, keyed the way a rate board names
one:
Reading either goes through
ExchangeRate::new, so a document cannot state amultiplier no exchange takes place at. A pair a table names twice keeps the
rate given last, matching what
set_ratedoes.