1 {-# LANGUAGE FlexibleContexts, UndecidableInstances #-}
2 module Cryptsy
.API
.Public
.OrderData
3 ( module Cryptsy
.API
.Public
.OrderData
4 , module Cryptsy
.API
.Public
.Types
.OrderBook
5 , module Cryptsy
.API
.Public
.Types
.Monad
6 , module Cryptsy
.API
.Public
.Types
.Num
11 import Data
.Aeson
(FromJSON
(..), Value
, withObject
)
12 import Data
.Aeson
.Types
(Parser
)
15 import Data
.Function
(($))
16 import Data
.Functor
(fmap, (<$>))
17 import Data
.String (String)
18 import Data
.Traversable
(mapM)
20 import Text
.Show (Show)
23 import Data
.Text
(Text
)
25 -- unordered-containers
26 import Data
.HashMap
.Strict
(HashMap
)
29 import Cryptsy
.API
.Public
.Internal
30 import Cryptsy
.API
.Public
.Types
.OrderBook
31 import Cryptsy
.API
.Public
.Types
.Monad
32 import Cryptsy
.API
.Public
.Types
.Num
34 -- |general order data parameterized by types for prices, quantities,
35 -- and totals (price * quantity)
36 newtype GOrderData p q t
=
37 OrderData
{ orderBooks
:: HashMap Text
(GOrderBook p q t
) }
40 -- |default order data
41 type OrderData
= GOrderData CryptsyNum CryptsyNum CryptsyNum
43 instance FromJSON
(GOrderBook p q t
) => FromJSON
(GOrderData p q t
) where
44 parseJSON
= parseOrderData parseJSON
46 -- |Build parser for multiple orderbooks from parser for single orderbook.
47 parseOrderData
:: (Value
-> Parser
(GOrderBook p q t
)) -- ^ orderbook parser
48 -> Value
-> Parser
(GOrderData p q t
)
49 parseOrderData parseBook
=
50 withObject
"OrderData" $ fmap OrderData
<$> mapM parseBook
53 orderdataURL
:: String
54 orderdataURL
= pubURL
"orderdata"
56 -- |Request full order book for all markets.
57 orderData
:: FromJSON
(GOrderData p q t
) => PubCryptsy
(GOrderData p q t
)
58 orderData
= pubCryptsy orderdataURL parseJSON