Show HN: Python Client for Blockchain Exchange API

0
0
Show HN: Python Client for Blockchain Exchange API

forthebadge

Desk of Contents

Generated with DocToc

Closing Change: 2020-05-17

Elements

All API is on the market via a websocket consumer:

import logging
from bcx.consumer import BlockchainWebsocketClient

logging.basicConfig(diploma=logging.INFO)

consumer = BlockchainWebsocketClient()

Search our documentation for API reference and gallery of examples for further information.

Set up

In expose to seek out began you must seemingly seemingly accrued have Python>=3.6 construct in.

For celebrated make the most of

Here is as straightforward as working

For progress

  • Obtain supply code

    git clone [email protected]:ilya-bc/blockchain-change-api.git
    cd blockchain-change-api
  • Arrange bundle in editable mode. Since there are hundred methods to achieve that, a standardised advance for this enterprise is with Makefile. This could process digital environment with pipenv principally primarily based utterly on python==3.7 and set up all compulsory dependencies for progress

  • Whilst you happen to haven’t received pipenv or train to assist watch over a digital environment the utilization of various devices, you then definately’ll be in a trouble to make the most of

  • In expose to originate documentation

    (cd docs && create html)
    start docs/originate/html/index.html

    ❗Basic: Constructing documentation will attain example scripts, so be terribly cautious when writing sample scripts that create make the most of of buying and selling channel.

Necessities for purchasing and promoting

Proper shopping for and promoting and getting access to steadiness of your story requires authentication with an API key. In expose to seek out one:

  1. You must seemingly seemingly accrued have an story at blockchain.com | change

  2. Produce API key here and retailer information. Inform, you may be succesful to be in a trouble to have setup key with permissions be taught about and be taught about & substitute.

  3. You must seemingly seemingly accrued obtain an email correspondence asking you to set off API key.

  4. Setup the next environment variable

export BLOCKCHAIN_API_SECRET="__ENTER_YOUR_API_SECRET_HERE__"

πŸ”₯Tip: Whilst you happen to make the most of pipenv you then definately’ll be in a trouble to regular construct it into .env file (uncared for by git) on the root of the cloned itemizing

Demos

Take heed to all public channels

asciicast listen to public channels

✏️Inform: There are time.sleep(2) between calling totally different techniques, in expose to be succesful to gape intermediate outcomes.

Produce market and restrict orders

asciicast create market and limit orders

✏️Inform: Every and every orders obtained rejected (anticipated behaviour) on story of of invalid amount and value being to colossal.

TODO

  • Exams
  • One thing irregular is happening with unsubscribing from channels in bulk for the next ones:
[
{"channel": "l2", "symbol": "BTC-USD"},
{"channel": "ticker", "symbol": "BTC-USD"},
{"channel": "trades", "symbol": "BTC-USD"}
]
[
{"seqnum":1,"event":"subscribed","channel":"prices","symbol":"BTC-USD","granularity":60},
{"seqnum":2,"event":"subscribed","channel":"prices","symbol":"ETH-USD","granularity":60},
{"seqnum":3,"event":"subscribed","channel":"prices","symbol":"BTC-USD","granularity":300},
{"seqnum":4,"event":"subscribed","channel":"prices","symbol":"ETH-USD","granularity":300}
]
[
{"seqnum":0,"event":"subscribed","channel":"ticker","symbol":"BTC-USD"},
{"seqnum":1,"event":"snapshot","channel":"ticker","symbol":"BTC-USD","price_24h":8744.9,"volume_24h":155.77132628,"last_trade_price":8881.0},
{"seqnum":2,"event":"updated","channel":"ticker","symbol":"BTC-USD","price_24h":8754.8,"volume_24h":155.70446581}
]

LEAVE A REPLY

Please enter your comment!
Please enter your name here