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

donisback
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 axios.post(
'https://api.kite.trade/margins/basket?consider_positions=true&mode=compact',
orders,
{
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.
  • Souvick
    Souvick edited October 2023
    @rakeshr @sujith
    I am facing some issues with placing basket orders. I am trying to place Buy BANKNIFTY OCT 44500 PE, Buy BANKNIFTY OCT Fut, Sell BANKNIFTY OCT 44500 CE in a sequence.

    Before placing the order, I am checking margin_amount = kite.basket_order_margins and checking if my available margin >= 150% * margin_amount['initial']['total']. I believe margin_amount['initial']['total'] should give the sum of individual legs' required margin.

    But I am getting Insufficient funds error for the Leg3 (Sell BANKNIFTY OCT 44500 CE). I have no open position when I am trying to place this. I have also checked the margin calculator portal which is inline with my expectations. But there is huge difference between the required margin mentioned on the rejection alert vs. on the margin calculator portal. Could you please check?



  • themohammedfaisal
    @Souvick, the 3rd leg margin benefit will kick in after the position is created. Rakesh has explained this above.
    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.
  • Souvick
    @themohammedfaisal I agree. but I am interested in only 3rd leg's margin without any benefit. if the margin calculator shows ~79k for margin requirement only for Leg3, why the order book showing the requirement was 2.81L?
  • Souvick
    @themohammedfaisal - otherwise what would be the best way to calculate the 2.8L, before I place the order?
  • Souvick
    @rakeshr @sujith - can you please check?
  • themohammedfaisal
    themohammedfaisal edited October 2023
    @Souvick ,
    If you want margins for the 3rd leg, you can just check margins for that leg individually and add it up with the margins for the first 2 legs.
Sign In or Register to comment.