Skip to content

api_authentication

luogang edited this page Nov 30, 2021 · 6 revisions

API Authentication

  • You must set ip whitelist on the mining setting page before calling API. Subaccounts will inherit ip whitelist setting from the primary account when its ip whitelist is empty.

  • Each account or subaccount has a pair of api key and secret key, which can be found on the mining setting page. Such as(sample api key, not work):

key value
api_key 16289e05354c3c3814b8f3045950395f
secret_key d186ababcb0eb1f6af5c1519424f462b84c631f86c06309992ae1f15604668b0
  • API need authentication. Just send request with the header X-API-KEY: <your_api_key>:
curl 'https://www.viabtc.net/res/openapi/v1/hashrate?coin=BTC' \
-H 'X-API-KEY: 16289e05354c3c3814b8f3045950395f'
  • Some API need a signature. Following the setps to sign a request:
  1. Add tonce field to the request parameter. The value of tonce is current timestamp accurate to milliseconds.
key value
coin BTC
amount 1.0
tonce 1513746038205
  1. If it is a GET or DELETE request, generate query string(in any order):
coin=BTC&amount=1.0&tonce=1513746038205

Calculate the HMAC SHA256 signature of query string with secret key:

echo -n 'coin=BTC&amount=1.0&tonce=1513746038205' \
| openssl dgst -sha256 -hmac "d186ababcb0eb1f6af5c1519424f462b84c631f86c06309992ae1f15604668b0"

# output: 4a1c9e4c73629b62fd999cbbcd2bc8b87a07f1791ae61ba576427f820dd3bc59

If it is a POST or PUT request, generate request body(in any order):

{"coin": "BTC", "amount": "1.0", "tonce": 1513746038205}

Calculate the HMAC SHA256 signature of request body with secret key:

echo -n '{"coin": "BTC", "amount": "1.0", tonce: 1513746038205}' \
| openssl dgst -sha256 -hmac "d186ababcb0eb1f6af5c1519424f462b84c631f86c06309992ae1f15604668b0"

# output: 2dd2cc09cb5b11c7f24d457b1c01e46f2f2b17f06a62bf29eda35b5fb45ce354
  1. Send the request with X-API-KEY: <your_api_key> and X-SIGNATURE: <signature> header. The query string or request body of the request should be from the previous step.
curl 'https://www.viabtc.net/res/openapi/v1/hashrate?coin=BTC&amount=1.0&tonce=1513746038205' \
-H 'X-API-KEY: 16289e05354c3c3814b8f3045950395f' \
-H 'X-SIGNATURE: 4a1c9e4c73629b62fd999cbbcd2bc8b87a07f1791ae61ba576427f820dd3bc59'

or

curl 'https://www.viabtc.net/res/openapi/v1/hashrate' \
-H 'Content-Type: application/json' \
-H 'X-API-KEY: 16289e05354c3c3814b8f3045950395f' \
-H 'X-SIGNATURE: 2dd2cc09cb5b11c7f24d457b1c01e46f2f2b17f06a62bf29eda35b5fb45ce354' \
-d '{"coin": "BTC", "amount": "1.0", tonce: 1513746038205}' \
-X POST