Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Bitfinex v2 REST Submit OrderSubmit an order. For more information, see https://docs.bitfinex.com/reference#rest-auth-submit-order
#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) { HCkHttpW http; BOOL success; 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; // 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 = CkHttpW_PostJson2(http,L"https://api.bitfinex.com/v2/auth/w/order/submit",L"application/json",body); if (CkHttpW_getLastMethodSuccess(http) == 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); return; } wprintf(L"Response body:\n"); wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp)); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkCrypt2W_Dispose(crypt); CkDateTimeW_Dispose(dt); CkStringBuilderW_Dispose(sbNonce); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sbSignature); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.