A database of price information. A PricePoint has a DateTime, a From commodity, a To commodity, and a QtyPerUnit. The PriceDb holds this information for several prices. You can query the database by supplying a from commodity, a to commodity, and a DateTime, and the database will give you the QtyPerUnit, if there is one.
- data PriceDb
- emptyDb :: PriceDb
- addPrice :: PriceDb -> PricePoint -> PriceDb
- getPrice :: PriceDb -> From -> To -> DateTime -> Exceptional PriceDbError CountPerUnit
- data PriceDbError
- convertAsOf :: HasQty q => PriceDb -> DateTime -> To -> Amount q -> Exceptional PriceDbError Qty
The PriceDb holds information about prices. Create an empty one
emptyDb then fill it with values using foldl or similar.
Looks up values from the PriceDb. Throws Error if something fails.
The DateTime is the time at which to find a price. If a price exists for that exact DateTime, that price is returned. If no price exists for that exact DateTime, but there is a price for an earlier DateTime, the latest possible price is returned. If there are no earlier prices, CpuNotFound is thrown.
Getting prices can fail; if it fails, an Error is returned.
Given an Amount and a Commodity to convert the amount to,
converts the Amount to the given commodity. If the Amount given is
already in the To commodity, simply returns what was passed in. Can
fail and throw PriceDbError. Internally uses
getPrice, so read its
documentation for details on how price lookup works.