Java
Chilkat2 Java
Bitfinex v2 REST User Info
See more Bitfinex v2 REST Examples
Retrieve the user ID, email, username and timezone setting for the account associated with the API key used.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.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();
// Implements the following CURL command:
// curl -X POST -H "bfx-nonce: nonce" \
// -H "bfx-apikey: apiKey" \
// -H "bfx-signature: sig" \
// https://api.bitfinex.com/v2/auth/r/info/user
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
Crypt2 crypt = new Crypt2();
String apiPath = "v2/auth/r/info/user";
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();
// This particular request has an empty body.
String body = "";
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.httpNoBody("POST", "https://api.bitfinex.com/v2/auth/r/info/user", resp);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Response body:");
System.out.println(resp.getBodyStr());
// Sample response body:
// [1234567,"joe@example.com","joe_trader",1527691729000,0,null,null,"Central Time (US & Canada)"]
}
}