Sample code for 30+ languages & platforms
Node.js

Bitfinex v2 REST Submit Order

See more Bitfinex v2 REST Examples

Submit an order.

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

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

    var http = new chilkat.Http();

    var crypt = new chilkat.Crypt2();

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

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

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

    var json = new chilkat.JsonObject();
    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 chilkat.StringBuilder();
    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 chilkat.HttpResponse();
    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);

}

chilkatExample();