module Cryptsy.API.Public.OrderBook
( module Cryptsy.API.Public.OrderBook
, module Cryptsy.API.Public.Types.Monad
, module Cryptsy.API.Public.Types.OrderBook
)
where
import Data.Aeson (FromJSON(..), withObject)
import Data.Text (Text, unpack)
import Data.HashMap.Strict (toList)
import Cryptsy.API.Public.Internal
import Cryptsy.API.Public.Types.Monad
import Cryptsy.API.Public.Types.OrderBook
singleOrderBook :: FromJSON (GOrderBook p q t)
=> Text
-> PubCryptsy (GOrderBook p q t)
singleOrderBook (unpack -> reqMarket) =
pubCryptsy orderBookURL parseSingleOrderBook
where
orderBookURL = pubURL $ "singleorderdata&marketid=" ++ reqMarket
parseSingleOrderBook = withObject dataStr $ \o ->
case toList o of
[] -> fail "No order book returned."
[(_, v)] -> parseJSON v
_ -> fail "Multiple order books returned."