Can't set leverage.

I used this code to set Leverage Binance Future

                        // API key and secret
                        const api_key = process.env.API_KEY;
                        const api_secret = process.env.SECRET_KEY;
                        

                        
                        // Parameters for the API call
                        const symbol = "BTCBUSD";
                        const leverage = 25;
                        const recv_window = 5000;
                        const timestamp = Date.now();
                        // Create the signature for the request
                        const query_string = `symbol=${symbol}&leverage=${leverage}&recvWindow=${recv_window}&timestamp=${timestamp}`;
                        const signature = crypto.createHmac('sha256', api_secret).update(query_string).digest('hex');

                        // Make the POST request to the API endpoint
                        const url = "https://fapi.binance.com/fapi/v1/leverage";
                        const headers = {
                            "X-MBX-APIKEY": api_key
                        };
                        const data = {
                            symbol,
                            leverage,
                            recvWindow: recv_window,
                            timestamp,
                            signature
                        };

                        async function setLeverage() {
                            try {
                                const response = await axios.post(url, data, { headers });
                                //console.log(response.data);
                            } catch (error) {
                                console.log(error);
                            }
                        }

                        setLeverage();

But error:

data: {
      code: -1102,
      msg: "Mandatory parameter 'timestamp' was not sent, was empty/null, or malformed."
    }

I checked timestamp, it had value.

method: 'post',
    url: 'https://fapi.binance.com/fapi/v1/leverage',
    data: '{"symbol":"BTCBUSD","leverage":25,"recvWindow":5000,"timestamp":1673841743735,"signature":"..."}'

How can i solve this issue ?
Thank in advanced !

please have a try by setting the parameters in url.

1 Like