Get Margin¶
get_margin() estimates Trading API V3 funds and margin requirements when NubraTrader is initialized with TradingAPIVersion.V3.
Use this page to estimate funds before placing:
- one single-instrument order
- multiple independent single-instrument orders
- one flexi / multi-leg strategy order
The orders payload uses the same Trading API V3 order fields as create_order(), plus top-level requestType.
LLM guidance
Use this page when the goal is to estimate Trading API V3 funds or margin before placement. Generate the documented field names exactly as shown, including requestType, refId, deliveryType, priceType, validityType, entryPrice, isMultiLeg, unitQty, stratTags, and echoFields.
Basic Usage¶
Create the Trading API V3 order payload you want to estimate, replace the payload dictionary when needed, and pass it to trader.get_margin(payload).
from nubra_python_sdk.refdata.instruments import InstrumentData
from nubra_python_sdk.marketdata.market_data import MarketData
from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
from nubra_python_sdk.trading.trading_data import NubraTrader
from nubra_python_sdk.trading.trading_enum import ExchangeEnum, TradingAPIVersion
nubra = InitNubraSdk(NubraEnv.UAT, env_creds=True)
instruments = InstrumentData(nubra)
market_data = MarketData(nubra)
trader = NubraTrader(nubra, version=TradingAPIVersion.V3)
hdfc_fut = instruments.get_instrument_by_symbol("HDFCBANKFUT26MAY", exchange=ExchangeEnum.NSE)
hdfc_fut_ltp = market_data.quote(ref_id=hdfc_fut.ref_id, levels=1).orderBook.last_traded_price
payload = {
"requestType": "NEW",
"orders": [
{
"refId": hdfc_fut.ref_id,
"qty": hdfc_fut.lot_size,
"side": "BUY",
"deliveryType": "IDAY",
"priceType": "LIMIT",
"validityType": "DAY",
"isMultiLeg": False,
"executionMode": "ENTRY",
"entryPrice": hdfc_fut_ltp,
"stratTags": ["python-sdk-test", "hdfcbank-fut-margin"],
"echoFields": "hdfcbank_fut_margin_example"
}
]
}
funds = trader.get_margin(payload)
print(funds.totalFundsRequired)
print(funds.marginInfo.totalMargin)
Example Margin Patterns¶
These examples estimate Trading API V3 margin for payloads before sending the same shape to create_order().
from nubra_python_sdk.refdata.instruments import InstrumentData
from nubra_python_sdk.marketdata.market_data import MarketData
from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
from nubra_python_sdk.trading.trading_data import NubraTrader
from nubra_python_sdk.trading.trading_enum import ExchangeEnum, TradingAPIVersion
nubra = InitNubraSdk(NubraEnv.UAT, env_creds=True)
instruments = InstrumentData(nubra)
market_data = MarketData(nubra)
trader = NubraTrader(nubra, version=TradingAPIVersion.V3)
hdfc_fut = instruments.get_instrument_by_symbol("HDFCBANKFUT26MAY", exchange=ExchangeEnum.NSE)
hdfc_fut_ltp = market_data.quote(ref_id=hdfc_fut.ref_id, levels=1).orderBook.last_traded_price
funds = trader.get_margin({
"requestType": "NEW",
"orders": [
{
"refId": hdfc_fut.ref_id,
"qty": hdfc_fut.lot_size,
"side": "BUY",
"deliveryType": "IDAY",
"priceType": "LIMIT",
"validityType": "DAY",
"isMultiLeg": False,
"executionMode": "ENTRY",
"entryPrice": hdfc_fut_ltp,
"stratTags": ["python-sdk-test", "hdfcbank-fut-margin"],
"echoFields": "hdfcbank_fut_margin_example"
}
]
})
print(funds.totalFundsRequired)
print(funds.marginInfo.totalMargin)
Use this pattern to estimate margin for a single HDFCBANK futures order.
from datetime import datetime
from nubra_python_sdk.refdata.instruments import InstrumentData
from nubra_python_sdk.marketdata.market_data import MarketData
from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
from nubra_python_sdk.trading.trading_data import NubraTrader
from nubra_python_sdk.trading.trading_enum import TradingAPIVersion
nubra = InitNubraSdk(NubraEnv.UAT, env_creds=True)
instruments = InstrumentData(nubra)
market_data = MarketData(nubra)
trader = NubraTrader(nubra, version=TradingAPIVersion.V3)
def get_ref_id(asset, strike, expiry, option_type):
expiry = datetime.strptime(expiry, "%d-%m-%Y").strftime("%Y%m%d")
result = instruments.get_instruments_by_pattern([{
"exchange": "NSE",
"asset": asset,
"strike_price": str(strike * 100),
"expiry": expiry,
"option_type": option_type,
}])
return result[0].ref_id if result else None
def get_ltp(asset, strike, expiry, option_type):
ref_id = get_ref_id(asset, strike, expiry, option_type)
quote = market_data.quote(ref_id=ref_id, levels=1)
return ref_id, quote.orderBook.last_traded_price
call_ref_id, call_ltp = get_ltp("NIFTY", 24000, "17-03-2026", "CE")
put_ref_id, put_ltp = get_ltp("NIFTY", 24000, "17-03-2026", "PE")
funds = trader.get_margin({
"requestType": "NEW",
"orders": [
{
"isMultiLeg": True,
"qty": 1,
"side": "BUY",
"deliveryType": "CNC",
"priceType": "LIMIT",
"validityType": "DAY",
"executionMode": "ENTRY",
"entryPrice": call_ltp + put_ltp,
"legs": [
{"refId": call_ref_id, "unitQty": 65},
{"refId": put_ref_id, "unitQty": 65}
],
"stratTags": ["python-sdk-test", "long-straddle-margin"],
"echoFields": "long_straddle_margin_example"
}
]
})
print(funds.totalFundsRequired)
print(funds.marginInfo.totalMargin)
Use this pattern to estimate funds for one flexi / multi-leg strategy order. The top-level qty is the strategy multiplier; each leg uses signed unitQty.
from datetime import datetime
from nubra_python_sdk.refdata.instruments import InstrumentData
from nubra_python_sdk.marketdata.market_data import MarketData
from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
from nubra_python_sdk.trading.trading_data import NubraTrader
from nubra_python_sdk.trading.trading_enum import TradingAPIVersion
nubra = InitNubraSdk(NubraEnv.UAT, env_creds=True)
instruments = InstrumentData(nubra)
market_data = MarketData(nubra)
trader = NubraTrader(nubra, version=TradingAPIVersion.V3)
def get_ref_id(asset, strike, expiry, option_type):
expiry = datetime.strptime(expiry, "%d-%m-%Y").strftime("%Y%m%d")
result = instruments.get_instruments_by_pattern([{
"exchange": "NSE",
"asset": asset,
"strike_price": str(strike * 100),
"expiry": expiry,
"option_type": option_type,
}])
return result[0].ref_id if result else None
def get_ltp(asset, strike, expiry, option_type):
ref_id = get_ref_id(asset, strike, expiry, option_type)
quote = market_data.quote(ref_id=ref_id, levels=1)
return ref_id, quote.orderBook.last_traded_price
short_call_ref_id, short_call_ltp = get_ltp("NIFTY", 23800, "17-03-2026", "CE")
long_call_ref_id, long_call_ltp = get_ltp("NIFTY", 24000, "17-03-2026", "CE")
funds = trader.get_margin({
"requestType": "NEW",
"orders": [
{
"isMultiLeg": True,
"qty": 1,
"side": "BUY",
"deliveryType": "CNC",
"priceType": "LIMIT",
"validityType": "DAY",
"executionMode": "ENTRY",
"entryPrice": -short_call_ltp + long_call_ltp,
"legs": [
{"refId": short_call_ref_id, "unitQty": -65},
{"refId": long_call_ref_id, "unitQty": 65}
],
"stratTags": ["python-sdk-test", "bear-call-spread-margin"],
"echoFields": "bear_call_spread_margin_example"
}
]
})
print(funds.totalFundsRequired)
print(funds.marginInfo.totalMargin)
Use this pattern to estimate margin for one bear call spread strategy unit.
Request Contract¶
| Field | Type | Required | Meaning |
|---|---|---|---|
requestType |
str |
yes | request label sent to Trading API V3 funds-required API. Use NEW when estimating funds for a new order before placement. |
orders |
list[IntentOrderStruct] |
yes | order payloads to estimate |
orders[].refId |
int |
conditional | single-leg instrument reference ID |
orders[].qty |
int |
yes | single-order quantity or strategy multiplier |
orders[].side |
str |
conditional | BUY or SELL; required for single-leg orders and recommended for flexi strategies |
orders[].deliveryType |
str |
yes | IDAY or CNC |
orders[].priceType |
str |
no | LIMIT |
orders[].validityType |
str |
no | DAY or GTE |
orders[].executionMode |
str |
no | ENTRY, EXIT, or ENTRY_AND_EXIT |
orders[].entryPrice |
int |
conditional | single-order price or strategy net price |
orders[].entryConfig |
dict |
no | entry trigger or timed-entry conditions |
orders[].exitConfig |
dict |
no | stop-loss, target, trailing, or timed exit conditions |
orders[].icebergInfo |
dict |
no | iceberg fields |
orders[].isMultiLeg |
bool |
yes | False for single-leg estimates; True for flexi / multi-leg estimates |
orders[].legs |
list[dict] |
conditional | required when isMultiLeg=True |
orders[].legs[].refId |
int |
yes for leg | leg instrument reference ID |
orders[].legs[].unitQty |
int |
yes for leg | signed leg quantity |
Condition Fields¶
| Field | Meaning |
|---|---|
entryConfig.entryTime |
timed entry |
entryConfig.triggers[].kind |
ABOVE, BELOW, AT_OR_ABOVE, or AT_OR_BELOW |
entryConfig.triggers[].value |
entry trigger threshold |
exitConfig.stoplossParams.stoplossTriggerPrice.value |
stop-loss trigger |
exitConfig.stoplossParams.stoplossLimitPrice.value |
stop-loss limit |
exitConfig.stoplossParams.stoplossTrailJump |
trailing-stop jump |
exitConfig.targetParams.targetProfitTriggerPrice.value |
target trigger |
exitConfig.targetParams.targetProfitLimitPrice.value |
target limit |
exitConfig.exitTime |
timed exit |
Response Contract¶
get_margin() returns FundsRequiredResp.
| Field | Type | Meaning |
|---|---|---|
code |
int |
funds-required result code |
marginInfo |
IntentMarginResp |
Trading API V3 margin information |
brokerageInfo |
IntentBrokerageResp |
brokerage and charges information |
totalFundsRequired |
int |
final funds required for the request |
willDefaultBePlacedAsAmo |
bool |
whether default placement would become AMO |
refIdAmoMap |
dict[str, bool] |
per-ref-id AMO indicator |
openOrders |
int |
open order count when returned |
icebergInfo |
IntentIcebergParams |
iceberg calculation info when returned |
marginInfo¶
| Field | Type | Meaning |
|---|---|---|
totalMargin |
int |
total margin requirement |
message |
str |
margin message |
maxAllowedQty |
int |
maximum allowed quantity |
cncSellAllowedQty |
int |
CNC sell quantity allowed |
cncSellAvailableQty |
int |
CNC sell quantity available |
edisDoneQty |
int |
EDIS completed quantity |
edisRemainingQty |
int |
EDIS remaining quantity |
brokerageInfo¶
| Field | Type | Meaning |
|---|---|---|
chargesFloat |
dict[str, float] |
individual charge components |
totalChargesFloat |
float |
total charges |
Important Rules¶
Important Rules
- Use the documented Trading API V3 payload fields for
get_margin(). - Set
requestType: "NEW"when estimating a new order before placing it. - Use
totalFundsRequiredas the top-level funds requirement and inspectmarginInfo.totalMarginfor the margin component. - Keep estimate payloads aligned with the order payloads you plan to submit with
create_order(). - Single-leg estimates require
refId,qty,side,deliveryType, andisMultiLeg: False. - Multi-leg estimates require
isMultiLeg: Trueand a non-emptylegslist. - For flexi / multi-leg strategy estimates, top-level
qtyis the strategy multiplier and each leg uses signedunitQty. - Use environment-correct
refIdvalues when estimating margins. - Prices are typically passed in exchange-native integer units such as paise for NSE instruments.