Blockchain.com Exchange API
Project description
Blockchain Exchange Python API
Table of Contents
Generated with DocToc
Last Update: 2020-05-11
Features
-
Subscribe to all websocket channels available at blockchain.com | exchage:
- Heartbeat :hearts:
- Orderbook L2 :blue_book:
- Orderbook L3 :green_book:
- Prices :atm:
- Symbols :symbols:
- Ticker :chart_with_upwards_trend:
- Trades :currency_exchange:
- Trading :bank: :closed_lock_with_key:
- Balance :moneybag: :closed_lock_with_key:
-
Subscription to new channels doesn't require client restart
-
Create Market orders
-
Create Limit orders
All API is available through a websocket client:
import logging
from blockchain_exchange.client import BlockchainWebsocketClient
logging.basicConfig(level=logging.INFO)
client = BlockchainWebsocketClient()
See our documentation for API reference and gallery of examples for more info.
Quick start
- Get source code
git clone git@github.com:ilya-bc/blockchain-exchange-api.git
cd blockchain-exchange-api
- Install package. Since there are hundred ways to do that, a standardised way for this project is with
Makefile
. It will create virtual environment withpipenv
and will use python 3.7 as its interpreter
# For general use
make install
# For development
make install-dev
Prerequisites for trading
Actual trading and accessing balance of your account requires authentication with an API key. In order to get one:
-
You should have an account at blockchain.com | exchange
-
Create API key here and store information. Note, you can have setup key with permissions
view
andview & trade
. -
You should receive an email asking you to activate API key.
-
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
: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
: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"}
]
- Check contradiction with API docs on prices channel
[
{"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}
]
- Docs doesn't say that ticker channel sends update events
[
{"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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.