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
(C) Bitfinex v2 REST Submit OrderSubmit an order. For more information, see https://docs.bitfinex.com/reference#rest-auth-submit-order
#include <C_CkHttp.h> #include <C_CkCrypt2.h> #include <C_CkDateTime.h> #include <C_CkStringBuilder.h> #include <C_CkJsonObject.h> #include <C_CkHttpResponse.h> void ChilkatSample(void) { HCkHttp http; BOOL success; HCkCrypt2 crypt; const char *apiPath; const char *apiKey; const char *apiSecret; HCkDateTime dt; HCkStringBuilder sbNonce; const char *nonce; HCkJsonObject json; const char *body; HCkStringBuilder sbSignature; const char *sig; HCkHttpResponse resp; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttp_Create(); crypt = CkCrypt2_Create(); apiPath = "v2/auth/w/order/submit"; 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); json = CkJsonObject_Create(); CkJsonObject_UpdateString(json,"type","LIMIT"); CkJsonObject_UpdateString(json,"symbol","tBTCUSD"); CkJsonObject_UpdateString(json,"price","15"); CkJsonObject_UpdateString(json,"amount","0.001"); CkJsonObject_UpdateInt(json,"flags",0); body = CkJsonObject_emit(json); 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 = CkHttp_PostJson2(http,"https://api.bitfinex.com/v2/auth/w/order/submit","application/json",body); if (CkHttp_getLastMethodSuccess(http) == FALSE) { printf("%s\n",CkHttp_lastErrorText(http)); CkHttp_Dispose(http); CkCrypt2_Dispose(crypt); CkDateTime_Dispose(dt); CkStringBuilder_Dispose(sbNonce); CkJsonObject_Dispose(json); CkStringBuilder_Dispose(sbSignature); return; } printf("Response body:\n"); printf("%s\n",CkHttpResponse_bodyStr(resp)); CkHttpResponse_Dispose(resp); CkHttp_Dispose(http); CkCrypt2_Dispose(crypt); CkDateTime_Dispose(dt); CkStringBuilder_Dispose(sbNonce); CkJsonObject_Dispose(json); CkStringBuilder_Dispose(sbSignature); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.