Package: bcx
Blockchain Exchange Python APITable of ContentsGenerated withDocTocLast Update: 2020-05-17FeaturesInstallationFor general useFor developmentPrerequisites for tradingDemosListen to all public channelsCreate market and limit ordersTODOFeaturesSubscribe to all websocket channels available atblockchain.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 restartCreate Market ordersCreate Limit ordersAll API is available through a websocket client:importloggingfrombcx.clientimportBlockchainWebsocketClientlogging.basicConfig(level=logging.INFO)client=BlockchainWebsocketClient()See our documentation forAPI referenceandgallery of examplesfor more info.InstallationIn order to get started you should havePython>=3.6installed.For general useThis is as simple as runningpipinstallbcxFor developmentGet source codegitclonegit@github.com:ilya-bc/blockchain-exchange-api.gitcdblockchain-exchange-apiInstall package in editable mode. Since there are hundred ways to do that, a standardised way for this project is withMakefile. It will create virtual environment withpipenvbased onpython==3.7and install all necessary dependencies for developmentmakeinstall-devIf you don't havepipenvor prefer to manage a virtual environment using different tools, then you can usepipinstall-e'.[dev]'In order to build documentation(cddocs&&makehtml)opendocs/build/html/index.html:exclamation:Important:Building documentation will executeexample scripts, so beextremely cautiouswhen writing sample scripts that make use oftrading channel.Prerequisites for tradingActual trading and accessing balance of your accountrequires authenticationwith an API key. In order to get one:You should have an account atblockchain.com | exchangeCreate API keyhereand store information. Note, you can have setup key with permissionsviewandview & trade.You should receive an email asking you to activate API key.Setup the following environment variableexportBLOCKCHAIN_API_SECRET="__ENTER_YOUR_API_SECRET_HERE__":fire:Tip:If you usepipenvthen you can just put it into.envfile (ignored by git) at the root of the cloned directoryDemosListen to all public channelsScriptScript extended:pencil2:Note:There aretime.sleep(2)between calling different methods, in order to be able to see intermediate results.Create market and limit ordersScriptScript extened:pencil2:Note:Both orders got rejected (expected behaviour) because of invalid quantity and price being to big.TODOTestsSomething 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 onprices 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 thatticker channelsends 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}]