Massive refactoring into smaller modules.
[haskell-cryptsy-api.git] / Cryptsy / API / Public / MarketData.hs
blob80bd01ccdabae5bb761824aa54c2bcdecd73cc8f
1 {-# LANGUAGE UndecidableInstances #-}
2 module Cryptsy.API.Public.MarketData where
4 -- aeson
5 import Data.Aeson (FromJSON(..), Value, withObject )
6 import Data.Aeson.Types (Parser)
8 -- base
9 import Data.Function (($))
10 import Data.Functor (fmap, (<$>))
11 import Data.Traversable (mapM)
12 import Prelude (Show(show))
14 -- text
15 import Data.Text (Text)
17 -- unordered-containers
18 import Data.HashMap.Strict (HashMap)
20 -- this package
21 import Cryptsy.API.Public.Market
22 import Cryptsy.API.Public.Num
23 import Cryptsy.API.Public.Time
25 -- |general market data parameterized by types for prices, quantities,
26 -- date/time values, and totals (price * quantity)
27 newtype GMarketData p q dt t =
28 MarketData { markets :: HashMap Text (GMarket p q dt t) }
29 deriving Show
31 -- |default market data
32 type MarketData = GMarketData CryptsyNum CryptsyNum CryptsyTime CryptsyNum
34 instance FromJSON (GMarket p q dt t) => FromJSON (GMarketData p q dt t) where
35 parseJSON = parseMarketData parseJSON
37 -- |Build parser for multiple markets from parser for single market.
38 parseMarketData :: (Value -> Parser (GMarket p q dt t)) -- ^ market parser
39 -> Value -> Parser (GMarketData p q dt t)
40 parseMarketData parseSingle =
41 withObject "MarketData" $ fmap MarketData <$> mapM parseSingle