binance / binance/binance-futures-connector-java
batchOrders -> Signature for this request is not valid
- Dominant language
- Java
- Stars
- 191
- Forks
- 96
- PR merge metrics
- No merged PRs in 30d
Description
`final static String HMAC_SHA256 = "HmacSHA256";
//convert byte array to hex string
private static String bytesToHex(byte[] bytes) {
final char[] hexArray = "0123456789abcdef".toCharArray();
char[] hexChars = new char[bytes.length * 2];
for (int j = 0, v; j < bytes.length; j++) {
v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
return new String(hexChars);
}`
` public static String getSignature(String data, String key) {
byte[] hmacSha256 = null;
try {
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), HMAC_SHA256);
Mac mac = Mac.getInstance(HMAC_SHA256);
mac.init(secretKeySpec);
hmacSha256 = mac.doFinal(data.getBytes());
} catch (Exception e) {
throw new RuntimeException("Failed to calculate hmac-sha256", e);
}
return bytesToHex(hmacSha256);
}`
`queryString = "batchOrders=[{"symbol":"BTCUSDT","side":"SELL","type":"LIMIT","price":"37300","timeInForce":"GTC","quantity":1.0},{"symbol":"BTCUSDT","side":"BUY","type":"TAKE_PROFIT_MARKET","stopPrice":"37000","timeInForce":"GTC","quantity":1.0},{"symbol":"BTCUSDT","side":"BUY","type":"STOP_MARKET","stopPrice":"37900","timeInForce":"GTC","quantity":1.0}]×tamp=1700531873609"`
`String signature = Signature.getSignature(queryString, secretKey);`
`https://testnet.binancefuture.com/fapi/v1/batchOrders?batchOrders=[{"symbol":"BTCUSDT","side":"SELL","type":"LIMIT","price":"37300","timeInForce":"GTC","quantity":1.0},{"symbol":"BTCUSDT","side":"BUY","type":"TAKE_PROFIT_MARKET","stopPrice":"37000","timeInForce":"GTC","quantity":1.0},{"symbol":"BTCUSDT","side":"BUY","type":"STOP_MARKET","stopPrice":"37900","timeInForce":"GTC","quantity":1.0}]×tamp=1700531873609&signature=9e5d7f6a32aa1fa48e909d8849394e2f1a5cbd11075d259fef1daf6f33cabe94`
**When I call the placeMultipleOrders api the result returns the error {"code":-1022,"msg":"Signature for this request is not valid."}. How can I fix it?**
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by comparing the Java HMAC-SHA256 input in getSignature with the exact batchOrders query string sent to the Binance Futures testnet endpoint. Check the request encoding and parameter representation against the API signing requirements; this is done when the same batchOrders request is accepted without error -1022.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100