It looks like you're new here. If you want to get involved, click one of these buttons!
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",
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
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.
Also, any document on how to handle on my side?
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?
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.