Python SDK
Funds
Read available balances and quote the margin an order or basket would need.
Balances and pre-trade margin checks, from the Funds
endpoints. Margin checks take place_order's arguments and are never retried.
Examples use api and quote from Getting started.
Available balances#
api.get_funds(*, timeout: float | None = None) -> dict
Calls GET /v1/funds · Scope: funds.read
There is no single balance: available has one figure per kind of order.
Returns#
available, balance, utilised and option_premium, in paise, as
the endpoint
documents. The available keys:
| Key | Spendable on |
|---|---|
stocks_delivery |
Delivery buys. Pledge collateral does not count. |
intraday_and_fno_selling |
Intraday, futures and option selling. Pledge collateral counts. |
options_buying |
Option buys, per premium pool: equity_fno, mcx, ncom. |
Raises#
SahiNotFoundException: the account is not set up for trading.SahiRateLimitException: over 1/s.
Order margin#
api.get_order_margin(*, exchange_segment: str, symbol: str, txn_type: str, qty: int, order_type: str, product: str, validity: str, price: int, trigger_price: int | None = None, disclosed_qty: int | None = None, market_protection: float | None = None, variant: str | None = None, timeout: float | None = None) -> dict
Calls POST /v1/margins/order · Scope: funds.read
The margin one order would need. Nothing is placed, and tick size, price band and lot size are not checked.
Returns#
{"required_margin": ..., "available_margin": ...}, in paise.
Raises#
SahiMaintenanceException: 04:45–07:00 IST, during start-of-day processing. Retry after 07:00.SahiValidationExceptionandSahiNotFoundException: as forplace_orderandget_funds.SahiRateLimitException: over 5/s, 250/min or 10,000/day, shared with the basket check.
Basket margin#
api.get_basket_margin(legs: list[dict], *, timeout: float | None = None) -> dict
Calls POST /v1/margins/basket · Scope: funds.read
The margin for one to ten orders together, netted against each other and your
positions. available_margin is a single pool, so it can overstate a basket
that mixes pools.
place_order's arguments.Returns#
{"required_margin": ..., "available_margin": ...}, in paise.
Raises#
TypeError: a leg is missing a key or has an unknown one, raised before sending.SahiValidationException: a leg breaks a rule, or the list is empty or over ten.- Otherwise as for
get_order_margin.