{ "info": { "author": "Daniel Paquin", "author_email": "dpaq34@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Intended Audience :: Financial and Insurance Industry", "Intended Audience :: Information Technology", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# coinbasepro-python\n[![Build Status](https://travis-ci.org/yiwensong/coinbasepro-python.svg?branch=master)](https://travis-ci.org/yiwensong/coinbasepro-python)\n[![Coverage Status](https://coveralls.io/repos/github/yiwensong/coinbasepro-python/badge.svg?branch=master)](https://coveralls.io/github/yiwensong/coinbasepro-python?branch=master)\n[![Documentation Status](https://readthedocs.org/projects/cbpro2/badge/?version=master&style=flat)](https://cbpro2.readthedocs.io/en/master/)\n[![PyPI version](https://badge.fury.io/py/cbpro2.svg)](https://pypi.org/project/cbpro2/)\n\nThe Python client for the [Coinbase Pro API](https://docs.pro.coinbase.com/) (formerly known as\nthe GDAX)\n\n### Note\nThis is a fork of the original [cbpro project](https://github.com/danpaquin/coinbasepro-python).\nI created this fork because between September and October of 2018, the maintainers of\nthat project seemed to be inactive in reviewing and merging pull requests. The goal of\nthis fork is as follows:\n- Keep reasonably up-to-date with upstream\n- Improve developer workflow and style\n- Surface coverage stats to encourage unit testing\n\n## Benefits\n- A simple to use python wrapper for both public and authenticated endpoints.\n- In about 10 minutes, you could be programmatically trading on one of the\nlargest Bitcoin exchanges in the *world*!\n- Do not worry about handling the nuances of the API with easy-to-use methods\nfor every API endpoint.\n- Gain an advantage in the market by getting under the hood of CB Pro to learn\nwhat and who is behind every tick.\n\n## Under Development\n- Test Scripts\n- Additional Functionality for the real-time order book\n- FIX API Client **Looking for assistance**\n\n## Getting Started\nThis README is documentation on the syntax of the python client presented in\nthis repository. See function docstrings for full syntax details. \n**This API attempts to present a clean interface to CB Pro, but in order to use it\nto its full potential, you must familiarize yourself with the official CB Pro\ndocumentation.**\n\n- https://docs.pro.coinbase.com/\n\n- You may manually install the project or use ```pip```:\n```python\npip install cbpro2\n#or\npip install git+git://github.com/yiwensong/coinbasepro-python.git\n```\n\n### Public Client\nOnly some endpoints in the API are available to everyone. The public endpoints\ncan be reached using ```PublicClient```\n\n```python\nimport cbpro\npublic_client = cbpro.PublicClient()\n```\n\n### PublicClient Methods\n- [get_products](https://docs.pro.coinbase.com//#get-products)\n```python\npublic_client.get_products()\n```\n\n- [get_product_order_book](https://docs.pro.coinbase.com/#get-product-order-book)\n```python\n# Get the order book at the default level.\npublic_client.get_product_order_book('BTC-USD')\n# Get the order book at a specific level.\npublic_client.get_product_order_book('BTC-USD', level=1)\n```\n\n- [get_product_ticker](https://docs.pro.coinbase.com/#get-product-ticker)\n```python\n# Get the product ticker for a specific product.\npublic_client.get_product_ticker(product_id='ETH-USD')\n```\n\n- [get_product_trades](https://docs.pro.coinbase.com/#get-trades) (paginated)\n```python\n# Get the product trades for a specific product.\n# Returns a generator\npublic_client.get_product_trades(product_id='ETH-USD')\n```\n\n- [get_product_historic_rates](https://docs.pro.coinbase.com/#get-historic-rates)\n```python\npublic_client.get_product_historic_rates('ETH-USD')\n# To include other parameters, see function docstring:\npublic_client.get_product_historic_rates('ETH-USD', granularity=3000)\n```\n\n- [get_product_24hr_stats](https://docs.pro.coinbase.com/#get-24hr-stats)\n```python\npublic_client.get_product_24hr_stats('ETH-USD')\n```\n\n- [get_currencies](https://docs.pro.coinbase.com/#get-currencies)\n```python\npublic_client.get_currencies()\n```\n\n- [get_time](https://docs.pro.coinbase.com/#time)\n```python\npublic_client.get_time()\n```\n\n### Authenticated Client\n\nNot all API endpoints are available to everyone.\nThose requiring user authentication can be reached using `AuthenticatedClient`.\nYou must setup API access within your\n[account settings](https://www.pro.coinbase.com/settings/api).\nThe `AuthenticatedClient` inherits all methods from the `PublicClient`\nclass, so you will only need to initialize one if you are planning to\nintegrate both into your script.\n\n```python\nimport cbpro\nauth_client = cbpro.AuthenticatedClient(key, b64secret, passphrase)\n# Use the sandbox API (requires a different set of API access credentials)\nauth_client = cbpro.AuthenticatedClient(key, b64secret, passphrase,\n api_url=\"https://api-public.sandbox.pro.coinbase.com\")\n```\n\n### Pagination\nSome calls are [paginated](https://docs.pro.coinbase.com/#pagination), meaning multiple\ncalls must be made to receive the full set of data. The CB Pro Python API provides\nan abstraction for paginated endpoints in the form of generators which provide a\nclean interface for iteration but may make multiple HTTP requests behind the\nscenes. The pagination options `before`, `after`, and `limit` may be supplied as\nkeyword arguments if desired, but aren't necessary for typical use cases.\n```python\nfills_gen = auth_client.get_fills()\n# Get all fills (will possibly make multiple HTTP requests)\nall_fills = list(fills_gen)\n```\nOne use case for pagination parameters worth pointing out is retrieving only\nnew data since the previous request. For the case of `get_fills()`, the\n`trade_id` is the parameter used for indexing. By passing\n`before=some_trade_id`, only fills more recent than that `trade_id` will be\nreturned. Note that when using `before`, a maximum of 100 entries will be\nreturned - this is a limitation of CB Pro.\n```python\nfrom itertools import islice\n# Get 5 most recent fills\nrecent_fills = islice(auth_client.get_fills(), 5)\n# Only fetch new fills since last call by utilizing `before` parameter.\nnew_fills = auth_client.get_fills(before=recent_fills[0]['trade_id'])\n```\n\n### AuthenticatedClient Methods\n- [get_accounts](https://docs.pro.coinbase.com/#list-accounts)\n```python\nauth_client.get_accounts()\n```\n\n- [get_account](https://docs.pro.coinbase.com/#get-an-account)\n```python\nauth_client.get_account(\"7d0f7d8e-dd34-4d9c-a846-06f431c381ba\")\n```\n\n- [get_account_history](https://docs.pro.coinbase.com/#get-account-history) (paginated)\n```python\n# Returns generator:\nauth_client.get_account_history(\"7d0f7d8e-dd34-4d9c-a846-06f431c381ba\")\n```\n\n- [get_account_holds](https://docs.pro.coinbase.com/#get-holds) (paginated)\n```python\n# Returns generator:\nauth_client.get_account_holds(\"7d0f7d8e-dd34-4d9c-a846-06f431c381ba\")\n```\n\n- [buy & sell](https://docs.pro.coinbase.com/#place-a-new-order)\n```python\n# Buy 0.01 BTC @ 100 USD\nauth_client.buy(price='100.00', #USD\n size='0.01', #BTC\n order_type='limit',\n product_id='BTC-USD')\n```\n```python\n# Sell 0.01 BTC @ 200 USD\nauth_client.sell(price='200.00', #USD\n size='0.01', #BTC\n order_type='limit',\n product_id='BTC-USD')\n```\n```python\n# Limit order-specific method\nauth_client.place_limit_order(product_id='BTC-USD',\n side='buy',\n price='200.00',\n size='0.01')\n```\n```python\n# Place a market order by specifying amount of USD to use.\n# Alternatively, `size` could be used to specify quantity in BTC amount.\nauth_client.place_market_order(product_id='BTC-USD',\n side='buy',\n funds='100.00')\n```\n```python\n# Stop order. `funds` can be used instead of `size` here.\nauth_client.place_stop_order(product_id='BTC-USD',\n side='buy',\n price='200.00',\n size='0.01')\n```\n\n- [cancel_order](https://docs.pro.coinbase.com/#cancel-an-order)\n```python\nauth_client.cancel_order(\"d50ec984-77a8-460a-b958-66f114b0de9b\")\n```\n- [cancel_all](https://docs.pro.coinbase.com/#cancel-all)\n```python\nauth_client.cancel_all(product_id='BTC-USD')\n```\n\n- [get_orders](https://docs.pro.coinbase.com/#list-orders) (paginated)\n```python\n# Returns generator:\nauth_client.get_orders()\n```\n\n- [get_order](https://docs.pro.coinbase.com/#get-an-order)\n```python\nauth_client.get_order(\"d50ec984-77a8-460a-b958-66f114b0de9b\")\n```\n\n- [get_fills](https://docs.pro.coinbase.com/#list-fills) (paginated)\n```python\n# All return generators\nauth_client.get_fills()\n# Get fills for a specific order\nauth_client.get_fills(order_id=\"d50ec984-77a8-460a-b958-66f114b0de9b\")\n# Get fills for a specific product\nauth_client.get_fills(product_id=\"ETH-BTC\")\n```\n\n- [deposit & withdraw](https://docs.pro.coinbase.com/#depositwithdraw)\n```python\ndepositParams = {\n 'amount': '25.00', # Currency determined by account specified\n 'coinbase_account_id': '60680c98bfe96c2601f27e9c'\n}\nauth_client.deposit(depositParams)\n```\n```python\n# Withdraw from CB Pro into Coinbase Wallet\nwithdrawParams = {\n 'amount': '1.00', # Currency determined by account specified\n 'coinbase_account_id': '536a541fa9393bb3c7000023'\n}\nauth_client.withdraw(withdrawParams)\n```\n\n### WebsocketClient\nIf you would like to receive real-time market updates, you must subscribe to the\n[websocket feed](https://docs.pro.coinbase.com/#websocket-feed).\n\n#### Subscribe to a single product\n```python\nimport cbpro\n# Paramters are optional\nwsClient = cbpro.WebsocketClient(url=\"wss://ws-feed.pro.coinbase.com\", products=\"BTC-USD\")\n# Do other stuff...\nwsClient.close()\n```\n\n#### Subscribe to multiple products\n```python\nimport cbpro\n# Paramaters are optional\nwsClient = cbpro.WebsocketClient(url=\"wss://ws-feed.pro.coinbase.com\",\n products=[\"BTC-USD\", \"ETH-USD\"])\n# Do other stuff...\nwsClient.close()\n```\n\n### WebsocketClient + Mongodb\nThe ```WebsocketClient``` now supports data gathering via MongoDB. Given a\nMongoDB collection, the ```WebsocketClient``` will stream results directly into\nthe database collection.\n```python\n# import PyMongo and connect to a local, running Mongo instance\nfrom pymongo import MongoClient\nimport cbpro\nmongo_client = MongoClient('mongodb://localhost:27017/')\n\n# specify the database and collection\ndb = mongo_client.cryptocurrency_database\nBTC_collection = db.BTC_collection\n\n# instantiate a WebsocketClient instance, with a Mongo collection as a parameter\nwsClient = cbpro.WebsocketClient(url=\"wss://ws-feed.pro.coinbase.com\", products=\"BTC-USD\",\n mongo_collection=BTC_collection, should_print=False)\nwsClient.start()\n```\n\n### WebsocketClient Methods\nThe ```WebsocketClient``` subscribes in a separate thread upon initialization.\nThere are three methods which you could overwrite (before initialization) so it\ncan react to the data streaming in. The current client is a template used for\nillustration purposes only.\n\n- onOpen - called once, *immediately before* the socket connection is made, this\nis where you want to add initial parameters.\n- onMessage - called once for every message that arrives and accepts one\nargument that contains the message of dict type.\n- on_close - called once after the websocket has been closed.\n- close - call this method to close the websocket connection (do not overwrite).\n```python\nimport cbpro, time\nclass myWebsocketClient(cbpro.WebsocketClient):\n def on_open(self):\n self.url = \"wss://ws-feed.pro.coinbase.com/\"\n self.products = [\"LTC-USD\"]\n self.message_count = 0\n print(\"Lets count the messages!\")\n def on_message(self, msg):\n self.message_count += 1\n if 'price' in msg and 'type' in msg:\n print (\"Message type:\", msg[\"type\"],\n \"\\t@ {:.3f}\".format(float(msg[\"price\"])))\n def on_close(self):\n print(\"-- Goodbye! --\")\n\nwsClient = myWebsocketClient()\nwsClient.start()\nprint(wsClient.url, wsClient.products)\nwhile (wsClient.message_count < 500):\n print (\"\\nmessage_count =\", \"{} \\n\".format(wsClient.message_count))\n time.sleep(1)\nwsClient.close()\n```\n\n### Real-time OrderBook\nThe ```OrderBook``` subscribes to a websocket and keeps a real-time record of\nthe orderbook for the product_id input. Please provide your feedback for future\nimprovements.\n\n```python\nimport cbpro, time\norder_book = cbpro.OrderBook(product_id='BTC-USD')\norder_book.start()\ntime.sleep(10)\norder_book.close()\n```\n\n## Development\n\n### Development Environment\nA development environment can be created and activated with the commands\n```bash\nmake venv && . venv/bin/activate\n```\n\n### Automated Testing\nUnit test framework uses pytest, coverage, and tox. A test suite is under development,\nplease contribute to the coverage. Tests for the authenticated client require a\nset of sandbox API credentials. To provide them, rename\n`api_config.json.example` in the tests folder to `api_config.json` and edit the\nfile accordingly. To run the tests, start in the project directory and run\n\n```bash\nmake test\n```\n\n### Pre-commit\nThis project uses pre-commit to enforce coding style. You can run pre-commit with\nthe following command (after activating the venv)\n```bash\npre-commit run --files [FILES]\n```\nYou can also run\n```bash\npre-commit run --all-files\n```\nbut that is guaranteed to fail because of legacy code that has yet to be linted.", "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/yiwensong/coinbasepro-python", "keywords": "gdax,gdax-api,orderbook,trade,bitcoin,ethereum,BTC,ETH,client,api,wrapper,exchange,crypto,currency,trading,trading-api,coinbase,pro,prime,coinbasepro", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "cbpro2", "package_url": "https://pypi.org/project/cbpro2/", "platform": "", "project_url": "https://pypi.org/project/cbpro2/", "project_urls": { "Homepage": "https://github.com/yiwensong/coinbasepro-python" }, "release_url": "https://pypi.org/project/cbpro2/1.0.4/", "requires_dist": null, "requires_python": "", "summary": "The unofficial Python client for the Coinbase Pro API", "version": "1.0.4" }, "last_serial": 4434437, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "fd25ca6d1e6e210d12c0f37d4acd1dac", "sha256": "0928ddf6c159d5d5ab96a34aa1a27af59cb6d3c0d46cc8a2b141d1b944e2f1d0" }, "downloads": -1, "filename": "cbpro2-1.0.0.tar.gz", "has_sig": false, "md5_digest": "fd25ca6d1e6e210d12c0f37d4acd1dac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23525, "upload_time": "2018-10-17T06:10:58", "url": "https://files.pythonhosted.org/packages/75/5a/9ff0afcf94d60931937cc965b00557eefd3d952948019fe5fe91ff5fca06/cbpro2-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "65df893ea9684819ea99069c7c45c779", "sha256": "4a34d01bc400b3a87892375aa9edb651faa8a935cfdc23dd8a52eb2626811e2c" }, "downloads": -1, "filename": "cbpro2-1.0.1.tar.gz", "has_sig": false, "md5_digest": "65df893ea9684819ea99069c7c45c779", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23542, "upload_time": "2018-10-17T06:13:38", "url": "https://files.pythonhosted.org/packages/16/8f/6f7b17fc7b50ba31e8cef42959138b7aad23f84643ede46da16814788261/cbpro2-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "512701365fd88d30eb3703f572b31218", "sha256": "083f81f1f739d829facb9bfdcbad5e097058094f0fc791fefc23f100085efe87" }, "downloads": -1, "filename": "cbpro2-1.0.2.tar.gz", "has_sig": false, "md5_digest": "512701365fd88d30eb3703f572b31218", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22869, "upload_time": "2018-10-17T06:55:27", "url": "https://files.pythonhosted.org/packages/d0/a7/db234dda1ed09a65199625faba39f8fbcbcaaa87c41bffd6fe006f97f6c8/cbpro2-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "07c7c6ee9dfcd079a19185e65105e499", "sha256": "b556a6678fcf47382b66a747ddebed2a05312f1e74bdd9ef7aa3a2691bd10c10" }, "downloads": -1, "filename": "cbpro2-1.0.3.tar.gz", "has_sig": false, "md5_digest": "07c7c6ee9dfcd079a19185e65105e499", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22938, "upload_time": "2018-10-17T08:09:17", "url": "https://files.pythonhosted.org/packages/d2/30/66a1895189ec2bca046a224bca8e96070ed30b15157fe98400aaf1aeb4ca/cbpro2-1.0.3.tar.gz" } ], "1.0.4": [ { "comment_text": "", "digests": { "md5": "eafb575a62f9cbbd917b779edfa5f806", "sha256": "4e985b85a45d771fd1ea5e40b2c54dd583882ec0b5ba1792728615e5d1aa9cfd" }, "downloads": -1, "filename": "cbpro2-1.0.4.tar.gz", "has_sig": false, "md5_digest": "eafb575a62f9cbbd917b779edfa5f806", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23029, "upload_time": "2018-10-31T05:13:13", "url": "https://files.pythonhosted.org/packages/9a/36/239e798d76ea20d699e1aa823497558461d621cc5d2c35feb8bfffaf9b84/cbpro2-1.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "eafb575a62f9cbbd917b779edfa5f806", "sha256": "4e985b85a45d771fd1ea5e40b2c54dd583882ec0b5ba1792728615e5d1aa9cfd" }, "downloads": -1, "filename": "cbpro2-1.0.4.tar.gz", "has_sig": false, "md5_digest": "eafb575a62f9cbbd917b779edfa5f806", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23029, "upload_time": "2018-10-31T05:13:13", "url": "https://files.pythonhosted.org/packages/9a/36/239e798d76ea20d699e1aa823497558461d621cc5d2c35feb8bfffaf9b84/cbpro2-1.0.4.tar.gz" } ] }