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?