Get equity funds/margins

Before placing an order you need to know how much cash/margin is available. Never assume — check.

margins = kite.margins(segment="equity")
print(margins)

Key fields:

{
  "available": {
    "cash": 48250.35,          # free cash
    "live_balance": 48250.35,  # cash + unrealised MTM adjustments
    "opening_balance": 50000.0,
  },
  "utilised": {
    "debits": 1749.65,         # margin blocked by open positions/orders
    "span": 0.0,
    "exposure": 0.0,
    "m2m_realised": 0.0,
    "m2m_unrealised": 0.0,
  },
  "net": 48250.35,
}

available["cash"] is what you can safely deploy on a fresh CNC buy. net is the number to check before sizing any new position — it already accounts for what's tied up in existing orders and positions.

def get_available_cash(kite) -> float:
    return kite.margins(segment="equity")["available"]["cash"]

Why check this every time, not just once at startup

Margin changes continuously — from fills, from mark-to-market on open positions, from other orders placed manually or by other bots on the same account. A sizing function that used a startup-time snapshot will eventually try to place an order with capital that's no longer free, producing an avoidable rejection (chapter 57) or, worse, a margin call. Fetch fresh margins immediately before each sizing decision.

Next: 013 — Get commodity/currency margins