GetData


SUBMITTED BY: Guest

DATE: Dec. 14, 2013, 8:51 p.m.

FORMAT: Text only

SIZE: 1.6 kB

HITS: 918

  1. module GetData where
  2. import Control.Applicative
  3. import Control.Monad (mzero)
  4. import Network.HTTP.Conduit
  5. import Data.Text
  6. import qualified Data.ByteString.Lazy as L
  7. import qualified Data.Aeson as A
  8. data BitcoinData = BitcoinData {
  9. ask :: Maybe Double,
  10. avg :: Maybe Double,
  11. bid :: Maybe Double,
  12. close :: Maybe Double,
  13. currency :: Text,
  14. currency_volumen :: Maybe Double,
  15. high :: Maybe Double,
  16. latest_trade :: Maybe Double,
  17. low :: Maybe Double,
  18. symbol :: Text,
  19. volumen :: Maybe Double
  20. } deriving (Show, Read, Eq, Ord)
  21. instance A.FromJSON BitcoinData where
  22. parseJSON (A.Object v) = BitcoinData <$>
  23. v A..: "ask" <*>
  24. v A..: "avg" <*>
  25. v A..: "bid" <*>
  26. v A..: "close" <*>
  27. v A..: "currency" <*>
  28. v A..: "currency_volumen" <*>
  29. v A..: "high" <*>
  30. v A..: "latest_trade" <*>
  31. v A..: "low" <*>
  32. v A..: "symbol" <*>
  33. v A..: "volumen"
  34. parseJSON _ = mzero
  35. getJSON :: IO BitcoinData
  36. getJSON = do
  37. json <- simpleHttp "http://api.bitcoincharts.com/v1/markets.json"
  38. return $ A.decode json::(Maybe BitcoinData)

comments powered by Disqus