Unicode C++
Unicode C++
Bitfinex v2 REST Submit Order
See more Bitfinex v2 REST Examples
Submit an order.Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkCrypt2W.h>
#include <CkDateTimeW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
void ChilkatSample(void)
{
bool success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW http;
CkCrypt2W crypt;
const wchar_t *apiPath = L"v2/auth/w/order/submit";
const wchar_t *apiKey = L"MY_API_KEY";
const wchar_t *apiSecret = L"MY_API_SECRET";
CkDateTimeW dt;
dt.SetFromCurrentSystemTime();
CkStringBuilderW sbNonce;
sbNonce.Append(dt.getAsUnixTimeStr(false));
sbNonce.Append(L"000");
const wchar_t *nonce = sbNonce.getAsString();
CkJsonObjectW json;
json.UpdateString(L"type",L"LIMIT");
json.UpdateString(L"symbol",L"tBTCUSD");
json.UpdateString(L"price",L"15");
json.UpdateString(L"amount",L"0.001");
json.UpdateInt(L"flags",0);
const wchar_t *body = json.emit();
CkStringBuilderW sbSignature;
sbSignature.Append(L"/api/");
sbSignature.Append(apiPath);
sbSignature.Append(nonce);
sbSignature.Append(body);
crypt.put_EncodingMode(L"hex_lower");
crypt.put_HashAlgorithm(L"sha384");
crypt.put_MacAlgorithm(L"hmac");
crypt.SetMacKeyString(apiSecret);
const wchar_t *sig = crypt.macStringENC(sbSignature.getAsString());
http.SetRequestHeader(L"bfx-apikey",apiKey);
http.SetRequestHeader(L"bfx-signature",sig);
http.SetRequestHeader(L"bfx-nonce",nonce);
CkHttpResponseW resp;
success = http.HttpStr(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",http.lastErrorText());
return;
}
wprintf(L"Response body:\n");
wprintf(L"%s\n",resp.bodyStr());
}