module Cryptsy.API.Public.Types.Trade
( module Cryptsy.API.Public.Types.Trade
, module Cryptsy.API.Public.Types.Num
, module Cryptsy.API.Public.Types.Time
)
where
import Control.Applicative ((<$>), (<*>))
import Data.Text (Text, pack)
import Data.Aeson (FromJSON(..), Value, withObject, (.:))
import Data.Aeson.Types (Parser)
import Cryptsy.API.Public.Types.Num
import Cryptsy.API.Public.Types.Time
data GTrade dt p q t = Trade
{ tradeId :: Text
, tradeTime :: dt
, tradePrice :: p
, tradeQuantity :: q
, tradeTotal :: t
} deriving Show
type Trade = GTrade CryptsyTime CryptsyNum CryptsyNum CryptsyNum
instance (FromJSON dt, FromJSON p, FromJSON q, FromJSON t) =>
FromJSON (GTrade dt p q t)
where
parseJSON = parseTrade parseJSON parseJSON parseJSON parseJSON
parseTrade :: (Value -> Parser dt)
-> (Value -> Parser p)
-> (Value -> Parser q)
-> (Value -> Parser t)
-> Value -> Parser (GTrade dt p q t)
parseTrade parseDatetime parsePrice parseQuantity parseTotal =
withObject "Trade" $ \o -> Trade <$>
o .: pack "id" <*>
(o .: pack "time" >>= parseDatetime) <*>
(o .: pack "price" >>= parsePrice ) <*>
(o .: pack "quantity" >>= parseQuantity) <*>
(o .: pack "total" >>= parseTotal )