Skip to main content

Blockchain.com Exchange API

Project description

Blockchain Exchange Python API

forthebadge

Table of Contents

Generated with DocToc

Last Update: 2020-05-17

Features

All API is available through a websocket client:

import logging
from bcx.client import BlockchainWebsocketClient

logging.basicConfig(level=logging.INFO)

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

pip install bcx

For development

  • Get source code

    git clone git@github.com:ilya-bc/blockchain-exchange-api.git
    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

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

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

    (cd docs && make html)
    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

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:
[
{"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}
]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bcx-0.2.1.tar.gz (3.0 MB view details)

Uploaded Source

Built Distribution

bcx-0.2.1-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file bcx-0.2.1.tar.gz.

File metadata

  • Download URL: bcx-0.2.1.tar.gz
  • Upload date:
  • Size: 3.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for bcx-0.2.1.tar.gz
Algorithm Hash digest
SHA256 60b6d9f33c815deb2653d790236d2de749d6abb7fc7293621452f696c22c33ac
MD5 355b5575d16bdb32f654ce0c14015326
BLAKE2b-256 ac3072f7e4c860555cffc618a510eee87afbf14242a064aea9b02eea66873481

See more details on using hashes here.

File details

Details for the file bcx-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: bcx-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for bcx-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a85da69d192e28bc5331fcb2b4c446ff789ca9e78719af84346805b9cfa49ce
MD5 36974fcf300c592cc69af09076c2d2fd
BLAKE2b-256 db508bf458cfe198909a6b50aa790117167e0dcaeae1457bb5245597baf431b3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page