module Cryptsy.API.Public.Types.Order
( module Cryptsy.API.Public.Types.Order
, module Cryptsy.API.Public.Types.Num
)
where
import Control.Applicative ((<$>), (<*>))
import Data.Text (pack)
import Data.Aeson (FromJSON(..), Value, withObject, (.:))
import Data.Aeson.Types (Parser)
import Cryptsy.API.Public.Types.Num
data GOrder p q t = Order
{ orderPrice :: p
, orderQuantity :: q
, orderTotal :: t
} deriving Show
type Order = GOrder CryptsyNum CryptsyNum CryptsyNum
instance (FromJSON p, FromJSON q, FromJSON t) =>
FromJSON (GOrder p q t)
where
parseJSON = parseOrder parseJSON parseJSON parseJSON
parseOrder :: (Value -> Parser p)
-> (Value -> Parser q)
-> (Value -> Parser t)
-> Value -> Parser (GOrder p q t)
parseOrder parsePrice parseQuantity parseTotal =
withObject "Order" $ \o -> Order <$>
(o .: pack "price" >>= parsePrice ) <*>
(o .: pack "quantity" >>= parseQuantity) <*>
(o .: pack "total" >>= parseTotal )