1 {-# LANGUAGE FlexibleContexts, ViewPatterns #-}
2 -- |Request for a single order book by market id.
3 module Cryptsy
.API
.Public
.OrderBook
4 ( module Cryptsy
.API
.Public
.OrderBook
5 , module Cryptsy
.API
.Public
.Types
.Monad
6 , module Cryptsy
.API
.Public
.Types
.OrderBook
11 import Data
.Aeson
(FromJSON
(..), withObject
)
14 import Data
.Text
(Text
, unpack
)
16 -- unordered-containers
17 import Data
.HashMap
.Strict
(toList
)
20 import Cryptsy
.API
.Public
.Internal
21 import Cryptsy
.API
.Public
.Types
.Monad
22 import Cryptsy
.API
.Public
.Types
.OrderBook
24 -- |single orderbook API request
25 singleOrderBook
:: FromJSON
(GOrderBook p q t
)
27 -> PubCryptsy
(GOrderBook p q t
)
28 singleOrderBook
(unpack
-> reqMarket
) =
29 pubCryptsy orderBookURL parseSingleOrderBook
31 orderBookURL
= pubURL
$ "singleorderdata&marketid=" ++ reqMarket
32 parseSingleOrderBook
= withObject dataStr
$ \o
->
34 [] -> fail "No order book returned."
35 [(_
, v
)] -> parseJSON v
36 _
-> fail "Multiple order books returned."
37 {-# INLINABLE singleOrderBook #-}