bitx-bitcoin

A Haskell library for working with the BitX bitcoin exchange.

https://github.com/tebello-thejane/bitx.hs

Version on this page:0.11.0.0
LTS Haskell 14.27:0.12.0.0
Stackage Nightly 2019-09-21:0.12.0.0
Latest on Hackage:0.12.0.0

See all snapshots bitx-bitcoin appears in

BSD-3-Clause licensed by Tebello Thejane
Maintained by Tebello Thejane
This version can be pinned in stack with:bitx-bitcoin-0.11.0.0@sha256:2fbbb62fabf34f464b05bb1c155ec23dec6bf28ca4428314f048bb1f9f5d7c8d,4553

Build Status Hackage BSD3

(Hopefully useful) Haskell bindings to the BitX bitcoin exchange’s API.

As a minimal example, to get the current selling price (in South African Rand) of bitcoin on the BitX exchange, do the following:

import Control.Lens ((^.))
import Network.Bitcoin.BitX (BitXAPIResponse(..), getTicker, CcyPair(..))
import qualified Network.Bitcoin.BitX as BitX
import Data.Text (unpack)
import Network.HTTP.Types.Status (Status(..))
import Network.HTTP.Client (responseStatus)

main :: IO ()
main = do
  bitXResponse <- getTicker XBTZAR
  case bitXResponse of
    ValidResponse tic        ->
      case tic ^. BitX.ask of
        Nothing              ->  putStrLn "The BTC-ZAR exchange not currently have an ask price..."
        Just p               ->  putStrLn ("1 bitcoin will set you back ZAR" ++ show p ++ ".00.")
    ErrorResponse err        ->
        error $ "BitX error received: \"" ++ unpack (err ^. BitX.error) ++ "\""
    ExceptionResponse ex     ->
        error $ "Exception was thrown: \"" ++ show ex ++ "\""
    UnparseableResponse _ resp ->
        error $ "Bad HTTP response; HTTP status code was: \"" ++ (show . statusCode . responseStatus $ resp) ++ "\""

Note that the code snippet above depends on http-types, text, http-client, lens (or any lens-compatible package, such as microlens), and finally bitx-bitcoin.

This library is known to work on Windows, but if you wish to use it then you will have to do a bit more work due to the Network library not building on Windows out of the box. See this blog post by Neil Mitchell.