As a minimal example, to get the current selling price (in South African Rand) of Bitcoin on the Luno 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 ++ ".") 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) ++ "\""
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. Your best bet might be to just
* We now handle nulls properly when deserialising JSON arrays.
* Luno has added Ethereum and an ETHXBT currency pair.
* Prices (bid, ask, and spot) are now consistently Scientific, rather than Int. BREAKING CHANGE.
* We no longer create a brand new connection manager on every API call, significatly improving performance.
* Luno's rate-limiting is now much more harsh.
* Added new fee_info endpoint.
* The BitX API no longer gives trades when returning private orders. BREAKING CHANGE.
* Due to the above change, a new function -- getAllTrades -- has been added to the private order API.
* The basic types now come with a large set of default typeclasses, to minimise the need for orphan instances.
* New optional beneficiary ID field for withdrawal requests. BREAKING CHANGE.
* Compatibility with http-client-0.5.0 and http-client-tls-0.3.0.
* The BitXAuth type can now be written as a string using the OverloadedStrings extension.
* Use (strict) Text consistantly instead of random string-like types. BREAKING CHANGE.
* Added Singapore Dollar.
* The UnparseableResponse now provides the Aeson error. BREAKING CHANGE.
* Last_trade and Bid and Ask prices don't always appear in the Ticker type. BREAKING CHANGE.
* GHC 8.0 is now officially supported.
* Forgot to export "status" lens,
* Added new "completed_timestamp" field to private order types.
* Added new "since" option to public trades' endpoint. BREAKING CHANGE.
* Added is_buy field for trade record.
* Added Indonesian Rupiah.
* Added the new endpoint for creating market (spot) orders.
* Replaced http-conduit with http-client and http-client-tls.
* Fixed broken rate limiting.
* A few more major bugfixes w.r.t. to BitX number formatting.
* Fixed issue due to BitX's handling of ints as decimal.
* Prices should be integers, not real. BREAKING CHANGE.
* Dropped support for versions of GHC lower than 7.8.1.
* BitX expects decimals to have 6 places and no trailing zeros.
* Changed license to BSD3.
* Now builds on Stack LTS-3.
* ExceptionResponse now holds the actual exception, rather than its text representation. BREAKING CHANGE.
* Replaced Volkov records with (micro)lenses. BREAKING CHANGE.
* Implemented a (naive) mechanism to work around nginx rate limiting.
* Added Nigerian Naira.
* Record library dependency needs upper bound.
* Replaced Decimal with Scientific. BREAKING CHANGE.
* Divided much of the Private module into smaller sub-modules. BREAKING CHANGE.
* Added the new endpoint for creating accounts.
* Remove ill-thought-out Auth module.
* Lots of internal improvements.
* Initial release!