Package: coinbasepro
FeaturesFull support of Coinbase Pro/Coinbase Exchange REST APIRate-limiting - no more 429 error responses!Pythonic abstractions for a clean interfaceReturn values are returned as Python data types instead of all string values:>>>importcoinbaseproascbp>>>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:>>>importitertools# get_product_trades is a generator>>>client.get_product_trades('BTC-USD')<generatorobjectPublicClient.get_product_trades.<locals>.<genexpr>at0x1098d6f68># 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 APIdefget_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:InvalidAPIKey# 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:Invalidorderid# 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')>>>exceptcbp.exceptions.CoinbaseAPIErrorase:>>>print('Caught error:{}'.format(e))Caughterror:InvalidorderidInstallation$pipinstallcoinbaseproDevelopmentEnvironment SetupCreate virtual environment using preferred toolBootstrappip-toolsby installing dev requirements directly:$pipinstall-rrequirements.txtOncepip-toolsis installed in your environment, you can update requirements by:$makeinstall-requirements3. (Optional) Installpre-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 Historydev[change here]0.4.1 (2023-02-18)BugfixesFixpython_requiresin setup.py so this package can be installed by poetry.get_signed_pricesshould be an authenticated endpoint.0.4.0 (2022-07-28)ImprovementsAddget_account_transfersmethod.Addget_all_transfersmethod.Addget_transfermethod.Addget_address_bookmethod.Addgenerate_crypto_addressmethod.Addget_crypto_withdrawal_fee_estimatemethod.Addget_feesmethod.Updateget_productsto reflect thatmin_market_fundsnow represents minimum order size. Added more type-conversions to numerical fields.Addget_productmethod.Addget_signed_pricesmethod.0.3.2 (2022-07-28)BugfixesFix url inwithdraw_to_coinbasemethod.0.3.1 (2022-04-15)BugfixesFix ratelimiting inget_coinbase_accountsmethod.0.3.0 (2021-03-13)ImprovementsAddtrade_idparam toget_trades. Allows you to get trades starting from an arbitrary trade, instead of only the most recent trade.0.2.1 (2020-01-09)BugfixesFix volume parsing error inget_fills.0.2.0 (2019-11-10)ImprovementsAdded 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)BugfixesParameters used for historic rates (start/end) were not being sent in query parameters (thanks imalovitsa-exos!).0.1.0 (2019-03-20)ImprovementsReturn 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.BugfixesUpdate requests version to >=2.20.0 to address security vulnerability.0.0.7 (2018-09-09)BugfixesFix parameter name forget_product_historic_rates.0.0.6 (2018-08-23)ImprovementsUpdate parameter validation forget_fillsto reflect Coinbase API change.BugfixesFixed bug where parameters had no effect inget_product_historic_rates.Fixed bug whereproduct_idparameter had no effect incancel_all.0.0.5 (2018-08-21)ImprovementsAdd exceptions for Coinbase error responses.0.0.4 (2018-07-15)ImprovementsUpdated stop orders to latest API.BugfixesFix issue with time in force error checking.0.0.3 (2018-07-07)ImprovementsRename deposit and withdraw methods to clarify action.BugfixesRemoved margin endpoints - now unsupported.0.0.2 (2018-07-01)ImprovementsClient request timeout is now configurable.0.0.1 (2018-06-27)Hello world.