一个简单的coinswitch(v1,v2)客户端api
coinswitchclient的Python项目详细描述
用于coinswitch的简单python库
这是一个使用coinswitchapi的简单库。 它只是一组实用程序,用于操作、解释和简化对其api的调用
如何使用
首先使用pip安装软件包
pip install coinswitchclient
那么一定要有你的api密钥。如果不是,则默认为沙盒api密钥 此软件包中有两个主要模块:
TransactionManager
:它是一组调用v2即时api的函数CoinSwitchV1Client
:反映v1 coinswitch api的函数CoinSwitchV2FixedClient
:反映v2固定coinswitch api的函数CoinSwitchV2InstantClient
:反映v2即时coinswitch api的函数ApiResponse
:表示来自coinswitch api的响应的对象
您可以在这个repo的test
目录中找到示例。
使用APIResponse
您不必指定这个对象,但它将由每个api调用返回。 下面是APIResponse的全局结构
{"success":true,"code":"","data":"","error":""}
APIResponse对象提供了访问基本信息的简单方法
api_response.is_success()# returns a booleanapi_response.code()# return the code string in the "code" fieldapi_response.message()# returns the content of error or msg depending on the remote responseapi_response.data()# return a dict object that represent the data
有关数据消息中返回字段的任何信息,请参见https://developer.coinswitch.co/。
TransactionManager的用法
# import required modules and classesfromcoinswitch_client.TransactionManagerimportTransactionManagerfromcoinswitch_client.APIClientimportAddress# create an instance of the transaction managermanager=TransactionManager(api_key="MY_API_KEY")# Ask to convert 1 BTC to ETH with manager.convert('btc','eth',1.0,Address('ETH_ADDRESS').json(),Address('REFUND_ADDRESS').json())#this function returns the response from the coinswitch api as a ApiResponse
coinswitchv1客户端的用法
它遵循https://developer.coinswitch.co/api 下面是一个简单的用法
fromcoinswitch_client.APIClientimportCoinSwitchV1Clientclient=CoinSwitchV1Client(api_key="MYKEY")api_response=client.coins()ifapi_response.is_success():print(api_response.data())
coinswitchv2instantclient的用法
它遵循https://developer.coinswitch.co/api 下面是一个简单的用法
fromcoinswitch_client.APIClientimportCoinSwitchV2InstantClientclient=CoinSwitchV2InstantClient(api_key="MYKEY")api_response=client.coins()ifapi_response.is_success():print(api_response.data())api_response=client.rates('btc','eth')ifapi_response.is_success():print(api_response.data())
coinswitchv2fixedclient的用法
它遵循https://developer.coinswitch.co/api 下面是一个简单的用法
fromcoinswitch_client.APIClientimportCoinSwitchV2FixedClientclient=CoinSwitchV2FixedClient(api_key="MYKEY")api_response=client.coins()ifapi_response.is_success():print(api_response.data())api_response=client.place_offer('btc','eth',quantity_from=1.0)ifapi_response.is_success():print(api_response.data())