Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

batchOrders -> Signature for this request is not valid #22

Open
hoi-nx opened this issue Nov 21, 2023 · 0 comments
Open

batchOrders -> Signature for this request is not valid #22

hoi-nx opened this issue Nov 21, 2023 · 0 comments

Comments

@hoi-nx
Copy link

hoi-nx commented Nov 21, 2023

`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}]&timestamp=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}]&timestamp=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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant