penny-0.32.0.10: Extensible double-entry accounting system

Safe HaskellNone

Penny.Lincoln.PriceDb

Description

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.

Synopsis

Documentation

data PriceDb Source

The PriceDb holds information about prices. Create an empty one using emptyDb then fill it with values using foldl or similar.

emptyDb :: PriceDbSource

An empty PriceDb

addPrice :: PriceDb -> PricePoint -> PriceDbSource

Add a single price to the PriceDb.

getPrice :: PriceDb -> From -> To -> DateTime -> Either 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.

convertAsOf :: HasQty q => PriceDb -> DateTime -> To -> Amount q -> Either 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.