【发布时间】:2026-01-07 13:20:05
【问题描述】:
我在通过 Binance exchange 发送 HTTP Get 请求时遇到问题。 (我需要返回我的钱包状态)
GitHub 手册说 (https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md)
账户信息(USER_DATA)
GET /api/v3/account (HMAC SHA256)
获取当前帐户信息。
重量:5
参数:
名称类型必填说明
recvWindow 长无
timestamp LONG YES
我的代码如下所示
public static String timestamp = String.valueOf(System.currentTimeMillis());
public static void wallet_status () throws NoSuchAlgorithmException, InvalidKeyException {
String url = "https://api.binance.com/api/v3/account×tamp=" + timestamp;
//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"+"?timestamp="+timestamp+"?signature="+sign);
request.addHeader("X-MBX-APIKEY", BINANCE_API_KEY);
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();
}
} //end
服务器响应如下
{"code":-1100,"msg":"参数'timestamp'中发现非法字符;合法范围是'^[0-9]{1,20}$'。"}
但我的字符串时间戳是 13 位数字字符串,应该没问题。请帮忙。
【问题讨论】:
-
添加时间戳变量值示例
-
时间戳 1499827319559 不起作用
-
我建议你从 binance java API 开始,或者阅读他们建议的代码。