Skip to content
James Atchue edited this page Nov 9, 2017 · 1 revision

pyCoinPayments - Unofficial Python API client for CoinPayments

This is an unofficial client for CoinPayments, a website that exposes an API which allows you to accept over 75 cryptocurrencies. The documentation was a little strange at times so I made this to simplify and help others overcome some of the initial hurdles of trying to use their API. There's some interesting functionality I added to this so you never have to deal directly with the returned json. A c#.net version is coming soon with javascript soon after.

The Absolute Basics

A basic API call to CoinPayments is outline in the following steps, the example is following the API call create_transaction:

  1. Generate parameters: Parameters are url encoded. Within the parameters is a cmd field which corresponds to the API route you're sending the request. In this case it'd look like this {'cmd':'create_transaction'}

Their official API endpoint is https://www.coinpayments.net/api.php all calls are made against the same URL. Normally (without this client) you'd need to pass a 'cmd' parameter like below to the endpoint to distinguish between the API calls. This client simplifies things so calling each API method automatically does this for you.

{'cmd':'get_basic_info'} is how you would call the 'Get Basic Account Information' API, this is handled automatically by the methods in this API so calling CryptoPayments().getBasicInfo() does this for you.

Basic Usage

To show you a basic using of the program I'm going to be calling the create_transaction method on the CoinPaymentsAPI

#import the module
from CryptoPayments import CryptoPayments

#Set Keys
API_KEY     = 'You Public API Key'
API_SECRET  = 'You API Secret'
IPN_URL = 'Your Callback URL'

## Parameters for your call, these are defined in the CoinPayments API Docs
## https://www.coinpayments.net/apidoc
post_params = {
    'amount' : 10,
    'currency1' : 'USD',
    'currency2' : 'LTCT'
}

#create a client to send requests to
client = CryptoPayments(API_KEY, API_SECRET, IPN_URL)

#call createTransaction on the client
transaction = client.createTransaction(post_params)


#Prints out transaction details
print transaction
print transaction.amount
print transaction.address

You can reference any of their return fields within the json as a field on the variable. For example the transaction.amount would print out the amount of requested cryptocurrency, same with the address. Their documentation outlines what it returned for fields in each request. The rest of the API client is very similar. Parameters are passed into the API method using a python dictionary, order in this case does not matter because the HMAC and encoded URL are generated at the same time.ncoded URL are generated at the same time.

Clone this wiki locally