{ "info": { "author": "dex.blue", "author_email": "tech@dex.blue", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# dex.blue python API wrapper\n\nThis is the official Python API wrapper for communicating with the dex.blue API.\n\nFor further information head to the [API Documentation](https://docs.dex.blue)\n\n## Installation\n\nInstall via [pip](https://pypi.org/project/dexblue-api/)\n\n```bash\npip install dexblue-api\n```\n\n## Introduction\n\ndex.blue is a trustless, non-custodial exchange. This means, that every input which moves funds needs to by signed with your private key.\n\n You either have to sign orders directly from your wallet address or use a [Delegated Signing Key](https://docs.dex.blue/delegation/).\n\nFor the most straightforward integration, which does not require you to directly interact with the blockchain, you can just use our [webinterface](https://dex.blue/trading) for deposits & withdrawals and register a [Delegated Signing Key](https://docs.dex.blue/delegation/) in the settings \u2699 section.\n\nIf you want to handle deposits and withdrawals from your bot, please check out [this page](https://docs.dex.blue/contract/) of our documentation.\n\n## Initializing a connection\n\nTha connection can be initialized with different parameters.\n\n```python\nimport dexblue\n\ndb = dexblue.WsAPI( # all parameters are optional\n # authenticate either an account...\n account=,\n # ...or a delegate\n delegate=,\n # optional parameters\n endpoint=, # default: wss://api.dex.blue/ws\n web3Provider=, # default: https://mainnet.infura.io/\n network=, # default: mainnet\n autoAuth= # default: True\n)\n\ndef callback(packet):\n # your logic here\n\ndb.on('wsOpen', callback)\n```\n\nIt is possible to load a encrypted key to authenticate your connection\n\n```python\nkey = dexblue.utils.readPrivateKeyFromFile(keyfile, password)\n\ndb = dexblue.WsAPI(delegate=key)\n```\n\n## Calling a method\n\nThis Library provides a wrapper function for [every method offered by the dex.blue API](https://docs.dex.blue/websocket/), which can be invoked with eg: `db.methods.getOrderBookSnapshot(parameters, callback, ...)`.\n\nFor a full list of the available methods and parameters, please refer to the [websocket API documentation](https://docs.dex.blue/websocket/).\n\nAdditionally the library offers some helper functions to deal with all of the hard and annoying stuff like hashing and signing:\n\n- `db.authenticate(privKey)` - called automatically, when you pass an account to the constructor\n- `db.authenticateDelegate(privKey)` - Called automatically, when you pass an delegate to the constructor\n- `db.placeOrder(order, callback)` - This function abstracts all the stress of contructing and signing orders away from you. Very recommended to use this!\n- `db.hashOrder(order) returns hash` - This function helps you hashing the order inputs correctly. You then need to sign the order by yourself.\n\n### Events\n\nYou can subscribe to any server and websocket events using the following functions:\n\nEvents:\n\n- Market Events:\n - `book20d5` ... `book20d1` Orderbook with a depth of 20 with 5 ... 1 decimal precision (for the rate)\n - `book100d5` ... `book100d1` Orderbook with a depth of 10 with 5 ... 1 decimal precision (for the rate)\n - `bookd5` ... `bookd1` Full orderbook with 5 ... 1 decimal precision (for the rate)\n - `trades` Trades Feed of the market\n - `ticker` The ticker of the market\n- Other Events:\n - `rate` subscribe to a ETH to fiat conversion rate e.g. ETHUSD, available are ETH traded against the config.conversion_currencies. (sub with: `{markets:[\"ETHUSD\"],events:[\"rate\"]}`)\n - `chainStats` subscribe to the servers block height and gas price (sub with: `{markets:[\"ethereum\"],events:[\"chainStats\"]}`)\n- Websocket Events (no need to subscribe, just listen)\n - `wsOpen` websocket connection is opened\n - `message` every received message\n - `wsError` websocket errored\n - `wsClose` websocket conn is closed\n\n### Subscribing to events\n\n```python\ndb.methods.subscribe({\n \"markets\" : [\"ETHDAI\", \"MKRETH\"],\n \"events\" : [\"trades\", \"book20d5\"]\n})\n\ndb.on('trade', print)\ndb.on('book', print)\n```\n\n### Callback\n\nA callback must have at least one paramater which is the received data. The following arguments are passed through from the callback definition.\n\n```python\ndef callback(packet, parameter1, parameter2, ...):\n print(packet, parameter1, parameter2)\n\ndb.on('listed', callback, \"parameter1\", \"parameter2\")\n```\n\nThe packet parameter is a dict, which has the following structure\n\n```python\n{\n \"chan\": , # The channel id is documented in the dex.blue api docs\n : ,\n \"packet\": # the same packet which the server sent\n}\n```\n\n### Placing an order\n\n```python\ndef callback(packet):\n # If you passed an account of delegate to the constructor, you will authenticated automatically\n # All private commands should be sent after we are successfully authenticated\n # If no expiry is passed, a default expiry of one month will be applied\n\n # This function supports either very abstracted input\n db.placeOrder({\n \"market\" : \"ETHDAI\",\n \"amount\" : -1, # positive amount implies buy order, negative sell\n \"rate\" : 300\n }, print)\n\n # But also supports all the granular API parameters\n orderIdentifier = int(time.time()) # client-set order identifier\n db.placeOrder({\n \"cid\" : orderIdentifier,\n \"sellToken\" : \"0x0000000000000000000000000000000000000000\", # ETH\n \"sellAmount\" : \"1000000000000000000\", # 1 ETH\n \"buyToken\" : \"0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359\", # DAI\n \"buyAmount\" : \"300000000000000000000\", # 300 DAI\n \"expiry\" : int(time.time() + 86400 * 2), # order is valid 2 days (different from the timeInForce parameter)\n \"hidden\" : False,\n \"postOnly\" : True, # order is either maker or canceled\n \"rebateToken\" : \"buy\", # we want to receive our rebate in DAI (the token we buy)\n # ... more possibilities are listed here: https://docs.dex.blue/websocket/#placeorder\n }, print)\n\ndb.on('auth', callback)\n```\n\n### Error handeling\n\n```python\ndef reconnect_cb(packet):\n print('Reconnect in: ' + str(packet[\"reconnect\"][\"timeout\"]) + 's. Message: ' + packet[\"reconnect\"][\"message\"])\n\ndb.on('reconnect', reconnect_cb) # server sent a reconnect instruction\n\ndb.on('error', print) # handle error (probably resulting in a disconnect)\n\ndb.on('wsClose', print) # handle disconnect\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/dexdotblue/dexblue-api-py", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "dexblue-api-python", "package_url": "https://pypi.org/project/dexblue-api-python/", "platform": "", "project_url": "https://pypi.org/project/dexblue-api-python/", "project_urls": { "Homepage": "https://github.com/dexdotblue/dexblue-api-py" }, "release_url": "https://pypi.org/project/dexblue-api-python/0.1.0b1/", "requires_dist": [ "web3 (>=5.0.2)", "websockets (>=7.0)" ], "requires_python": ">=3.7", "summary": "dex.blue API wrapper for python", "version": "0.1.0b1" }, "last_serial": 5862794, "releases": { "0.1.0b1": [ { "comment_text": "", "digests": { "md5": "d9ed42d88d0ab73644ae3b1d28ed005f", "sha256": "448ba073802208c82f769720138ef79b726bb06983b3b4480404165c65d9715e" }, "downloads": -1, "filename": "dexblue_api_python-0.1.0b1-py3-none-any.whl", "has_sig": false, "md5_digest": "d9ed42d88d0ab73644ae3b1d28ed005f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 13658, "upload_time": "2019-09-20T15:00:24", "url": "https://files.pythonhosted.org/packages/84/09/e8aadc6b28c46451b18b5c869063423dbcc969a2c8d1ba4313393f1cddc5/dexblue_api_python-0.1.0b1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "729d3c0d03a5087d6e6b2c1a487b2922", "sha256": "23acb5ff2cd07fa98e6249a2427db1a4d83f98e32d4e613df0eaba8fb8331c51" }, "downloads": -1, "filename": "dexblue-api-python-0.1.0b1.tar.gz", "has_sig": false, "md5_digest": "729d3c0d03a5087d6e6b2c1a487b2922", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 14939, "upload_time": "2019-09-20T15:00:27", "url": "https://files.pythonhosted.org/packages/e8/19/6e5e85de8797f2933720df19f7e51080f6ec97fabd5a9d1c5a008b916e19/dexblue-api-python-0.1.0b1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d9ed42d88d0ab73644ae3b1d28ed005f", "sha256": "448ba073802208c82f769720138ef79b726bb06983b3b4480404165c65d9715e" }, "downloads": -1, "filename": "dexblue_api_python-0.1.0b1-py3-none-any.whl", "has_sig": false, "md5_digest": "d9ed42d88d0ab73644ae3b1d28ed005f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 13658, "upload_time": "2019-09-20T15:00:24", "url": "https://files.pythonhosted.org/packages/84/09/e8aadc6b28c46451b18b5c869063423dbcc969a2c8d1ba4313393f1cddc5/dexblue_api_python-0.1.0b1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "729d3c0d03a5087d6e6b2c1a487b2922", "sha256": "23acb5ff2cd07fa98e6249a2427db1a4d83f98e32d4e613df0eaba8fb8331c51" }, "downloads": -1, "filename": "dexblue-api-python-0.1.0b1.tar.gz", "has_sig": false, "md5_digest": "729d3c0d03a5087d6e6b2c1a487b2922", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 14939, "upload_time": "2019-09-20T15:00:27", "url": "https://files.pythonhosted.org/packages/e8/19/6e5e85de8797f2933720df19f7e51080f6ec97fabd5a9d1c5a008b916e19/dexblue-api-python-0.1.0b1.tar.gz" } ] }