module GetData where
import Control.Applicative
import Control.Monad (mzero)
import Network.HTTP.Conduit
import Data.Text
import qualified Data.ByteString.Lazy as L
import qualified Data.Aeson as A
data BitcoinData = BitcoinData {
ask :: Maybe Double,
avg :: Maybe Double,
bid :: Maybe Double,
close :: Maybe Double,
currency :: Text,
currency_volumen :: Maybe Double,
high :: Maybe Double,
latest_trade :: Maybe Double,
low :: Maybe Double,
symbol :: Text,
volumen :: Maybe Double
} deriving (Show, Read, Eq, Ord)
instance A.FromJSON BitcoinData where
parseJSON (A.Object v) = BitcoinData <$>
v A..: "ask" <*>
v A..: "avg" <*>
v A..: "bid" <*>
v A..: "close" <*>
v A..: "currency" <*>
v A..: "currency_volumen" <*>
v A..: "high" <*>
v A..: "latest_trade" <*>
v A..: "low" <*>
v A..: "symbol" <*>
v A..: "volumen"
parseJSON _ = mzero
getJSON :: IO BitcoinData
getJSON = do
json <- simpleHttp "http://api.bitcoincharts.com/v1/markets.json"
return $ A.decode json::(Maybe BitcoinData)