项目作者: ilya-bc

项目描述 :
Blockchain Exchange API in Python
高级语言: Python
项目地址: git://github.com/ilya-bc/blockchain-exchange-api.git
创建时间: 2020-05-03T16:29:04Z
项目社区:https://github.com/ilya-bc/blockchain-exchange-api

开源协议:MIT License

下载


Blockchain Exchange Python API

forthebadge

Downloads

Table of Contents

Generated with DocToc

Last Update: 2020-05-17

Features

All API is available through a websocket client:

  1. import logging
  2. from bcx.client import BlockchainWebsocketClient
  3. logging.basicConfig(level=logging.INFO)
  4. client = BlockchainWebsocketClient()

See our documentation for API reference and gallery of examples for more info.

Installation

In order to get started you should have Python>=3.6 installed.

For general use

This is as simple as running

  1. pip install bcx

For development

  • Get source code

    1. git clone git@github.com:ilya-bc/blockchain-exchange-api.git
    2. cd blockchain-exchange-api
  • Install package in editable mode. Since there are hundred ways to do that, a standardised way for this project is with Makefile. It will create virtual environment with pipenv based on python==3.7 and install all necessary dependencies for development

    1. make install-dev
  • If you don’t have pipenv or prefer to manage a virtual environment using different tools, then you can use

    1. pip install -e '.[dev]'
  • In order to build documentation

    1. (cd docs && make html)
    2. open docs/build/html/index.html

    :exclamation: Important: Building documentation will execute example scripts, so be extremely cautious when writing sample scripts that make use of trading channel.

Prerequisites for trading

Actual trading and accessing balance of your account requires authentication with an API key. In order to get one:

  1. You should have an account at blockchain.com | exchange

  2. Create API key here and store information. Note, you can have setup key with permissions view and view & trade.

  3. You should receive an email asking you to activate API key.

  4. Setup the following environment variable

    1. export BLOCKCHAIN_API_SECRET="__ENTER_YOUR_API_SECRET_HERE__"

    :fire: Tip: If you use pipenv then you can just put it into .env file (ignored by git) at the root of the cloned directory

Demos

Listen to all public channels

asciicast listen to public channels

:pencil2: Note: There are time.sleep(2) between calling different methods, in order to be able to see intermediate results.

Create market and limit orders

asciicast create market and limit orders

:pencil2: Note: Both orders got rejected (expected behaviour) because of invalid quantity and price being to big.

TODO

  • Tests
  • Something weird is going on with unsubscribing from channels in bulk for the following ones:
    1. [
    2. {"channel": "l2", "symbol": "BTC-USD"},
    3. {"channel": "ticker", "symbol": "BTC-USD"},
    4. {"channel": "trades", "symbol": "BTC-USD"}
    5. ]
  • Check contradiction with API docs on prices channel
    1. [
    2. {"seqnum":1,"event":"subscribed","channel":"prices","symbol":"BTC-USD","granularity":60},
    3. {"seqnum":2,"event":"subscribed","channel":"prices","symbol":"ETH-USD","granularity":60},
    4. {"seqnum":3,"event":"subscribed","channel":"prices","symbol":"BTC-USD","granularity":300},
    5. {"seqnum":4,"event":"subscribed","channel":"prices","symbol":"ETH-USD","granularity":300}
    6. ]
  • Docs doesn’t say that ticker channel sends update events
    1. [
    2. {"seqnum":0,"event":"subscribed","channel":"ticker","symbol":"BTC-USD"},
    3. {"seqnum":1,"event":"snapshot","channel":"ticker","symbol":"BTC-USD","price_24h":8744.9,"volume_24h":155.77132628,"last_trade_price":8881.0},
    4. {"seqnum":2,"event":"updated","channel":"ticker","symbol":"BTC-USD","price_24h":8754.8,"volume_24h":155.70446581}
    5. ]