coinbasepro-python

The unofficial Python client for the Coinbase Pro API


Keywords
coinbase
License
MIT
Install
pip install coinbasepro-python==0.0.5

Documentation

coinbasepro-python

The Python client for the Coinbase Pro API (formerly known as the GDAX Exchange API)

Provided under MIT License

Note: this library may be subtly broken or buggy. The code is released under the MIT License – please take the following message to heart:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Benefits

  • A simple to use python wrapper for both public and authenticated Coinbase Pro api.
  • In a few minutes you could be trading on one of the largest cryptocurrency exchanges in the world!
  • Easy to use methods for every API endpoint (including Buy/Sell)
  • Gain an advantage in the market by creating an automated trading algorithm.

Getting Started

This README is documentation on the syntax of the python client presented in this repository. See function docstrings for full syntax details.
This API attempts to present a clean interface to Coinbase Pro, but in order to use it to its full potential, you must familiarize yourself with the official Coinbase Pro documentation.

pip install coinbasepro-python
  • You may manually install the project:
git clone https://github.com/pearsonkyle/coinbasepro-python.git
cd coinbasepro-python
python setup.py install

Public Client

Only some endpoints in the API are available to everyone. The public endpoints can be reached using PublicClient

import coinbasepro
public_client = coinbasepro.PublicClient()

PublicClient Methods

public_client.get_products()
# Get the order book at the default level.
public_client.get_product_order_book('BTC-USD')
# Get the order book at a specific level.
public_client.get_product_order_book('BTC-USD', level=1)
# Get the product ticker for a specific product.
public_client.get_product_ticker(product_id='ETH-USD')
# Get the product trades for a specific product.
public_client.get_product_trades(product_id='ETH-USD')
public_client.get_product_historic_rates('ETH-USD')
# To include other parameters, see function docstring:
public_client.get_product_historic_rates('ETH-USD', granularity=3000)
public_client.get_product_24hr_stats('ETH-USD')
public_client.get_currencies()
public_client.get_time()

Authenticated Client

Not all API endpoints are available to everyone. Those requiring user authentication can be reached using AuthenticatedClient. You must setup API access within your account settings. The AuthenticatedClient inherits all methods from the PublicClient class, so you will only need to initialize one if you are planning to integrate both into your script.

import coinbasepro
auth_client = coinbasepro.AuthenticatedClient(key, b64secret, passphrase)

# Use the sandbox API (requires a different set of API access credentials)
auth_client = coinbasepro.AuthenticatedClient(key, b64secret, passphrase,
                    api_url="https://api-public.sandbox.pro.coinbase.com")

AuthenticatedClient Methods

auth_client.get_accounts()
auth_client.get_account("7d0f7d8e-dd34-4d9c-a846-06f431c381ba")
auth_client.get_account_history("7d0f7d8e-dd34-4d9c-a846-06f431c381ba")
auth_client.get_account_holds("7d0f7d8e-dd34-4d9c-a846-06f431c381ba")
# Buy 0.01 BTC @ 100 USD
auth_client.buy(price='100.00', #USD
               size='0.01', #BTC
               product_id='BTC-USD')
# Sell 0.01 BTC @ 200 USD
auth_client.sell(price='200.00', #USD
                size='0.01', #BTC
                product_id='BTC-USD')
auth_client.cancel_order("d50ec984-77a8-460a-b958-66f114b0de9b")
auth_client.cancel_all(product_id='BTC-USD')
auth_client.get_orders()
auth_client.get_order("d50ec984-77a8-460a-b958-66f114b0de9b")
auth_client.get_fills()
# Get fills for a specific order
auth_client.get_fills(order_id="d50ec984-77a8-460a-b958-66f114b0de9b")
# Get fills for a specific product
auth_client.get_fills(product_id="ETH-BTC")
depositParams = {
        'amount': '25.00', # Currency determined by account specified
        'coinbase_account_id': '60680c98bfe96c2601f27e9c'
}
auth_client.deposit(depositParams)
# Withdraw from CoinbasePro into Coinbase Wallet
withdrawParams = {
        'amount': '1.00', # Currency determined by account specified
        'coinbase_account_id': '536a541fa9393bb3c7000023'
}
auth_client.withdraw(withdrawParams)

Pagination

Some calls are paginated, meaning multiple calls must be made to receive the full set of data. Each page/request is a list of dict objects that are then appended to a master list, making it easy to navigate pages (e.g. request[0] would return the first page of data in the example below). This feature is under consideration for redesign. Please provide feedback if you have issues or suggestions

request = auth_client.get_fills(limit=100)
request[0] # Page 1 always present
request[1] # Page 2+ present only if the data exists

It should be noted that limit does not behave exactly as the official documentation specifies. If you request a limit and that limit is met, additional pages will not be returned. This is to ensure speedy response times when less data is preferred.

Under Development

  • Authenticated Client (Beta)
  • Websocket
  • Test Scripts
  • Real-time order book functionality
  • FIX API Client Looking for assistance