REST API: How do I put leverage as an input in the query?

Hey guys!
I am trying to place an order on binance futures with API, I couldn’t find how to work around if user has given a input of leverage that I want to be used while placing an order. Here’s a list of parameter I use in the current code (whole code below)

var params = {
timestamp: Date.now(),
recWindow: 20000,
    symbol: "BTCUSDT",
    side: "SELL",
    type: "STOP_MARKET",
    timeInForce: "GTC",
    price: 6200,
    quantity: 0.003
};

I couldn’t make it work with the help of this


Currently testing it on test net, but couldn’t find a way to put leverage in the code.

whole code:

const express = require("express");
const router = express.Router();
const UserApiConnection = require("../models/UserApiConnection");
const api = require('binance');
const apiHelper = require('../helpers/telnetBinance')
const axios = require('axios')
const jsonToQuery  = require('json-to-http-query-string')
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

const baseUrl =  "https://testnet.binancefuture.com/fapi/v1/";

async function getUser(user_id){
    const connection = await UserApiConnection.findOne({
        where: {
            'user_id': user_id
        }
    })
    return connection;
}

router.get("/user/account", async (req, res) => {
    var timestamp = Number(new Date());
    const params = {
        recWindow: 20000,
        timestamp: timestamp,
    };
    params.signature = apiHelper.generateHmacSign(
        params,
        apiHelper.binanceSecretkey({isTesting: true})
    );
    axios.get(baseUrl+"account", {
        params: params,
        headers: {
            "X-MBX-APIKEY": apiHelper.binanceApikey({
                isTesting:true
            }),
        },
    }).then((response)=>{
        res.send(response.data)
    })
})


router.get("/user/openOrders", (req, res) => {
    var timestamp = Number(new Date());
    const params = {
        recWindow: 20000,
        timestamp: timestamp
    };
    params.signature = apiHelper.generateHmacSign(
        params,
        apiHelper.binanceSecretkey({isTesting: true})
    );
    axios.get(baseUrl+"openOrders", {
        params: params,
        headers: {
            "X-MBX-APIKEY": apiHelper.binanceApikey({
                isTesting:true
            }),
        },
    }).then((response)=>{
        res.send(response.data)
    })    
})

router.get("/user/allOrders", (req, res) => {
    var timestamp = Number(new Date()); 
    const params = {
        recWindow: 20000,
        timestamp: timestamp
    };
    params.signature = apiHelper.generateHmacSign(
        params,
        apiHelper.binanceSecretkey({isTesting: true})
    );
    axios.get(baseUrl+"allOrders", {
        params: params,
        headers: {
            "X-MBX-APIKEY": apiHelper.binanceApikey({
                isTesting:true
            }),
        },
    }).then((response)=>{
        res.send(response.data)
    })    
})

router.get("/user/order", (req, res) => {
    var timestamp = Number(new Date());
    var params = {
        timestamp: Date.now(),
        recWindow: 20000,
        symbol: "BTCUSDT",
        side: "SELL",
        type: "STOP_MARKET",
        timeInForce: "GTC",
        price: 6200,
        quantity: 0.003
    };
    params.signature = apiHelper.generateHmacSign(
        params,
        apiHelper.binanceSecretkey({isTesting: true})
    );
    var ourRequest = new XMLHttpRequest();
    ourRequest.open('POST',baseUrl+"order?"+jsonToQuery(params),true);
    ourRequest.setRequestHeader('X-MBX-APIKEY', apiHelper.binanceApikey({isTesting: true}));
    ourRequest.onload = function(){
        res.send(ourRequest.responseText);
    }
    ourRequest.send();
})

module.exports = router;

The following endpoint changes the user’s leverage for a given symbol

1 Like

Thanks! That clears my doubt :slight_smile: