getMargins for the current basket order is not fetching the correct value

I check the margins before placing basket order. Sometimes, my order gets rejected by RMS though I do a check. Below is an example:
Below is the code
const {
equity: { net }
} = await kite.getMargins()

console.log('[ensureMarginForBasketOrder]', { net })

const { data } = await
headers: {
'X-Kite-Version': 3,
Authorization: `token ${KITE_API_KEY as string}:${user.session
.access_token as string}`,
'Content-Type': 'application/json'

const totalMarginRequired = data?.data?.initial?.total

console.log('[ensureMarginForBasketOrder]', { totalMarginRequired })
Output is below:

[ensureMarginForBasketOrder] { net: 1126738.0322499997 }
[kha-ching] [2022-01-19 07:03:57] [ensureMarginForBasketOrder] { totalMarginRequired: 1109165.4360000002 }
Though totalMargin required is less than available margin (net), I still got the error today while placing the order:
   "order_id": "220119202409403",
"exchange_order_id": null,
"parent_order_id": null,
"status": "REJECTED",
"status_message": "Insufficient funds. Required margin is 4008865.49 but available margin is 3966419.10. Check the orderbook for open orders.",
"status_message_raw": "RMS:Margin Exceeds,Required:4008865.49, Available:3966419.10 for entity account-ZZ0829 across exchange across segment across product ",
"order_timestamp": "2022-01-19T07:03:58.000Z",
"exchange_update_timestamp": null,
"exchange_timestamp": null,
"variety": "regular",
"exchange": "NFO",
"tradingsymbol": "NIFTY2212017950PE",

Could you please check? Is there a bug or something I could do to avoid this error? For every basket order, I check the margin before placing it. So, there is no chance that any other order was placed in between the check for margin and the actual order.
  • rakeshr
    The difference might come because of the margin benefit pass-on. This thread might help. We are checking on this.
  • donisback
    Hi Rakesh,
    Though the above thread is above helpful, it doesn't answer my question. If the basket order requires higher margins, so be it, but please return the proper margin too in the margin calculation API.
    The margin returned by the API is different from the margin required during order execution
  • donisback
    Any update on this @rakeshr ?
  • rakeshr
    The margin returned by the API is different from the margin required during order execution
    As explained in the above thread basket margin API consider margin benefit for all 3 legs before the position is created but we have restricted this 3rd leg margin benefit before position creation, because of our risk management policy for now, as this is done to ensure that the margin doesn't significantly go up if the client closes the margin benefit position before the full portfolio is created.
    This can change depending on our risk policy in the future. But, for now, only for 3 legged margin benefit, the net margin will be benefited after all 3 positions are created. You need to consider this at your end.
  • donisback
    My basket order had only 2 legs (short straddle: CE+PE) not sure where the 3rd leg came.
    Also, any document on how to handle on my side?
  • rakeshr
    My basket order had only 2 legs (short straddle: CE+PE)
    Can you paste here the complete basket margin request param(including both order params)? We will check on this.
  • donisback
    I've DMed the details. As you could see above - I was trying to short NIFTY2212017950PE and NIFTY2212017950CE yesterday.
Sign In or Register to comment.