Authentication and API Keys

Get your API keys to unlock full access to all EarnBIT API features.

Get your API keys

Follow simple steps to generate API keys for using private endpoints:

  • Sign In to the EarnBIT exchange and navigate to the API Management section in your profile. (Note: You also need to enable two-step authentication if you haven't already)

  • To create API keys, click Add API Key. A package of keys will be generated, including an API Public Key, an API Secret Key, and a WebSocket Token. You can create up to 5 packages of API keys.

  • Before using your API keys, they must be activated. To activate them, use the "Activate API" switch in the created package.

Requirements

  • Base URL: https://api.earnbit.com

  • Auth requests should be using POST method and should include:

    • Body data with JSON that contains the following params:

      • "request" - a request endpoint path without the domain name. Example: "/api/v1/account/balance"

        • "nonce" - a 13-character number that must always be greater than the nonce of the previous completed request. For example: "1704070810000". We suggest generating a nonce as the UNIX timestamp in milliseconds. This ensures you always get an incrementing number, but be careful not to send two API calls simultaneously, as their nonces will be identical, causing one of the requests to be rejected.

        • params of request (depending on choosen request)

    • Headers - With every request you need to provide next headers:

      • 'Content-type': 'application/json'

        • 'X-TXC-APIKEY': api_key (it's your public EarnBIT API key)

        • 'X-TXC-PAYLOAD': payload (it's payload is base64-encoded body data)

        • 'X-TXC-SIGNATURE': signature (it's signature is hex(HMAC_SHA512(payload), key=api_secret))

Connection Examples

To assist you in getting started with our API, we've provided sample code in multiple programming languages.

use GuzzleHttp\Client;

public function callApi()
{
    $apiKey = 'xxxxxxxxx';
    $apiSecret = 'xxxxxxxxxxxx';
    $request = '/api/v1/account/balances';
    $baseUrl = 'https://api.earnbit.com';

    $data = [
        'request' => $request,
        'nonce' => (string)\Carbon\Carbon::now()->getTimestampMs(),
    ];

    $completeUrl = $baseUrl . $request;
    $dataJsonStr = json_encode($data, JSON_UNESCAPED_SLASHES);
    $payload = base64_encode($dataJsonStr);
    $signature = hash_hmac('sha512', $payload, $apiSecret);

    $client = new Client();
    try {
        $res = $client->post($completeUrl, [
            'headers' => [
                'Content-type' => 'application/json',
                'X-TXC-APIKEY' => $apiKey,
                'X-TXC-PAYLOAD' => $payload,
                'X-TXC-SIGNATURE' => $signature
            ],
            'body' => json_encode($data, JSON_UNESCAPED_SLASHES)
        ]);
    } catch (\Exception $e) {
        return response()->json(['error' => $e->getMessage()]);
    }

    return response()->json(['result' => json_decode($res->getBody()->getContents())]);
}
Errors

Response example:

{
    "code": 400,
    "success": false,
    "message": "authentication failure",
    "result": []
}

This error occurs in the following cases:

  • The request was signed incorrectly.

  • Some of the provided parameters are incorrect.

  • Provided nonce is incorrect or less than on the previous completed request

  • The base URL or path is incorrect.

  • The API keys are not activated.

Last updated