haspara-0.0.0.0: A library providing definitions to work with monetary values.
Safe HaskellNone
LanguageHaskell2010

Haspara.FXQuote

Description

This module provides base data definitions and functions for Haspara library.

Synopsis

FX Quote

Data Definition

data FXQuote (s :: Nat) Source #

Type encoding for FX rates.

Instances

Instances details
Eq (FXQuote s) Source # 
Instance details

Defined in Haspara.Internal.FXQuote

Methods

(==) :: FXQuote s -> FXQuote s -> Bool #

(/=) :: FXQuote s -> FXQuote s -> Bool #

Ord (FXQuote s) Source # 
Instance details

Defined in Haspara.Internal.FXQuote

Methods

compare :: FXQuote s -> FXQuote s -> Ordering #

(<) :: FXQuote s -> FXQuote s -> Bool #

(<=) :: FXQuote s -> FXQuote s -> Bool #

(>) :: FXQuote s -> FXQuote s -> Bool #

(>=) :: FXQuote s -> FXQuote s -> Bool #

max :: FXQuote s -> FXQuote s -> FXQuote s #

min :: FXQuote s -> FXQuote s -> FXQuote s #

KnownNat s => Show (FXQuote s) Source # 
Instance details

Defined in Haspara.Internal.FXQuote

Methods

showsPrec :: Int -> FXQuote s -> ShowS #

show :: FXQuote s -> String #

showList :: [FXQuote s] -> ShowS #

KnownNat s => ToJSON (FXQuote s) Source #

ToJSON instance for Currency

>>> :set -XDataKinds
>>> let rate = fxquoteUnsafe (read "2021-01-01") "USD" "SGD" 1.35 :: FXQuote 2
>>> Aeson.encode rate
"{\"ccy2\":\"SGD\",\"date\":\"2021-01-01\",\"rate\":1.35,\"ccy1\":\"USD\"}"
Instance details

Defined in Haspara.Internal.FXQuote

KnownNat s => FromJSON (FXQuote s) Source #

FromJSON instance for Currency

>>> :set -XDataKinds
>>> Aeson.eitherDecode "{\"date\": \"2021-01-01\", \"ccy1\": \"USD\", \"ccy2\": \"SGD\", \"rate\": 1.35}" :: Either String (FXQuote 2)
Right ("USD/SGD","2021-01-01","1.35")
>>> Aeson.eitherDecode "{\"date\": \"2021-01-01\", \"ccy1\": \"USD\", \"ccy2\": \"SGD\", \"rate\": 1.354}" :: Either String (FXQuote 2)
Right ("USD/SGD","2021-01-01","1.35")
>>> Aeson.eitherDecode "{\"date\": \"2021-01-01\", \"ccy1\": \"USD\", \"ccy2\": \"SGD\", \"rate\": 1.355}" :: Either String (FXQuote 2)
Right ("USD/SGD","2021-01-01","1.36")
>>> Aeson.eitherDecode "{\"date\": \"2021-01-01\", \"ccy1\": \"USD\", \"ccy2\": \"SGD\", \"rate\": 1.356}" :: Either String (FXQuote 2)
Right ("USD/SGD","2021-01-01","1.36")
>>> Aeson.eitherDecode "{\"date\": \"2021-01-01\", \"ccy1\": \"USD\", \"ccy2\": \"SGD\", \"rate\": 1.364}" :: Either String (FXQuote 2)
Right ("USD/SGD","2021-01-01","1.36")
>>> Aeson.eitherDecode "{\"date\": \"2021-01-01\", \"ccy1\": \"USD\", \"ccy2\": \"SGD\", \"rate\": 1.365}" :: Either String (FXQuote 2)
Right ("USD/SGD","2021-01-01","1.36")
>>> Aeson.eitherDecode "{\"date\": \"2021-01-01\", \"ccy1\": \"USD\", \"ccy2\": \"SGD\", \"rate\": 1.366}" :: Either String (FXQuote 2)
Right ("USD/SGD","2021-01-01","1.37")
>>> Aeson.eitherDecode "{\"date\": \"2021-01-01\", \"ccy1\": \"USD\", \"ccy2\": \"USD\", \"rate\": 1.35}" :: Either String (FXQuote 2)
Left "Error in $: Can not create FX Rate. Error was: Can not create currency pair from same currencies: USD and USD"
>>> Aeson.eitherDecode "{\"date\": \"2021-01-01\", \"ccy1\": \"USD\", \"ccy2\": \"SGD\", \"rate\": -1.35}" :: Either String (FXQuote 2)
Left "Error in $: Can not create FX Rate. Error was:   The predicate (GreaterThan 0) failed with the message: Value is not greater than 0\n"
Instance details

Defined in Haspara.Internal.FXQuote

fxQuoteDate :: FXQuote s -> Date Source #

Actual date of the FX rate.

fxQuotePair :: FXQuote s -> CurrencyPair Source #

Currency pair of the FX rate.

fxQuoteRate :: FXQuote s -> Refined Positive (Quantity s) Source #

Rate value of the FX rate.

Constructors

fxquote Source #

Arguments

:: (KnownNat s, MonadError String m) 
=> Date

Date of the FX rate.

-> Currency

First currency (from) of the FX rate.

-> Currency

Second currency (to) of the FX rate.

-> Scientific

FX rate value.

-> m (FXQuote s) 

Smart constructor for FXQuote values within MonadError context.

fxquoteFail Source #

Arguments

:: (KnownNat s, MonadFail m) 
=> Date

Date of the FX rate.

-> Currency

First currency (from) of the FX rate.

-> Currency

Second currency (to) of the FX rate.

-> Scientific

FX rate value.

-> m (FXQuote s) 

Smart constructor for FXQuote values within MonadFail context.

FX Quote Database

fxquoteDatabase