CoinBase Pro API的Python接口。
coinbasepro的Python项目详细描述
功能
完全支持CoinBase Pro Rest API
- 干净界面的pythonic抽象
- 返回值作为python数据类型而不是所有字符串值返回:
>>>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')}
- 分页端点被抽象为生成器:
>>>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'}]
- coinbase rest api中的疣被消除:
# 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使用python3中提供的类型:
# Example function prototype in APIdefget_product_ticker(self,product_id:str)->Dict[str,Any]:
允许轻松处理CoinBase错误响应的异常
>>>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:Invalidorderid
安装
$ pip install coinbasepro
发布历史记录
偏差
- [非琐碎变化的简短描述。]
0.1.1(2019-07-23)
错误修复
- 查询参数中未发送用于历史费率(开始/结束)的参数(感谢imalovitsa exos!).
0.1.0(2019-03-20)
改进
- 返回值现在是pythonic类型(即decimal、datetime),而不是所有字符串类型。
- python3类型现在用于帮助使用此api进行开发。
- docstring改进和更改以匹配更新的接口。
- 在自述文件中有更多的文档。
错误修复
- 将请求版本更新为>;=2.20.0以解决安全漏洞。
0.0.7(2018-09-09)
错误修复
- 修正获取产品历史价格的参数名。
0.0.6(2018-08-23)
改进
- 更新get_fills的参数验证以反映CoinBase API更改。
错误修复
- 修正了参数对“获取产品”的历史价格没有影响的错误。
- 修正了product\u id参数对cancel\u all没有影响的错误。
0.0.5(2018-08-21)
改进
- 为CoinBase错误响应添加异常。
0.0.4(2018-07-15)
改进
- 根据最新的API更新了停止令。
错误修复
- 修正时间生效错误检查的问题。
0.0.3(2018-07-07)
改进
- 重新命名存取款方法以澄清操作。
错误修复
- 已删除边距终结点-现在不支持。
0.0.2(2018-07-01)
改进
- 客户端请求超时现在是可配置的。
0.0.1(2018-06-27)
- 你好,世界。