CoinBase Commerce API客户端库

coinbase-commerce的Python项目详细描述


CircleCI

Coinbase CommercePython

Coinbase CommercePython

目录

python版本

python 2.7+和3.4+是受支持和测试的。

第三方库和依赖项

安装客户端库时将安装以下库:

文档

有关详细信息,请访问Coinbase API docs

要开始使用库,您需要在Commerce SignUp上注册。 从用户设置中获取API_KEY

接下来创建一个Client对象,用于与api进行交互:

fromcoinbase_commerce.clientimportClientAPI_KEY="API KEY"client=Client(api_key=API_KEY)

Client包含指向api资源的每个python类表示的链接 Checkout, Charge, Event

您可以从api资源类调用list, list_paging_iter, create, retrieve, modify方法

client.charge.createclient.checkout.list_paging_iterclient.event.listclient.charge.retrieveclient.checkout.modify

以及来自api资源类实例的save, delete, refresh方法。

checkout=client.checkout.retrieve(<id>)checkout.refresh()checkout.save()checkout.delete()

每个api方法返回一个表示api的json响应的APIObject(一个dict的子类),所有模型都可以用json转储。
另外,当响应数据被解析为python对象时,将自动使用适当的APIObject子类。 APIResource类的所有子类都支持refresh方法。这将通过向相关api端点发出新的GET请求来更新它们的属性和所有嵌套数据。

客户端支持常见的API错误和警告处理。 与api交互期间发生的所有错误都将作为异常引发。

ErrorStatus Code
APIError*
InvalidRequestError400
ParamRequiredError400
ValidationError400
AuthenticationError401
ResourceNotFoundError404
RateLimitExceededError429
InternalServerError500
ServiceUnavailableError503

安装

安装时使用pip

pip install --upgrade coinbase-commerce

或者用easy_install

easy_install --upgrade coinbase-commerce

用法

fromcoinbase_commerce.clientimportClientclient=Client(api_key=API_KEY)

退房

Checkouts API docs

检索

checkout=client.checkout.retrieve(<checkout_id>)

创建

checkout_info={"name":'The Sovereign Individual',"description":'Mastering the Transition to the Information Age',"pricing_type":'fixed_price',"local_price":{"amount":"100.00","currency":"USD"},"requested_info":["name","email"]}checkout=client.checkout.create(**checkout_info)# orcheckout=client.checkout.create(name='The Sovereign Individual',description='Mastering the Transition to the Information Age',pricing_type='fixed_price',local_price={"amount":"100.00","currency":"USD"},requested_info=["name","email"])

更新

checkout=client.checkout.retrieve(<checkout_id>)checkout.name='new name'checkout.save()# orcheckout=client.checkout.modify('<checkout_id>',name='new name')

删除

checkout.delete()

列表

checkouts=client.checkout.list()

分页列表迭代

forcheckoutinclient.checkout.list_paging_iter():print("{!r}".format(checkout))

费用

Charges API docs

检索

charge=client.charge.retrieve(<charge_id>)

创建

charge_info={"name":"The Sovereign Individual","description":"Mastering the Transition to the Information Age","local_price":{"amount":"100.00","currency":"USD"},"pricing_type":"fixed_price"}charge=client.charge.create(**charge_info)# orcharge=client.charge.create(name='The Sovereign Individual',description='Mastering the Transition to the Information Age',pricing_type='fixed_price',local_price={"amount":"100.00","currency":"USD"})

列表

checkouts=client.charge.list()

分页列表迭代

forchargeinclient.charge.list_paging_iter():print("{!r}".format(charge))

事件

Events API Docs

检索

event=client.event.retrieve(<event_id>)

列表

events=client.event.list()

分页列表迭代

foreventinclient.event.list_paging_iter():print("{!r}".format(event))

正在验证Webhook签名

您可以使用我们的库来验证webhook签名。 要执行验证,您需要提供事件数据、来自请求头的webhook签名和端点的机密。 如果请求签名或请求负载无效,您将收到相应的错误消息。

WEBHOOK_SECRET='your_webhook_secret'# using Flask@app.route('/webhooks',methods=['POST'])defwebhooks():# event payloadrequest_data=request.data.decode('utf-8')# webhook signaturerequest_sig=request.headers.get('X-CC-Webhook-Signature',None)try:# signature verification and event object constructionevent=Webhook.construct_event(request_data,request_sig,WEBHOOK_SECRET)except(WebhookInvalidPayload,SignatureVerificationError)ase:returnstr(e),400print("Received event: id={id}, type={type}".format(id=event.id,type=event.type))return'success',200

测试和贡献

欢迎任何和所有的贡献!这个过程很简单:派生这个repo,进行更改,运行测试套件,并提交一个pull请求。测试通过nosetest运行。要运行测试,请克隆存储库,然后:

安装要求
pip install -r requirements.txt

为当前版本的python运行测试

使用tox对多个版本的python运行测试套件。您可以使用pip或easy_安装tox:

pip install tox
easy_install tox

tox需要合适的python解释器在不同的环境中运行测试。我们建议对此使用pyenv。一旦安装了适当的解释器,在每个环境中运行测试就很简单:

tox

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java这算是人工智能吗?   java@OnDelete(级联)不处理双向映射(hibernate)   java我怎样才能在基元类型(int)上修复这个等式   java如何初始化PrintWriter数组?   arraylist如何使用java添加敌人   java如何处理2019年的背景地理围栏?   java是否有一个XPath表达式可用于在CDATA区域中导航XML?   Kotlin(Android Studio)中的java选项卡式活动   安卓 java。lang.IllegalArgumentException:provider=网络   广播控制流和主流的java排序   java Apache Nifi无法启动Nifi实例   java我正在尝试将内容作为字符串放入ListView   java阻止mozilla会话还原   java在春季选择引用哪个bean?