Sample code for 30+ languages & platforms
JavaScript

Bitfinex v2 REST Submit Order

See more Bitfinex v2 REST Examples

Submit an order.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

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

var http = new CkHttp();

var crypt = new CkCrypt2();

var apiPath = "v2/auth/w/order/submit";
var apiKey = "MY_API_KEY";
var apiSecret = "MY_API_SECRET";

var dt = new CkDateTime();
dt.SetFromCurrentSystemTime();

var sbNonce = new CkStringBuilder();
sbNonce.Append(dt.GetAsUnixTimeStr(false));
sbNonce.Append("000");
var nonce = sbNonce.GetAsString();

var json = new CkJsonObject();
json.UpdateString("type","LIMIT");
json.UpdateString("symbol","tBTCUSD");
json.UpdateString("price","15");
json.UpdateString("amount","0.001");
json.UpdateInt("flags",0);
var body = json.Emit();

var sbSignature = new CkStringBuilder();
sbSignature.Append("/api/");
sbSignature.Append(apiPath);
sbSignature.Append(nonce);
sbSignature.Append(body);

crypt.EncodingMode = "hex_lower";
crypt.HashAlgorithm = "sha384";
crypt.MacAlgorithm = "hmac";
crypt.SetMacKeyString(apiSecret);

var sig = crypt.MacStringENC(sbSignature.GetAsString());

http.SetRequestHeader("bfx-apikey",apiKey);
http.SetRequestHeader("bfx-signature",sig);
http.SetRequestHeader("bfx-nonce",nonce);

var resp = new CkHttpResponse();
success = http.HttpStr("POST","https://api.bitfinex.com/v2/auth/w/order/submit",body,"utf-8","application/json",resp);
if (success == false) {
    console.log(http.LastErrorText);
    return;
}

console.log("Response body:");
console.log(resp.BodyStr);