SAHI DOCS

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#

method api.get_funds(...)
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#

Order margin#

method api.get_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#

Basket margin#

method api.get_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.

legs list[dict] Required
One to ten orders, each a dict of place_order's arguments.
timeout float Optional
Seconds.

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.