Skip to main content

[Deprecated] A Python interface for the Coinbase Pro/Coinbase Exchange API.

Project description

This project has been deprecated, as the Coinbase Pro API is now deprecated. Coinbase has replaced it with Coinbase Advanced Trading API.

https://img.shields.io/pypi/v/coinbasepro.svg https://img.shields.io/pypi/l/coinbasepro.svg https://img.shields.io/pypi/pyversions/coinbasepro.svg

Features

  • Full support of Coinbase Pro/Coinbase Exchange REST API

  • Rate-limiting - no more 429 error responses!

  • Pythonic abstractions for a clean interface
    • Return values are returned as Python data types instead of all string values:

    >>> import coinbasepro as cbp
    >>> client = cbp.PublicClient()
    # datetime and Decimal are among the return types in the dict returned
    # by this call:
    >>> client.get_product_ticker('BTC-USD')
    {'trade_id': 2845680,
    'price': Decimal('2496.69000000'),
    'size': Decimal('0.00100000'),
    'time': datetime.datetime(2019, 3, 20, 23, 53, 59, 596000),
    'bid': Decimal('2496.69'), 'ask': Decimal('2496.7'),
    'volume': Decimal('771.51495215')}
    • Paginated endpoints are abstracted as generators:

    >>> import itertools
    # get_product_trades is a generator
    >>> client.get_product_trades('BTC-USD')
    <generator object PublicClient.get_product_trades.<locals>.<genexpr> at 0x1098d6f68>
    
    # Get 2 most recent trades. For many trade requests (>100), multiple
    # HTTP requests will be made under the hood.
    >>> list(itertools.islice(client.get_product_trades('BTC-USD'), 2))
    [{'time': datetime.datetime(2019, 3, 21, 0, 2, 45, 609000),
    'trade_id': 2845779,
    'price': Decimal('2463.38000000'),
    'size': Decimal('0.00100000'),
    'side': 'buy'},
    {'time': datetime.datetime(2019, 3, 21, 0, 2, 39, 877000),
    'trade_id': 2845778,
    'price': Decimal('2463.39000000'),
    'size': Decimal('0.00100000'),
    'side': 'sell'}]
    • Warts in the Coinbase REST API are smoothed out:

    # CBPro API returns raw candles from this call as tuples, which would
    # require user to look up value meaning in API docs. This python API
    # returns candles as a list of dicts, similar to other API endpoints.
    
    # Get first candle:
    >>> client.get_product_historic_rates('BTC-USD')[0]
    {'time': datetime.datetime(2019, 3, 21, 0, 6),
    'low': Decimal('2463.3'),
    'high': Decimal('2463.31'),
    'open': Decimal('2463.3'),
    'close': Decimal('2463.31'),
    'volume': Decimal('0.006')}
    • Python API uses typing available in Python3:

    # Example function prototype in API
    def get_product_ticker(self, product_id: str) -> Dict[str, Any]:
  • Exceptions to enable easy handling of Coinbase error responses

>>> client.get_product_ticker(product_id='fake_product')
coinbasepro.exceptions.CoinbaseAPIError: NotFound
>>> auth_client = cbp.AuthenticatedClient(key='fake',
                                          secret='fake',
                                          passphrase='fake')
>>> auth_client.get_accounts()
coinbasepro.exceptions.BadRequest: Invalid API Key
# Authenticated client using API key which doesn't have withdrawal
# privileges:
>>> auth_client.withdraw_to_coinbase(0.01, 'BTC', 'fake_acct_id')
coinbasepro.exceptions.InvalidAuthorization: Forbidden
# This call throws a BadRequest exception
>>> auth_client.get_order('invalid_order_num')
coinbasepro.exceptions.BadRequest: Invalid order id

# CoinbaseAPIError is the parent exception for all exceptions the API
# throws, so catching this will catch anything
>>> try:
>>>     auth_client.get_order('invalid_order_num')
>>> except cbp.exceptions.CoinbaseAPIError as e:
>>>     print('Caught error: {}'.format(e))
Caught error: Invalid order id

Installation

$ pip install coinbasepro

Development

Environment Setup

  1. Create virtual environment using preferred tool

  2. Bootstrap pip-tools by installing dev requirements directly:

