GithubHelp home page GithubHelp logo

tebello-thejane / bitx.hs Goto Github PK

View Code? Open in Web Editor NEW
11.0 5.0 3.0 594 KB

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

License: BSD 3-Clause "New" or "Revised" License

Haskell 100.00%
haskell bitcoin bitcoin-exchange haskell-bindings api

bitx.hs's Introduction

Build Status Hackage BSD3

(Hopefully useful) Haskell bindings to the Luno (formerly BitX) cryptocurrency exchange's API.

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) ++ "\""

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. Your best bet might be to just use Stack.

bitx.hs's People

Contributors

mithrandi avatar tebello-thejane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bitx.hs's Issues

Precision issue

λ> B.postEncode $ B.OrderRequest B.XRPXBT B.BID 673 0.00002683
[("pair","XRPXBT"),("type","BID"),("volume","673"),("price","0.000026")]

Not sure where we're losing precision but this is clearly wrong!

Could not find module ‘Network’

src/Network/Bitcoin/BitX/Internal.hs:26:1: error:
    Could not find module ‘Network’
    Use -v to see a list of the files searched for.
   |
26 | import Network (withSocketsDo)

Ticker values need to be `Scientific`

Currently these are Int, which is fine for XBTZAR since no decimals are allowed in the price, but useless for ETHXBT since the prices are always fractional in this market.

Streaming API

I have some code implementing the streaming websocket API which I'd like to contribute, but it probably needs some more cleaning up. Also I used type-level symbols for pairs rather than value-level constants, so the API will probably need to be changed. Filing this so I hopefully don't forget forever.

Creating managers is expensive

Currently a new connection manager is created for every request. This is fairly expensive, mainly because for TLS all of the certificates in the certificate store need to be parsed and loaded. If I replace globalManager with this, my CPU usage goes down a lot:

{-# NOINLINE yuck #-}
yuck :: NetCon.Manager
yuck = unsafePerformIO (NetCon.newManager NetCon.tlsManagerSettings)

globalManager :: IO NetCon.Manager
globalManager = pure yuck

(Obviously this isn't a great thing to do, it's just a quick'n'dirty PoC of sharing the manager)

What we probably want is some way to pass a manager in to the operation to be used, but I'm not quite sure how to do this without creating duplicate variants of every operation in the API, which sounds tedious.

Stackage nightly test failure

Failures:
  test/Network/Bitcoin/BitX/Spec/Specs/NetSpec.hs:24: 
  1) Network.Bitcoin.BitX.Spec.Specs.Net, 
       Public BitX connectivity, 
       getTrades connects to BitX and works

CI is totally buggered

We have basically given up on Travis-CI as it has a lot of noisy failures.

  • Are we trying to support too many GHC versions?
  • And what about the jobs which just decide to fail on whim?

Get this shit stable and fixed, so that we don't ignore valid failures due to all this noise.

ETHXBT pair

Luno recently added this (along with the ETH asset). Should be a pretty easy change, I'll try send a PR shortly.

Travis jobs randomly run into 503 issues

The travis jobs randomly time out when testing live API connectivity. This might be due to the default (non-container-based) infrastructure sharing the same IP address between multiple instances running the same test, and thus flooding BitX.

Perhaps moving to container-based infrastructure might help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.