Use more correct "license:" in cabal file.
[haskell-cryptsy-api.git] / src / Cryptsy / API / Public / OrderData.hs
blobf91a14f461281758a58fa2e98315614a9c8ba7fe
1 {-# LANGUAGE FlexibleContexts, UndecidableInstances #-}
2 -- |Type and request for order book for all markets.
3 module Cryptsy.API.Public.OrderData
4 ( GOrderData(..), OrderData
5 , parseOrderData, orderData
6 , module Cryptsy.API.Public.Types.OrderBook
7 , module Cryptsy.API.Public.Types.Monad
8 , module Cryptsy.API.Public.Types.Num
10 where
12 -- aeson
13 import Data.Aeson (FromJSON(..), Value, withObject)
14 import Data.Aeson.Types (Parser)
16 -- base
17 import Data.Function (($))
18 import Data.Functor (fmap, (<$>))
19 import Data.String (String)
20 import Data.Traversable (mapM)
21 import Prelude ()
22 import Text.Show (Show)
24 -- text
25 import Data.Text (Text)
27 -- unordered-containers
28 import Data.HashMap.Strict (HashMap)
30 -- this package
31 import Cryptsy.API.Public.Internal
32 import Cryptsy.API.Public.Types.OrderBook
33 import Cryptsy.API.Public.Types.Monad
34 import Cryptsy.API.Public.Types.Num
36 -- |general order data parameterized by types for prices, quantities,
37 -- and totals (price * quantity)
38 newtype GOrderData p q t =
39 OrderData { orderBooks :: HashMap Text (GOrderBook p q t) }
40 deriving Show
42 -- |default order data
43 type OrderData = GOrderData CryptsyNum CryptsyNum CryptsyNum
45 instance FromJSON (GOrderBook p q t) => FromJSON (GOrderData p q t) where
46 parseJSON = parseOrderData parseJSON
48 -- |Build parser for multiple orderbooks from parser for single orderbook.
49 parseOrderData :: (Value -> Parser (GOrderBook p q t)) -- ^ orderbook parser
50 -> Value -> Parser (GOrderData p q t)
51 parseOrderData parseBook =
52 withObject "OrderData" $ fmap OrderData <$> mapM parseBook
53 {-# INLINABLE parseOrderData #-}
55 -- |URL for API call
56 orderdataURL :: String
57 orderdataURL = pubURL "orderdata"
59 -- |Request full order book for all markets.
60 orderData :: FromJSON (GOrderData p q t) => PubCryptsy (GOrderData p q t)
61 orderData = pubCryptsy orderdataURL parseJSON
62 {-# INLINABLE orderData #-}