# Coinbase Advanced
Python library for the Coinbase Advanced Trade API.
## Features
- Support for all the [REST API endpoints](https://docs.cloud.coinbase.com/advanced-trade-api/docs/rest-api-overview) through convenient methods.
- Automatic parsing of API responses into relevant Python objects.
- Unit Tests based on real responses using fixtures.
- [Support for Cloud and Legacy Auth Schemas](https://docs.cloud.coinbase.com/advanced-trade-api/docs/rest-api-auth):
- Support for [Cloud API Trading Keys](https://cloud.coinbase.com/access/api) (Recommended)
- Support for [Legacy API Keys](https://www.coinbase.com/settings/api) (Deprecated but supported in this library for backward compatibility reasons)
## Example
```
from coinbaseadvanced.client import CoinbaseAdvancedTradeAPIClient
# Creating the client using Clould API Keys.
client = CoinbaseAdvancedTradeAPIClient.from_cloud_api_keys(API_KEY_NAME, PRIVATE_KEY)
# Listing accounts.
accounts_page = client.list_accounts()
print(accounts_page.size)
# Creating a limit order.
order_created = client.create_limit_order(client_order_id="lknalksdj89asdkl", product_id="ALGO-USD", side=Side.BUY, limit_price=".19", base_size=5)
```
## Websocket usage
Here is a basic example of how to use the CoinbaseWebSocketClient:
```
import asyncio
import time
from client_websocket import CoinbaseWebSocketClient
def handle_candle_event(event):
print(f"Received event candle: {event}")
async def main():
api_key = "your-api-key"
private_key = "-----BEGIN EC PRIVATE KEY-----\n\n-----END EC PRIVATE KEY-----"
client = CoinbaseWebSocketClient(api_key, private_key)
client.subscribe(["BTC-EUR"], "candles", callback=handle_candle_event)
while True:
time.sleep(1)
if __name__ == "__main__":
asyncio.run(main())
```
### Callback Functions
You can define your own callback functions to handle different types of events. The callback function will receive an event object that you can process as needed.
### Heartbeat Subscription
For each subscription to a market data channel, a separate heartbeat subscription is automatically created. This helps to ensure that the connection remains open and active.
### Concurrencyadding
Each subscription runs in a separate thread to ensure that multiple subscriptions can operate concurrently without blocking each other.
### Coinbase API Rate Limits
Before using this library, it is highly recommended to read the Coinbase API rate limits (https://docs.cdp.coinbase.com/advanced-trade/docs/ws-best-practices/) to understand the constraints and avoid exceeding the limits.
### Best Practices
It is also recommended to follow the WebSocket best practices (https://docs.cdp.coinbase.com/advanced-trade/docs/ws-best-practices/) provided by Coinbase for optimal performance and reliability.
### Subscription Recommendations
If possible, subscribe to one symbol per subscription to help balance the load on the Coinbase server and improve the reliability of your data stream.
## Installation
```
pip install coinbaseadvanced
```
## Contributing/Development
Any and all contributions are welcome! The process is simple:
1. Fork repo.
2. Install Requirements: `pip install -r requirements.txt`.
3. Make your changes.
4. Run the test suite `python -m unittest -v`.
5. Submit a pull request.
Raw data
{
"_id": null,
"home_page": "https://github.com/KmiQ/coinbase-advanced-python/",
"name": "coinbaseadvanced",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "api, coinbase, bitcoin, client, crypto",
"author": "Camilo Quintas",
"author_email": "kmiloc89@gmail.com",
"download_url": "https://github.com/KmiQ/coinbase-advanced-python/archive/refs/tags/1.2.0.tar.gz",
"platform": null,
"description": "# Coinbase Advanced\nPython library for the Coinbase Advanced Trade API.\n\n## Features\n- Support for all the [REST API endpoints](https://docs.cloud.coinbase.com/advanced-trade-api/docs/rest-api-overview) through convenient methods.\n- Automatic parsing of API responses into relevant Python objects.\n- Unit Tests based on real responses using fixtures.\n- [Support for Cloud and Legacy Auth Schemas](https://docs.cloud.coinbase.com/advanced-trade-api/docs/rest-api-auth):\n - Support for [Cloud API Trading Keys](https://cloud.coinbase.com/access/api) (Recommended)\n - Support for [Legacy API Keys](https://www.coinbase.com/settings/api) (Deprecated but supported in this library for backward compatibility reasons)\n\n## Example\n```\nfrom coinbaseadvanced.client import CoinbaseAdvancedTradeAPIClient\n\n# Creating the client using Clould API Keys.\nclient = CoinbaseAdvancedTradeAPIClient.from_cloud_api_keys(API_KEY_NAME, PRIVATE_KEY)\n\n# Listing accounts.\naccounts_page = client.list_accounts()\nprint(accounts_page.size)\n\n# Creating a limit order.\norder_created = client.create_limit_order(client_order_id=\"lknalksdj89asdkl\", product_id=\"ALGO-USD\", side=Side.BUY, limit_price=\".19\", base_size=5)\n```\n\n## Websocket usage\n\nHere is a basic example of how to use the CoinbaseWebSocketClient:\n\n```\nimport asyncio\nimport time\nfrom client_websocket import CoinbaseWebSocketClient\n\ndef handle_candle_event(event):\n print(f\"Received event candle: {event}\")\n\nasync def main():\n api_key = \"your-api-key\"\n private_key = \"-----BEGIN EC PRIVATE KEY-----\\n\\n-----END EC PRIVATE KEY-----\"\n \n client = CoinbaseWebSocketClient(api_key, private_key)\n client.subscribe([\"BTC-EUR\"], \"candles\", callback=handle_candle_event)\n \n while True:\n time.sleep(1)\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n\n```\n\n### Callback Functions\nYou can define your own callback functions to handle different types of events. The callback function will receive an event object that you can process as needed.\n\n### Heartbeat Subscription\nFor each subscription to a market data channel, a separate heartbeat subscription is automatically created. This helps to ensure that the connection remains open and active.\n\n### Concurrencyadding\nEach subscription runs in a separate thread to ensure that multiple subscriptions can operate concurrently without blocking each other.\n\n### Coinbase API Rate Limits\nBefore using this library, it is highly recommended to read the Coinbase API rate limits (https://docs.cdp.coinbase.com/advanced-trade/docs/ws-best-practices/) to understand the constraints and avoid exceeding the limits.\n\n### Best Practices\nIt is also recommended to follow the WebSocket best practices (https://docs.cdp.coinbase.com/advanced-trade/docs/ws-best-practices/) provided by Coinbase for optimal performance and reliability.\n\n### Subscription Recommendations\nIf possible, subscribe to one symbol per subscription to help balance the load on the Coinbase server and improve the reliability of your data stream.\n\n## Installation\n```\npip install coinbaseadvanced\n```\n## Contributing/Development\nAny and all contributions are welcome! The process is simple:\n 1. Fork repo.\n 2. Install Requirements: `pip install -r requirements.txt`.\n 3. Make your changes.\n 4. Run the test suite `python -m unittest -v`.\n 5. Submit a pull request.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Coinbase Advanced Trade API client library.",
"version": "1.2.0",
"project_urls": {
"Download": "https://github.com/KmiQ/coinbase-advanced-python/archive/refs/tags/1.2.0.tar.gz",
"Homepage": "https://github.com/KmiQ/coinbase-advanced-python/"
},
"split_keywords": [
"api",
" coinbase",
" bitcoin",
" client",
" crypto"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "686202a96c1b6665282c54195d116cc08abf263132819db95cb69042c9b020cc",
"md5": "463c6696f36c82dce4fa18239a060461",
"sha256": "058f6fee7360fee15e7fab06f32ac15f2c0abf148f2b696711cc46a13f9235c2"
},
"downloads": -1,
"filename": "coinbaseadvanced-1.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "463c6696f36c82dce4fa18239a060461",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 31039,
"upload_time": "2024-08-19T04:54:55",
"upload_time_iso_8601": "2024-08-19T04:54:55.412132Z",
"url": "https://files.pythonhosted.org/packages/68/62/02a96c1b6665282c54195d116cc08abf263132819db95cb69042c9b020cc/coinbaseadvanced-1.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-19 04:54:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "KmiQ",
"github_project": "coinbase-advanced-python",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "cfgv",
"specs": [
[
"==",
"3.3.1"
]
]
},
{
"name": "cryptography",
"specs": [
[
"==",
"42.0.4"
]
]
},
{
"name": "PyJWT",
"specs": [
[
"==",
"2.8.0"
]
]
},
{
"name": "requests",
"specs": [
[
"==",
"2.32.0"
]
]
},
{
"name": "rfc3986",
"specs": [
[
"==",
"2.0.0"
]
]
},
{
"name": "websocket-client",
"specs": [
[
"==",
"1.8.0"
]
]
}
],
"lcname": "coinbaseadvanced"
}