Java
Chilkat2 Java
Bitfinex v2 REST Submit Order
See more Bitfinex v2 REST Examples
Submit an order.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Crypt2;
import com.chilkatsoft.chilkat2.DateTime;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;
public class ChilkatExample {
public static void main(String[] args) {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Http http = new Http();
Crypt2 crypt = new Crypt2();
String apiPath = "v2/auth/w/order/submit";
String apiKey = "MY_API_KEY";
String apiSecret = "MY_API_SECRET";
DateTime dt = new DateTime();
dt.setFromCurrentSystemTime();
StringBuilder sbNonce = new StringBuilder();
sbNonce.append(dt.getAsUnixTimeStr(false));
sbNonce.append("000");
String nonce = sbNonce.getAsString();
JsonObject json = new 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();
StringBuilder sbSignature = new StringBuilder();
sbSignature.append("/api/");
sbSignature.append(apiPath);
sbSignature.append(nonce);
sbSignature.append(body);
crypt.setEncodingMode("hex_lower");
crypt.setHashAlgorithm("sha384");
crypt.setMacAlgorithm("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);
HttpResponse resp = new HttpResponse();
try {
http.httpStr("POST", "https://api.bitfinex.com/v2/auth/w/order/submit", body, "utf-8", "application/json", resp);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Response body:");
System.out.println(resp.getBodyStr());
}
}