Programmatic Modification of API created SL order

ELLORA
Hi, For a intraday long Nifty option order was created through the API. Now for the new buy order, the program was able to create a SL Order. Then when as part of the program based TSLO logic, the code tried to update the initial SL order created. But got this error. ERROR in MODIFYING SL order for 2085225244812943360 - Insufficient funds. Margin required: 822825.65. Margin available: 295149.20. Add 527676.45 to place this order.
com.zerodhatech.kiteconnect.kitehttp.exceptions.MarginException: Insufficient funds. Margin required: 822825.65. Margin available: 295149.20. Add 527676.45 to place this order.
at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.dealWithException(KiteResponseHandler.java:63)
at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.handle(KiteResponseHandler.java:21)
at com.zerodhatech.kiteconnect.kitehttp.KiteRequestHandler.putRequest(KiteRequestHandler.java:126)
at com.zerodhatech.kiteconnect.KiteConnect.modifyOrder(KiteConnect.java:438)
at neo.IntraDriver3.modifyOrder(IntraDriver3.java:631) - Earlier I used to run this and never got this. Any suggestions on why?

This is my initial SL order creation code. This created a SL order successfully. public String enterSLTrade(String tradingSymbol, int size, double buyPrice) {

// Code to enter a Call trade
System.out.println(
"^^^ Creating a new STOP LOSS trade... " + tradingSymbol + " size " + size + " buyPrice " + buyPrice);

OrderParams orderParams = new OrderParams();
orderParams.quantity = size;
double triggerPrice = Math.round((buyPrice * 0.92));

if (insideDB)
triggerPrice = Math.round((buyPrice * 0.92));

orderParams.orderType = Constants.ORDER_TYPE_SL;
orderParams.triggerPrice = triggerPrice;
orderParams.price = triggerPrice - 10;
orderParams.tradingsymbol = tradingSymbol;
orderParams.product = Constants.PRODUCT_MIS;
orderParams.exchange = Constants.EXCHANGE_NFO;
orderParams.transactionType = Constants.TRANSACTION_TYPE_SELL;
orderParams.validity = Constants.VALIDITY_DAY;
orderParams.tag = "scalp";
// orderParams.marketProtection = 5.0;

OrderResponse order;
try {
order = kiteConnect.placeOrder(orderParams, Constants.VARIETY_REGULAR);
logMSg("Order ID " + order.orderId);

The following is my modify order code that is failing.
public boolean modifyOrder(String orderId, int qty, double triggerPrice, boolean closeNow, boolean forceReplace) {

System.out.println("^^^ Modifying a STOP LOSS trade... ID: " + orderId + " Trigger: " + Math.round(triggerPrice)
+ " (Mod Count: " + (this.currentSLModCount + 1) + ")");

if (!closeNow)
triggerPrice = Math.round(triggerPrice);

// Order modify request will return order model which will contain only
// order_id.
OrderParams orderParams = new OrderParams();
orderParams.orderType = Constants.ORDER_TYPE_SL;
orderParams.validity = Constants.VALIDITY_DAY;
orderParams.quantity = qty;

if (!closeNow) {
orderParams.triggerPrice = triggerPrice;
orderParams.price = triggerPrice - 10;
}

if (closeNow) {
orderParams.orderType = Constants.ORDER_TYPE_SL;
orderParams.price = triggerPrice;
// orderParams.marketProtection = 5.0;
}

try {
Order order21 = kiteConnect.modifyOrder(orderId, orderParams, Constants.VARIETY_REGULAR);
This discussion has been closed.