Created
January 18, 2021 21:53
-
-
Save evgenii-malov/ec7a36426720aba81de67b40c69a7e8e to your computer and use it in GitHub Desktop.
Bitcoin price monitor in haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- see video https://youtu.be/M4_OW2_zXQo | |
import Network.HTTP.Conduit | |
import Text.JSON.JPath | |
import Data.ByteString.Lazy.Char8 (unpack) | |
import Control.Concurrent | |
import Control.Exception | |
import Control.Applicative | |
import Control.Monad.Loops | |
u = "https://api.bittrex.com/api/v1.1/public/getticker?market=USD-BTC" | |
parsed d = head $ (jPath "result/Ask" d) <|> ["parse_price_error"] | |
act = try $ (simpleHttp u) >>= (\d -> threadDelay 1000000 >> return (parsed $ unpack d)) :: IO (Either HttpException [Char]) | |
pe pp (Right p) = if pp==p then return p else print p >> return p | |
pe pp (Left e) = print er >> threadDelay 1000000 >> return er where er = show e | |
main = iterateUntilM (\_->False) (\pp -> act >>= (pe pp)) "start" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see video