Unicode C
Unicode C
Bitfinex v2 REST Submit Order
See more Bitfinex v2 REST Examples
Submit an order.Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkCrypt2W.h>
#include <C_CkDateTimeW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.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;
HCkJsonObjectW json;
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();
crypt = CkCrypt2W_Create();
apiPath = L"v2/auth/w/order/submit";
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);
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"type",L"LIMIT");
CkJsonObjectW_UpdateString(json,L"symbol",L"tBTCUSD");
CkJsonObjectW_UpdateString(json,L"price",L"15");
CkJsonObjectW_UpdateString(json,L"amount",L"0.001");
CkJsonObjectW_UpdateInt(json,L"flags",0);
body = CkJsonObjectW_emit(json);
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_HttpStr(http,L"POST",L"https://api.bitfinex.com/v2/auth/w/order/submit",body,L"utf-8",L"application/json",resp);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkCrypt2W_Dispose(crypt);
CkDateTimeW_Dispose(dt);
CkStringBuilderW_Dispose(sbNonce);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbSignature);
CkHttpResponseW_Dispose(resp);
return;
}
wprintf(L"Response body:\n");
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpW_Dispose(http);
CkCrypt2W_Dispose(crypt);
CkDateTimeW_Dispose(dt);
CkStringBuilderW_Dispose(sbNonce);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbSignature);
CkHttpResponseW_Dispose(resp);
}