我一直感谢你们所有人。
我想通过Binance API查看我的帐户状态
(https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#account-information-user_data) (请参阅“帐户信息(USER_DATA)”部分)
我知道如何发送纯HTTPGet请求,但不知道如何对其进行签名。
我的代码如下
public static void wallet_status () throws NoSuchAlgorithmException, InvalidKeyException {
//GET /api/v3/account (HMAC SHA256)
String url = "https://api.binance.com/api/v3/account";
//sign url
Mac shaMac = Mac.getInstance("HmacSHA256");
SecretKeySpec keySpec = new SecretKeySpec(BINANCE_SECRET_KEY.getBytes(), "HmacSHA256");
shaMac.init(keySpec);
final byte[] macData = shaMac.doFinal(url.getBytes());
String sign = Hex.encodeHexString(macData);
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet("https://api.binance.com/api/v3/account");
request.addHeader("timestamp", nonce);
try {
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null) {
try (InputStream stream = entity.getContent()) {
BufferedReader reader =
new BufferedReader(new InputStreamReader(stream));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
我知道这部分应该修改
HttpGet request = new HttpGet("https://api.binance.com/api/v3/account");
请帮助。