module Cryptsy.API.Public.Market
( module Cryptsy.API.Public.Market
, module Cryptsy.API.Public.Types.Market
, module Cryptsy.API.Public.Types.Monad
)
where
import Data.Text (Text, unpack)
import Data.Aeson (FromJSON(..), withObject)
import Data.HashMap.Strict (toList)
import Cryptsy.API.Public.Internal
import Cryptsy.API.Public.Types.Market
import Cryptsy.API.Public.Types.Monad
singleMarket :: FromJSON (GMarket p q dt t)
=> Text
-> PubCryptsy (GMarket p q dt t)
singleMarket (unpack -> reqMarket) = pubCryptsy marketURL $ onMarkets parseSingleMarket
where
marketURL = pubURL $ "singlemarketdata&marketid=" ++ reqMarket
parseSingleMarket = withObject dataStr $ \o ->
case toList o of
[] -> fail "No market returned."
[(_, v)] -> parseJSON v
_ -> fail "Multiple markets returned."