You now have access to all documented API endpoints once you have your API keys ready. All endpoints require authentication, and for the purposes of this example, we are going to use HMAC authentication to transfer funds to an email address.

1. Setting up HMAC

HMAC is an authentication method that uses your own account to sign your requests. For the purposes of this tutorial, we'll use the following code snippet to sign our requests:

"""
hmac_example.py

Sign a request using an API_KEY and an API_SECRET.
"""
import hashlib
import hmac
import time
import json

API_KEY = 'YOUR_API_KEY'  # Replace this with your API Key
API_SECRET = 'YOUR_API_SECRET'  # Replace this with your API secret


def get_nonce():
    """Return a nonce based on the current time.
  
    A nonce should only use once and should always be increasing.
    Using the current time is perfect for this.
    """
    # Get the current unix epoch time, and convert it to milliseconds
      return int(time.time() * 1e6)

  
def sign_request(url, nonce, body=None):
    """Return an HMAC signature based on the request."""
    if body is None:
        # GET requests don't have a body, so we'll skip that for signing
        message = str(nonce) + url
    else:
        body = json.dumps(body, separators=(',', ':'))
        message = str(nonce) + url + body
        
    return str(
        hmac.new(
            str(API_SECRET),
            message,
            hashlib.sha256
        ).hexdigest()
    )

2. Your wallet account

A transfer requires a payload that should specify the account where the funds should come from, the amount to be sent, and the recipient. The first thing we should do is to retrieve our wallet account details:

import requests
import hmac_example

url = 'https://api.coins.asia/v3/crypto-accounts/'
nonce = hmac_example.get_nonce()
signature = hmac_example.sign_request(url, nonce)

headers = {
    'ACCESS_SIGNATURE': signature,
    'ACCESS_KEY': hmac_example.API_KEY,
    'ACCESS_NONCE': nonce,
    'Content-Type': 'application/json',
    'Accept': 'application/json'
}

requests.get(url, headers=headers)

This request would return a response that looks like the one below. What we should take note of is the id, which we would use for the next request. An id for an account would never change, which means you could use it for subsequent requests.

{
   "crypto-accounts":[
      {
         "id":"2r45ab4",
         "name":"Default Account",
         "currency":"BTC",
         "balance":"1.5",
         "pending_balance":"0.00000000",
         "default_address":"1a2a3c4b"
      }
   ]
}

3. Initiating the transfer

Now that we know the id of our BTC account, we can now initiate a transfer to [email protected]. For this example, we would like to give [email protected] 0.5 BTC:

import json
import requests
import hmac_example

url = 'https://api.coins.asia/v3/transfers/'
nonce = hmac_example.get_nonce()
body = {
    'amount': 0.5,
    'account': '2r45ab4',
    'target_address': '[email protected]'
}
signature = hmac_example.sign_request(
  url, 
  nonce, 
  body=body
)

headers = {
    'ACCESS_SIGNATURE': signature,
    'ACCESS_KEY': hmac_example.API_KEY,
    'ACCESS_NONCE': nonce,
    'Content-Type': 'application/json',
    'Accept': 'application/json'
}

requests.post(url, headers=headers, data=body)

A successful request would return the following response:

{
    "transfer": {
        "id":"1bbq",
        "account":"2r45ab4",
        "amount":"0.00010000",
        "target_address":"[email protected]",
        "payment": null,
        "status":"pending",
        "created_at":"2015-05-01T12:11:36.938Z"
    }
}