Documentation¶
client¶
Handles Clients in the Coinbase Exchange Library.
-
class
cbexchange.client.
APIClient
[source]¶ Base class of all client in the Coinbase Exchange Library.
-
class
cbexchange.client.
PaginationClient
(api_uri=None, before=True, limit=None, cursor=None)[source]¶ Handles Pagination https://docs.exchange.coinbase.com/#pagination
This client is iterable in the given direction (before parameter).
Parameters: -
is_after
()[source]¶ Returns True if the direction is set to after.
Returns: True if the direction is set to after, otherwise False Return type: bool
-
is_before
()[source]¶ Returns True if the direction is set to before.
Returns: True if the direction is set to before, otherwise False Return type: bool
-
next
()¶ Iterator function for Python 3.
Returns: the next message in the sequence Raises: StopIteration – if there are no more messages
-
error¶
Handles Errors in the Coinbase Exchange Library.
-
exception
cbexchange.error.
APIError
(response)[source]¶ Unless otherwise stated, errors to bad requests will respond with HTTP 4xx or status codes. The body will also contain a message parameter indicating the cause. Your language’s http library should be configured to provide message bodies for non-2xx requests so that you can read the message field from the body. Find more here: https://docs.exchange.coinbase.com/#errors
Parameters: response (requests.Response) – HTTP error response
-
exception
cbexchange.error.
CBExchangeError
[source]¶ All Coinbase Exchange Library related errors extend this class.
market¶
The Market Data API is an unauthenticated set of endpoints for retrieving market data. These endpoints provide snapshots of market data.
Find more here: https://docs.exchange.coinbase.com/#market-data
-
class
cbexchange.market.
GetTradesPagination
(product_id='BTC-USD', api_uri=None, before=True, limit=None, cursor=None)[source]¶
-
class
cbexchange.market.
MarketClient
(api_uri=None)[source]¶ -
-
get_historic_trades
(start, end, granularity, product_id='BTC-USD')[source]¶ https://docs.exchange.coinbase.com/#get-historic-rates
Parameters: - start – either datetime.datetime or str in ISO 8601
- end – either datetime.datetime or str in ISO 8601
Pram int granularity: desired timeslice in seconds
Returns: desired data
-
orderbook¶
The websocket feed provides real-time updates on orders and trades. These updates can be applied on to a level 2 or 3 order book snapshot to maintain an accurate and up-to-date copy of the exchange order book.
Find more here: https://docs.exchange.coinbase.com/#real-time-order-book
-
class
cbexchange.orderbook.
OrderBook
(ws_uri=None, api_uri=None, product_id=None)[source]¶ https://docs.exchange.coinbase.com/#real-time-order-book
Includes a real-time thread that makes sure the order book is up to date. Supports the ‘with’ statment.
The order book format will be:
>>> { >>> "asks": { >>> "da863862-25f4-4868-ac41-005d11ab0a5f": { >>> "price": "295.97", >>> "size": "5.72036512" >>> }, >>> ... >>> }, >>> "bids": { >>> "3b0f1225-7f84-490b-a29f-0faef9de823a": { >>> "price": "295.96", >>> "size": "0.05088265" >>> }, >>> ... >>> }, >>> "sequence": 3 >>> }
Parameters: -
API_URI
= 'https://api.exchange.coinbase.com'¶
-
PRODUCT_ID
= 'BTC-USD'¶
-
WS_URI
= 'wss://ws-feed.exchange.coinbase.com'¶
-
private¶
Private endpoints are available for order management, and account management. Every private request must be signed using the described authentication scheme.
Find more here: https://docs.exchange.coinbase.com/#private
-
class
cbexchange.private.
AccountPagination
(account_id, auth, api_uri=None, before=True, limit=None, cursor=None)[source]¶
-
class
cbexchange.private.
CancelAllPagination
(product_id, auth, api_uri=None, before=True, limit=None, cursor=None)[source]¶
-
class
cbexchange.private.
CoinbaseExchangeAuth
(api_key, secret_key, passphrase)[source]¶ https://docs.exchange.coinbase.com/#authentication
Parameters:
-
class
cbexchange.private.
GetAccountHistoryPagination
(account_id, auth, api_uri=None, before=True, limit=None, cursor=None)[source]¶
-
class
cbexchange.private.
GetHoldsPagination
(account_id, auth, api_uri=None, before=True, limit=None, cursor=None)[source]¶
-
class
cbexchange.private.
ListAccountsPagination
(auth, api_uri=None, before=True, limit=None, cursor=None)[source]¶
-
class
cbexchange.private.
ListFillsPagination
(auth, api_uri=None, before=True, limit=None, cursor=None)[source]¶
-
class
cbexchange.private.
ListOrdersPagination
(auth, status=None, api_uri=None, before=True, limit=None, cursor=None)[source]¶
-
class
cbexchange.private.
PrivateClient
(auth, api_uri=None)[source]¶ https://docs.exchange.coinbase.com/#authentication
Parameters: - auth (CoinbaseExchangeAuth) – authentication for the Private API
- api_uri (str) – Coinbase Exchange REST API URI
-
new_accounts_report
(start_date, end_date, account_id, product_id='BTC-USD', format=None, email=None)[source]¶
-
new_fills_report
(start_date, end_date, account_id=None, product_id='BTC-USD', format=None, email=None)[source]¶
-
place_limit_order
(side, price, size, product_id='BTC-USD', client_oid=None, stp=None, time_in_force=None, cancel_after=None, post_only=None)[source]¶
-
place_market_order
(side, product_id='BTC-USD', size=None, funds=None, client_oid=None, stp=None)[source]¶
websock¶
The WebSocket Feed provides real-time market data updates for orders and trades.
Find more here: https://docs.exchange.coinbase.com/#websocket-feed
-
class
cbexchange.websock.
WSClient
(ws_uri=None, ws_type=None, ws_product_id=None)[source]¶ API Client for Coinbase Exchange WebSocket Feed.
This class starts in a disconnected state so make sure to connect before attempting to receive any messages. When using the ‘with’ statement the client connects and disconnects automatically.
Once connected the client starts a thread which keeps the WebSocket alive using periodic pings. There will be only one keep alive thread per client instance. If the WebSocket connection is somehow lost, the keep alive thread will clean up and exit.
The client is iterable over the messages in the feed:
Example: >>> from cbexchange.websock import WSClient >>> client = WSClient() >>> client.connect() >>> for message in client: >>> print(message)
The client supports the ‘with’ statment:
Example: >>> from cbexchange.websock import WSClient >>> with WSClient() as client: >>> print(client.receive())
Parameters: - ws_uri (str) – WebSocket URI.
- ws_type (str) – https://docs.exchange.coinbase.com/#subscribe
- ws_product_id (str) –
-
WS_PRODUCT_ID
= 'BTC-USD'¶
-
WS_TYPE
= 'subscribe'¶
-
WS_URI
= 'wss://ws-feed.exchange.coinbase.com'¶
-
connected
()[source]¶ Checks if we are connected to the WebSocket Feed.
Returns: True if connected, otherwise False Return type: bool