$ pip install -r requirements.txt

Once pip-tools is installed in your environment, you can update requirements by:

$ make install-requirements

3. (Optional) Install pre-commit git hooks. This will run pre-commit with every commit, which should fix any lint issues before you push changes to your remote branch.

Release History

dev

  • [change here]

0.4.1 (2023-02-18)

Bugfixes

  • Fix python_requires in setup.py so this package can be installed by poetry.

  • get_signed_prices should be an authenticated endpoint.

0.4.0 (2022-07-28)

Improvements

  • Add get_account_transfers method.

  • Add get_all_transfers method.

  • Add get_transfer method.

  • Add get_address_book method.

  • Add generate_crypto_address method.

  • Add get_crypto_withdrawal_fee_estimate method.

  • Add get_fees method.

  • Update get_products to reflect that min_market_funds now represents minimum order size. Added more type-conversions to numerical fields.

  • Add get_product method.

  • Add get_signed_prices method.

0.3.2 (2022-07-28)

Bugfixes

  • Fix url in withdraw_to_coinbase method.

0.3.1 (2022-04-15)

Bugfixes

  • Fix ratelimiting in get_coinbase_accounts method.

0.3.0 (2021-03-13)

Improvements

  • Add trade_id param to get_trades. Allows you to get trades starting from an arbitrary trade, instead of only the most recent trade.

0.2.1 (2020-01-09)

Bugfixes

  • Fix volume parsing error in get_fills.

0.2.0 (2019-11-10)

Improvements

  • Added rate-limiting to all public and authenticated endpoints. Dropping support for Python 3.4 to keep the implementation simple.

0.1.1 (2019-07-23)

Bugfixes

  • Parameters used for historic rates (start/end) were not being sent in query parameters (thanks imalovitsa-exos!).

0.1.0 (2019-03-20)

Improvements

  • Return values are now Pythonic types (i.e Decimal, datetime) instead of all string types.

  • Python3 typing now used to help with development using this API.

  • Docstring improvements and changes to match updated interface.

  • A bit more documentation in the readme.

Bugfixes

  • Update requests version to >=2.20.0 to address security vulnerability.

0.0.7 (2018-09-09)

Bugfixes

  • Fix parameter name for get_product_historic_rates.

0.0.6 (2018-08-23)

Improvements

  • Update parameter validation for get_fills to reflect Coinbase API change.

Bugfixes

  • Fixed bug where parameters had no effect in get_product_historic_rates.

  • Fixed bug where product_id parameter had no effect in cancel_all.

0.0.5 (2018-08-21)

Improvements

  • Add exceptions for Coinbase error responses.

0.0.4 (2018-07-15)

Improvements

  • Updated stop orders to latest API.

Bugfixes

  • Fix issue with time in force error checking.

0.0.3 (2018-07-07)

Improvements

  • Rename deposit and withdraw methods to clarify action.

Bugfixes

  • Removed margin endpoints - now unsupported.

0.0.2 (2018-07-01)

Improvements

  • Client request timeout is now configurable.

0.0.1 (2018-06-27)

  • Hello world.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coinbasepro-0.4.2.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coinbasepro-0.4.2-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file coinbasepro-0.4.2.tar.gz.

File metadata

  • Download URL: coinbasepro-0.4.2.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.3

File hashes

Hashes for coinbasepro-0.4.2.tar.gz
Algorithm Hash digest
SHA256 bd9ec844ca987d57050278faa90e09082b88965fcfa6d81a7ee51989f1d4464e
MD5 f0db6546b10329511918ece4d06b54fd
BLAKE2b-256 be67b1cbd39c649ea076652c5af0bdbeb3d2eff90730e09421c1f28e9091efe9

See more details on using hashes here.

File details

Details for the file coinbasepro-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: coinbasepro-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.3

File hashes

Hashes for coinbasepro-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2f957d70b1fff07d683a720e45173efa3a9705dd76b5bd3edb794f04910ee202
MD5 926d56fffd967e8d489d0b19560a5096
BLAKE2b-256 6fa61b3040794cfa2a197887ed80fe0062ea0e3efaa467c5567f7eb1dcf1e310

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page