Sample code for 30+ languages & platforms
Unicode 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 Unicode C Downloads

Unicode C
#include <C_CkHttpW.h>
#include <C_CkCrypt2W.h>
#include <C_CkDateTimeW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkCrypt2W crypt;
    const wchar_t *apiPath;
    const wchar_t *apiKey;
    const wchar_t *apiSecret;
    HCkDateTimeW dt;
    HCkStringBuilderW sbNonce;
    const wchar_t *nonce;
    const wchar_t *body;
    HCkStringBuilderW sbSignature;
    const wchar_t *sig;
    HCkHttpResponseW resp;

    success = FALSE;

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

    http = CkHttpW_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 = CkCrypt2W_Create();

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

    dt = CkDateTimeW_Create();
    CkDateTimeW_SetFromCurrentSystemTime(dt);

    sbNonce = CkStringBuilderW_Create();
    CkStringBuilderW_Append(sbNonce,CkDateTimeW_getAsUnixTimeStr(dt,FALSE));
    CkStringBuilderW_Append(sbNonce,L"000");
    nonce = CkStringBuilderW_getAsString(sbNonce);

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

    sbSignature = CkStringBuilderW_Create();
    CkStringBuilderW_Append(sbSignature,L"/api/");
    CkStringBuilderW_Append(sbSignature,apiPath);
    CkStringBuilderW_Append(sbSignature,nonce);
    CkStringBuilderW_Append(sbSignature,body);

    CkCrypt2W_putEncodingMode(crypt,L"hex_lower");
    CkCrypt2W_putHashAlgorithm(crypt,L"sha384");
    CkCrypt2W_putMacAlgorithm(crypt,L"hmac");
    CkCrypt2W_SetMacKeyString(crypt,apiSecret);

    sig = CkCrypt2W_macStringENC(crypt,CkStringBuilderW_getAsString(sbSignature));

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

    resp = CkHttpResponseW_Create();
    success = CkHttpW_HttpNoBody(http,L"POST",L"https://api.bitfinex.com/v2/auth/r/info/user",resp);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkCrypt2W_Dispose(crypt);
        CkDateTimeW_Dispose(dt);
        CkStringBuilderW_Dispose(sbNonce);
        CkStringBuilderW_Dispose(sbSignature);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    wprintf(L"Response body:\n");
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));

    // Sample response body:

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


    CkHttpW_Dispose(http);
    CkCrypt2W_Dispose(crypt);
    CkDateTimeW_Dispose(dt);
    CkStringBuilderW_Dispose(sbNonce);
    CkStringBuilderW_Dispose(sbSignature);
    CkHttpResponseW_Dispose(resp);

    }