Safe Haskell | None |
---|
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
- convert :: PriceDb -> DateTime -> To -> Amount -> Exceptional PriceDbError Qty
Documentation
The PriceDb holds information about prices. Create an empty one
using emptyDb
then fill it with values using foldl or similar.
addPrice :: PriceDb -> PricePoint -> PriceDbSource
Add a single price to the PriceDb.
getPrice :: PriceDb -> From -> To -> DateTime -> Exceptional PriceDbError CountPerUnitSource
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.
data PriceDbError Source
Getting prices can fail; if it fails, an Error is returned.
convert :: PriceDb -> DateTime -> To -> Amount -> Exceptional PriceDbError QtySource
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.