Sample code for 30+ languages & platforms
C

Bitfinex v2 REST User Info

See more Bitfinex v2 REST Examples

Retrieve the user ID, email, username and timezone setting for the account associated with the API key used.

Chilkat C Downloads

C
#include <C_CkHttp.h>
#include <C_CkCrypt2.h>
#include <C_CkDateTime.h>
#include <C_CkStringBuilder.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttp http;
    HCkCrypt2 crypt;
    const char *apiPath;
    const char *apiKey;
    const char *apiSecret;
    HCkDateTime dt;
    HCkStringBuilder sbNonce;
    const char *nonce;
    const char *body;
    HCkStringBuilder sbSignature;
    const char *sig;
    HCkHttpResponse resp;

    success = FALSE;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttp_Create();

    // Implements the following CURL command:

    // curl -X POST -H "bfx-nonce: nonce" \
    //   -H "bfx-apikey: apiKey" \
    //   -H "bfx-signature: sig" \ 
    //   https://api.bitfinex.com/v2/auth/r/info/user

    // Use the following online tool to generate HTTP code from a CURL command
    // Convert a cURL Command to HTTP Source Code

    crypt = CkCrypt2_Create();

    apiPath = "v2/auth/r/info/user";
    apiKey = "MY_API_KEY";
    apiSecret = "MY_API_SECRET";

    dt = CkDateTime_Create();
    CkDateTime_SetFromCurrentSystemTime(dt);

    sbNonce = CkStringBuilder_Create();
    CkStringBuilder_Append(sbNonce,CkDateTime_getAsUnixTimeStr(dt,FALSE));
    CkStringBuilder_Append(sbNonce,"000");
    nonce = CkStringBuilder_getAsString(sbNonce);

    // This particular request has an empty body.
    body = "";

    sbSignature = CkStringBuilder_Create();
    CkStringBuilder_Append(sbSignature,"/api/");
    CkStringBuilder_Append(sbSignature,apiPath);
    CkStringBuilder_Append(sbSignature,nonce);
    CkStringBuilder_Append(sbSignature,body);

    CkCrypt2_putEncodingMode(crypt,"hex_lower");
    CkCrypt2_putHashAlgorithm(crypt,"sha384");
    CkCrypt2_putMacAlgorithm(crypt,"hmac");
    CkCrypt2_SetMacKeyString(crypt,apiSecret);

    sig = CkCrypt2_macStringENC(crypt,CkStringBuilder_getAsString(sbSignature));

    CkHttp_SetRequestHeader(http,"bfx-apikey",apiKey);
    CkHttp_SetRequestHeader(http,"bfx-signature",sig);
    CkHttp_SetRequestHeader(http,"bfx-nonce",nonce);

    resp = CkHttpResponse_Create();
    success = CkHttp_HttpNoBody(http,"POST","https://api.bitfinex.com/v2/auth/r/info/user",resp);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkCrypt2_Dispose(crypt);
        CkDateTime_Dispose(dt);
        CkStringBuilder_Dispose(sbNonce);
        CkStringBuilder_Dispose(sbSignature);
        CkHttpResponse_Dispose(resp);
        return;
    }

    printf("Response body:\n");
    printf("%s\n",CkHttpResponse_bodyStr(resp));

    // Sample response body:

    // [1234567,"joe@example.com","joe_trader",1527691729000,0,null,null,"Central Time (US & Canada)"]


    CkHttp_Dispose(http);
    CkCrypt2_Dispose(crypt);
    CkDateTime_Dispose(dt);
    CkStringBuilder_Dispose(sbNonce);
    CkStringBuilder_Dispose(sbSignature);
    CkHttpResponse_Dispose(resp);

    }