Skip to main content

Coinbase Advanced

Python library for the Coinbase Advanced Trade API.

Features

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.

Metadata

Release files for coinbaseadvanced 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for coinbaseadvanced 1.2.0
File Interpreter ABI Platform
coinbaseadvanced-1.2.0-py3-none-any.whl Python 3 none any Details

Release files / coinbaseadvanced-1.2.0-py3-none-any.whl

Download URL coinbaseadvanced-1.2.0-py3-none-any.whl
Size 31.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
058f6fee7360fee15e7fab06f32ac15f2c0abf148f2b696711cc46a13f9235c2
BLAKE2b-256 checksum
How to use checksums
686202a96c1b6665282c54195d116cc08abf263132819db95cb69042c9b020cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.19

Release history Release notifications | RSS feed

This release

1.2.0 This release

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.3.0

1 release file

0.2.0

2 release files

0.1.1

3 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page