Unable to change the leverage using Node JS SDK

Hi,
I am trying to change the leverage for BTCUSD with the below code in NodeJS, but throwing error, can anybody please help

new DeltaRestClient(vApiKey, vApiSecret).then(client => {
    client.apis.Orders.changeOrderLeverage({
        product_id: 27,
        order_leverage: {
          leverage: '50'
        }
      }).then(function (response) {
        let objResult = JSON.parse(response.data);

        if(objResult.success){
            res.send({ "status": "success", "message": "Order Leverage is Set Successfully!", "data": objResult });
        }
        else{
            res.send({ "status": "warning", "message": "Error: Contact Admin!", "data": objResult });
        }
    })
    .catch(function(objError) {
        console.log(objError);
        res.send({ "status": "danger", "message": objError.response.text, "data": objError });
    });
});

Thank You,
ANIL

1 Like

You’re using
client.apis.Orders.changeOrderLeverage()
which doesn’t match the actual API endpoint structure. According to the Delta Exchange documentation, the correct endpoint for changing leverage is:

POST /products/{product_id}/orders/leverage

Here’s how you should modify your code to correctly change the leverage for BTCUSD:

new DeltaRestClient(vApiKey, vApiSecret).then(client => {
    // The correct endpoint is /products/{product_id}/orders/leverage
    client.post(`/products/27/orders/leverage`, {
        leverage: '50'  // This should be the body parameter
    })
    .then(function (response) {
        let objResult = response.data;  // The response might already be parsed

        if(objResult.success){
            res.send({ "status": "success", "message": "Order Leverage is Set Successfully!", "data": objResult });
        }
        else{
            res.send({ "status": "warning", "message": "Error: Contact Admin!", "data": objResult });
        }
    })
    .catch(function(objError) {
        console.log(objError);
        res.send({ "status": "danger", "message": objError.response ? objError.response.text : objError.message, "data": objError });
    });
});

Let me know if this helps or if you need further assistance!

Sir,
Its not working and the error is
D:\NodeJS\AlgoMarti\server\controller\controllerDeltaLive.js:70
client.post(/products/27/orders/leverage, { leverage: ‘50’ }).then(function (response) {
^

TypeError: client.post is not a function
at D:\NodeJS\AlgoMarti\server\controller\controllerDeltaLive.js:70:16
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Node.js v22.14.0

Our team is currently looking into this and will get back to you as soon as we have a solution. Thank you for your patience!