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
13 import Data
.Aeson
(FromJSON
(..), Value
, withObject
)
14 import Data
.Aeson
.Types
(Parser
)
17 import Data
.Function
(($))
18 import Data
.Functor
(fmap, (<$>))
19 import Data
.String (String)
20 import Data
.Traversable
(mapM)
22 import Text
.Show (Show)
25 import Data
.Text
(Text
)
27 -- unordered-containers
28 import Data
.HashMap
.Strict
(HashMap
)
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
) }
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 #-}
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 #-}