Get Margin¶
get_margin() estimates margin requirements before order placement. It supports single orders, basket-like payloads, portfolio-aware estimation, and optional leg-level breakdowns.
LLM guidance
Use this page when the goal is to estimate margin for a specific order payload before placement. Match the margin request shape to the actual execution workflow you plan to submit, including single-order versus basket-style payloads and portfolio-aware estimation. Do not use funds snapshots as a substitute for request-specific margin estimation. For account-level available capital, use Funds.
Basic Usage¶
from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
from nubra_python_sdk.trading.trading_data import NubraTrader
nubra = InitNubraSdk(NubraEnv.UAT, env_creds=True)
trader = NubraTrader(nubra, version="V2")
margin = trader.get_margin({
"with_portfolio": True,
"with_legs": False,
"is_basket": False,
"order_req": {
"exchange": "NSE",
"orders": [
{
"ref_id": 1755599,
"order_type": "ORDER_TYPE_REGULAR",
"price_type": "LIMIT",
"order_qty": 75,
"order_price": 24500,
"order_side": "ORDER_SIDE_BUY",
"order_delivery_type": "ORDER_DELIVERY_TYPE_CNC",
"validity_type": "IOC",
"request_type": "ORDER_REQUEST_NEW"
}
]
}
})
print(margin.total_margin)
Request Contract¶
| Field | Type | Required | Meaning |
|---|---|---|---|
with_portfolio |
bool |
yes | whether to include portfolio-aware benefits |
with_legs |
bool |
no | whether to return leg-level margin |
is_basket |
bool |
no | whether to apply basket-level logic |
order_req.exchange |
enum |
yes | exchange |
order_req.orders |
list |
conditional | order legs for the estimate |
order_req.basket_params |
dict |
conditional | basket-level parameters when is_basket=True |
Response Contract¶
| Field | Type | Meaning |
|---|---|---|
total_margin |
int |
final margin requirement |
span |
int |
span component |
exposure |
int |
exposure component |
delivery_margin |
int |
delivery component |
opt_prem |
int |
option premium component |
var |
int |
VAR component |
margin_benefit |
int |
hedge benefit component |
leg_margin |
list[LegMargin] |
per-leg breakdown when requested |
message |
str |
response label |
Important Rules¶
Important Rules
- Use
total_marginas the final required margin value for most decision-making. with_portfolio=Trueis important when the estimate should consider existing portfolio offsets.- Keep order request fields aligned with the real order workflow you plan to submit.
- Use environment-correct
ref_idvalues when estimating margins. - Prices are typically passed in exchange-native integer units such as paise for NSE instruments.