First of all, this is very cool. It is very elegantly integrated. great work.
Regarding the following –
This largely depends on your trading style. But to accurately calculate this, I use a term called “real cash”.
RC = OB-SOP
RC => Real Money
OB => Opening Balance of Kite for the Current Day> Funds
SOP => Short Option Premium from the current console > Dashboard. This can only be used after Zerodha has updated the data of the previous day which it does without fail.
I think LOP (Long Option Premium) should not be part of this equation because it is already calculated directly in the available cash. Replace the available cash with this real cash and your deviation will be reduced to less than 5%. If the user chooses the basket option, you can require the user to manually punch these two values from the kite money and dashboard to accurately calculate the basket margin.
I hope this helps you.