Use more correct "license:" in cabal file.
[haskell-cryptsy-api.git] / src / Cryptsy / API / Public / OrderBook.hs
blobe80f035d9bcec0875c103eb7b296666042722462
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
8 where
10 -- aeson
11 import Data.Aeson (FromJSON(..), withObject)
13 -- text
14 import Data.Text (Text, unpack)
16 -- unordered-containers
17 import Data.HashMap.Strict (toList)
19 -- this package
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)
26 => Text -- ^ marketid
27 -> PubCryptsy (GOrderBook p q t)
28 singleOrderBook (unpack -> reqMarket) =
29 pubCryptsy orderBookURL parseSingleOrderBook
30 where
31 orderBookURL = pubURL $ "singleorderdata&marketid=" ++ reqMarket
32 parseSingleOrderBook = withObject dataStr $ \o ->
33 case toList o of
34 [] -> fail "No order book returned."
35 [(_, v)] -> parseJSON v
36 _ -> fail "Multiple order books returned."
37 {-# INLINABLE singleOrderBook #-}