Websocket API Client
WSClient Constructor
- class coinbase.websocket.WSClient(api_key: str | None = None, api_secret: str | None = None, key_file: IO | str | None = None, base_url='wss://advanced-trade-ws.coinbase.com', timeout: int | None = None, max_size: int | None = 10485760, on_message: Callable[[str], None] | None = None, on_open: Callable[[], None] | None = None, on_close: Callable[[], None] | None = None, retry: bool | None = True, verbose: bool | None = False)[source]
WSClient
Initialize using WSClient
Parameters:
api_key | Optional (str) - The API key
api_secret | Optional (str) - The API key secret
key_file | Optional (IO | str) - Path to API key file or file-like object
base_url | (str) - The websocket base url. Default set to “wss://advanced-trade-ws.coinbase.com”
timeout | Optional (int) - Set timeout in seconds for REST requests
max_size | Optional (int) - Max size in bytes for messages received. Default set to (10 * 1024 * 1024)
on_message | Optional (Callable[[str], None]) - Function called when a message is received
on_open | Optional ([Callable[[], None]]) - Function called when a connection is opened
on_close | Optional ([Callable[[], None]]) - Function called when a connection is closed
retry | Optional (bool) - Enables automatic reconnections. Default set to True
verbose | Optional (bool) - Enables debug logging. Default set to False
WebSocket Utils
- async coinbase.websocket.WSClient.open_async(self) None
Open Websocket Async
Open the websocket client connection asynchronously.
- coinbase.websocket.WSClient.close(self) None
Close Websocket
Close the websocket client connection.
- async coinbase.websocket.WSClient.close_async(self) None
Close Websocket Async
Close the websocket client connection asynchronously.
- coinbase.websocket.WSClient.subscribe(self, product_ids: List[str], channels: List[str]) None
Subscribe
Subscribe to a list of channels for a list of product ids.
product_ids - product ids to subscribe to
channels - channels to subscribe to
- async coinbase.websocket.WSClient.subscribe_async(self, product_ids: List[str], channels: List[str]) None
Subscribe Async
Async subscribe to a list of channels for a list of product ids.
product_ids - product ids to subscribe to
channels - channels to subscribe to
- coinbase.websocket.WSClient.unsubscribe(self, product_ids: List[str], channels: List[str]) None
Unsubscribe
Unsubscribe to a list of channels for a list of product ids.
product_ids - product ids to unsubscribe from
channels - channels to unsubscribe from
- async coinbase.websocket.WSClient.unsubscribe_async(self, product_ids: List[str], channels: List[str]) None
Unsubscribe Async
Async unsubscribe to a list of channels for a list of product ids.
product_ids - product ids to unsubscribe from
channels - channels to unsubscribe from
- coinbase.websocket.WSClient.unsubscribe_all(self) None
Unsubscribe All
Unsubscribe from all channels you are currently subscribed to.
- async coinbase.websocket.WSClient.unsubscribe_all_async(self) None
Unsubscribe All Async
Async unsubscribe from all channels you are currently subscribed to.
- coinbase.websocket.WSClient.sleep_with_exception_check(self, sleep: int) None
Sleep with Exception Check
Sleep for a specified number of seconds and check for background exceptions.
sleep - number of seconds to sleep.
- async coinbase.websocket.WSClient.sleep_with_exception_check_async(self, sleep: int) None
Sleep with Exception Check Async
Async sleep for a specified number of seconds and check for background exceptions.
sleep - number of seconds to sleep.
- coinbase.websocket.WSClient.run_forever_with_exception_check(self) None
Run Forever with Exception Check
Runs an endless loop, checking for background exceptions every second.
Channels
- coinbase.websocket.WSClient.heartbeats(self) None
Heartbeats Subscribe
Description:
Subscribe to heartbeats channel.
Read more on the official documentation: Heartbeats Channel
- async coinbase.websocket.WSClient.heartbeats_async(self) None
Heartbeats Subscribe Async
Description:
Async subscribe to heartbeats channel.
Read more on the official documentation: Heartbeats Channel
- coinbase.websocket.WSClient.heartbeats_unsubscribe(self) None
Heartbeats Unsubscribe
Description:
Unsubscribe to heartbeats channel.
Read more on the official documentation: Heartbeats Channel
- async coinbase.websocket.WSClient.heartbeats_unsubscribe_async(self) None
Heartbeats Unsubscribe Async
Description:
Async unsubscribe to heartbeats channel.
Read more on the official documentation: Heartbeats Channel
- coinbase.websocket.WSClient.candles(self, product_ids: List[str]) None
Candles Subscribe
Description:
Subscribe to candles channel for a list of products_ids.
Read more on the official documentation: Candles Channel
- async coinbase.websocket.WSClient.candles_async(self, product_ids: List[str]) None
Candles Subscribe Async
Description:
Async subscribe to candles channel for a list of products_ids.
Read more on the official documentation: Candles Channel
- coinbase.websocket.WSClient.candles_unsubscribe(self, product_ids: List[str]) None
Candles Unsubscribe
Description:
Unsubscribe to candles channel for a list of products_ids.
Read more on the official documentation: Candles Channel
- async coinbase.websocket.WSClient.candles_unsubscribe_async(self, product_ids: List[str]) None
Candles Unsubscribe Async
Description:
Async unsubscribe to candles channel for a list of products_ids.
Read more on the official documentation: Candles Channel
- coinbase.websocket.WSClient.market_trades(self, product_ids: List[str]) None
Market Trades Subscribe
Description:
Subscribe to market_trades channel for a list of products_ids.
Read more on the official documentation: Market Trades Channel
- async coinbase.websocket.WSClient.market_trades_async(self, product_ids: List[str]) None
Market Trades Subscribe Async
Description:
Async subscribe to market_trades channel for a list of products_ids.
Read more on the official documentation: Market Trades Channel
- coinbase.websocket.WSClient.market_trades_unsubscribe(self, product_ids: List[str]) None
Market Trades Unsubscribe
Description:
Unsubscribe to market_trades channel for a list of products_ids.
Read more on the official documentation: Market Trades Channel
- async coinbase.websocket.WSClient.market_trades_unsubscribe_async(self, product_ids: List[str]) None
Market Trades Unsubscribe Async
Description:
Async unsubscribe to market_trades channel for a list of products_ids.
Read more on the official documentation: Market Trades Channel
- coinbase.websocket.WSClient.status(self, product_ids: List[str]) None
Status Subscribe
Description:
Subscribe to status channel for a list of products_ids.
Read more on the official documentation: Status Channel
- async coinbase.websocket.WSClient.status_async(self, product_ids: List[str]) None
Status Subscribe Async
Description:
Async subscribe to status channel for a list of products_ids.
Read more on the official documentation: Status Channel
- coinbase.websocket.WSClient.status_unsubscribe(self, product_ids: List[str]) None
Status Unsubscribe
Description:
Unsubscribe to status channel for a list of products_ids.
Read more on the official documentation: Status Channel
- async coinbase.websocket.WSClient.status_unsubscribe_async(self, product_ids: List[str]) None
Status Unsubscribe Async
Description:
Async unsubscribe to status channel for a list of products_ids.
Read more on the official documentation: Status Channel
- coinbase.websocket.WSClient.ticker(self, product_ids: List[str]) None
Ticker Subscribe
Description:
Subscribe to ticker channel for a list of products_ids.
Read more on the official documentation: Ticker Channel
- async coinbase.websocket.WSClient.ticker_async(self, product_ids: List[str]) None
Ticker Subscribe Async
Description:
Async subscribe to ticker channel for a list of products_ids.
Read more on the official documentation: Ticker Channel
- coinbase.websocket.WSClient.ticker_unsubscribe(self, product_ids: List[str]) None
Ticker Unsubscribe
Description:
Unsubscribe to ticker channel for a list of products_ids.
Read more on the official documentation: Ticker Channel
- async coinbase.websocket.WSClient.ticker_unsubscribe_async(self, product_ids: List[str]) None
Ticker Unsubscribe Async
Description:
Async unsubscribe to ticker channel for a list of products_ids.
Read more on the official documentation: Ticker Channel
- coinbase.websocket.WSClient.ticker_batch(self, product_ids: List[str]) None
Ticker Batch Subscribe
Description:
Subscribe to ticker_batch channel for a list of products_ids.
Read more on the official documentation: Ticker Batch Channel
- async coinbase.websocket.WSClient.ticker_batch_async(self, product_ids: List[str]) None
Ticker Batch Subscribe Async
Description:
Async subscribe to ticker_batch channel for a list of products_ids.
Read more on the official documentation: Ticker Batch Channel
- coinbase.websocket.WSClient.ticker_batch_unsubscribe(self, product_ids: List[str]) None
Ticker Batch Unsubscribe
Description:
Unsubscribe to ticker_batch channel for a list of products_ids.
Read more on the official documentation: Ticker Batch Channel
- async coinbase.websocket.WSClient.ticker_batch_unsubscribe_async(self, product_ids: List[str]) None
Ticker Batch Unsubscribe Async
Description:
Async unsubscribe to ticker_batch channel for a list of products_ids.
Read more on the official documentation: Ticker Batch Channel
- coinbase.websocket.WSClient.level2(self, product_ids: List[str]) None
Level2 Subscribe
Description:
Subscribe to level2 channel for a list of products_ids.
Read more on the official documentation: Level2 Channel
- async coinbase.websocket.WSClient.level2_async(self, product_ids: List[str]) None
Level2 Subscribe Async
Description:
Async subscribe to level2 channel for a list of products_ids.
Read more on the official documentation: Level2 Channel
- coinbase.websocket.WSClient.level2_unsubscribe(self, product_ids: List[str]) None
Level2 Unsubscribe
Description:
Unsubscribe to level2 channel for a list of products_ids.
Read more on the official documentation: Level2 Channel
- async coinbase.websocket.WSClient.level2_unsubscribe_async(self, product_ids: List[str]) None
Level2 Unsubscribe Async
Description:
Async unsubscribe to level2 channel for a list of products_ids.
Read more on the official documentation: Level2 Channel
- coinbase.websocket.WSClient.user(self, product_ids: List[str]) None
User Subscribe
Description:
Subscribe to user channel for a list of products_ids.
Read more on the official documentation: User Channel
- async coinbase.websocket.WSClient.user_async(self, product_ids: List[str]) None
User Subscribe Async
Description:
Async subscribe to user channel for a list of products_ids.
Read more on the official documentation: User Channel
- coinbase.websocket.WSClient.user_unsubscribe(self, product_ids: List[str]) None
User Unsubscribe
Description:
Unsubscribe to user channel for a list of products_ids.
Read more on the official documentation: User Channel
- async coinbase.websocket.WSClient.user_unsubscribe_async(self, product_ids: List[str]) None
User Unsubscribe Async
Description:
Async unsubscribe to user channel for a list of products_ids.
Read more on the official documentation: User Channel
- coinbase.websocket.WSClient.futures_balance_summary(self) None
Futures Balance Summary Subscribe
Description:
Subscribe to futures_balance_summary channel.
Read more on the official documentation: Futures Balance Summary Channel
- async coinbase.websocket.WSClient.futures_balance_summary_async(self) None
Futures Balance Summary Subscribe Async
Description:
Async subscribe to futures_balance_summary channel.
Read more on the official documentation: Futures Balance Summary Channel
- coinbase.websocket.WSClient.futures_balance_summary_unsubscribe(self) None
Futures Balance Summary Unsubscribe
Description:
Unsubscribe to futures_balance_summary channel.
Read more on the official documentation: Futures Balance Summary Channel
- async coinbase.websocket.WSClient.futures_balance_summary_unsubscribe_async(self) None
Futures Balance Summary Unsubscribe Async
Description:
Async unsubscribe to futures_balance_summary channel.
Read more on the official documentation: Futures Balance Summary Channel