Sample code for 30+ languages & platforms
C#

Bitfinex v2 REST Submit Order

See more Bitfinex v2 REST Examples

Submit an order.

Chilkat C# Downloads

C#
bool success = false;

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

Chilkat.Http http = new Chilkat.Http();

Chilkat.Crypt2 crypt = new Chilkat.Crypt2();

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

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

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

Chilkat.JsonObject 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);
string body = json.Emit();

Chilkat.StringBuilder 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);

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

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

Chilkat.HttpResponse 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) {
    Debug.WriteLine(http.LastErrorText);
    return;
}

Debug.WriteLine("Response body:");
Debug.WriteLine(resp.BodyStr);