On this page
Works out the margin for a group of orders at once. This matters because hedged positions need far less margin together than they do apart -- a basket calculation can be dramatically cheaper than the sum of its parts.
https://api.infinn.in/NorenWClientAPI/GetBasketMargin- Method
- POST
- Authentication
- Token required
- Content-Type
- text/plain
- Body
- jData=<json>
- Returns
- JSON object
- Rate limit
- 20 orders/sec, 200/min (account-wide)
What it does
Works out the margin for a group of orders at once. This matters because hedged positions need far less margin together than they do apart -- a basket calculation can be dramatically cheaper than the sum of its parts.
Calculates the combined margin for several orders taken together.
The documented arithmetic is relative to your existing margin usage, which only Limits can tell you. Without it you cannot separate this basket's margin from what you were already using.
Let mu be marginused from Limits. Excluding existing margin: post-trade margin = marginusedtrade − mu and basket margin = marginused − mu. Including existing margin: post-trade margin = marginusedtrade and basket margin = marginused.
Counter-intuitively, you do not put all the orders in basketlists. The first order's fields go directly in jData, and basketlists carries the rest.
Request
Send a POST with the header Content-Type: text/plain. The body is a single form field, jData, whose value is a JSON string. Include Authorization: Bearer <access_token>. See how requests are shaped if that sounds unfamiliar.
Headers
| Header | Type | Description |
|---|---|---|
| Authorization | string |
|
| Content-Type | string |
|
jData fields
| Field | Type | Description |
|---|---|---|
| uid | string | User ID of the logged-in user. Your Infinn login ID - the same one you type at trade.infinn.in. Example IN001Where to get itThe ID you log in with at trade.infinn.in. Also returned as uid by GenAcsTok. |
| actid | string | Account ID of the logged-in user. Your trading account number. For an individual account this is the same as your user ID. Example IN001Where to get itReturned as actid by GenAcsTok and UserDetails. Same as the user ID for individual accounts. |
| exch | string | Exchange segment. Choose from the exarr array returned by UserDetails. Which exchange the instrument trades on. Example NSEWhere to get itThe exarr array in the UserDetails response lists the exchanges enabled on your account. NSENFOBSEBFOCDSMCXNCXNSE = National Stock Exchange - cash / equity; NFO = NSE equity derivatives (futures & options); BSE = Bombay Stock Exchange - cash / equity; BFO = BSE equity derivatives; CDS = NSE currency derivatives; MCX = Multi Commodity Exchange; NCX = NSE commodity |
| tsym | string | Trading symbol: the unique identifier of the contract. URL-encode it to avoid errors with symbols that contain special characters, such as M&M. The exact ticker for the thing you are trading. Example RELIANCE-EQWhere to get itThe TradingSymbol column of the symbol master file, or the tsym field of a SearchScrip response. |
| qty | string (integer) | Order quantity. How many you want to trade. Example 1Where to get itA plain unit count for equities. For futures and options it must be a multiple of the contract's lot size, which the symbol master's LotSize column gives you. |
| prc | string (decimal) | Order price. Send "0" when prctyp is MKT or SL-MKT. The price you are willing to pay or accept. Market orders ignore this, so send 0. Example 1000Where to get itYour chosen limit price. Must be a multiple of the instrument's tick size (the TickSize column in the symbol master). |
| trgprc | string (decimal) | Trigger price. Send only for SL-LMT and SL-MKT orders. The price that wakes a stop-loss order up. Example 995Where to get itYour chosen trigger level. Only meaningful for the two SL price types. |
| prd | string | Product type. Choose from the prarr array returned by UserDetails, and check it is permitted for the chosen exchange. How the position should be treated: squared off today, held overnight, or delivered into your demat account. Example CWhere to get itThe prarr array in the UserDetails response. Show the user s_prdt_ali (the display name) and send prd. CIMHBSPC = Delivery - shares settle into your demat account (CNC); I = Intraday - must be squared off the same day (MIS); M = Margin - carry-forward derivatives position (NRML); H = Cover order - entry plus a compulsory stop-loss; B = Bracket order - entry plus a stop-loss and a target; S = Special; P = Special2 |
| trantype | string | Transaction type. Whether you are buying or selling. Example BBSB = Buy; S = Sell |
| prctyp | string | Price type (order type). How the order should be priced - at your price, at whatever the market offers, or only once a trigger is hit. Example LMTWhere to get itThe orarr array in the UserDetails response lists the price types enabled on your account. LMTMKTSL-LMTSL-MKTLMT = Limit - fills at your price or better; MKT = Market - fills immediately at whatever the market offers; SL-LMT = Stop-loss limit - becomes a limit order once trgprc is hit; SL-MKT = Stop-loss market - becomes a market order once trgprc is hit |
| blprc | string (decimal) | Book-loss price. Applies only when prd is H (cover) or B (bracket). The stop-loss price for a cover or bracket order. |
| rorgqty | string | Open order quantity. Only for a modify-order calculation. |
| fillshares | string | Quantity already filled. Only for a modify-order calculation. |
| rorgprc | string | Open order price. Only for a modify-order calculation. |
| orgtrgprc | string | Open order trigger price. Only for a modify-order calculation. |
| norenordno | string | Order number. Only for modifying an H or B order. The order's receipt number. You get it back when you place an order, and you need it to change or cancel that order later. Example 24010100000001Where to get itThe norenordno field of the PlaceOrder response, or any row in the OrderBook. |
| snonum | string | Sequence number. Only for modifying an H or B order. |
| basketlists | object[] | The remaining orders in the basket, as an array of JSON objects. The fields sent at the top level count as the first order. The other orders in the basket. |
Request and response together
The same call, shown as raw HTTP on the left and the documented response on the right.
POST /NorenWClientAPI/GetBasketMargin HTTP/1.1
Host: api.infinn.in
Authorization: Bearer YOUR_ACCESS_TOKEN
Content-Type: text/plain
jData={"uid":"IN001","actid":"IN001","exch":"NSE","tsym":"RELIANCE-EQ","qty":"1","prc":"1000","prd":"C","trantype":"B","prctyp":"LMT"}Code examples
Each sample is a complete, runnable program. Replace YOUR_ACCESS_TOKEN and the placeholder field values, and it will run as-is. Every one checks both error layers.
curl --request POST \
--url 'https://api.infinn.in/NorenWClientAPI/GetBasketMargin' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--header 'Content-Type: text/plain' \
--data 'jData={"uid":"IN001","actid":"IN001","exch":"NSE","tsym":"RELIANCE-EQ","qty":"1","prc":"1000","prd":"C","trantype":"B","prctyp":"LMT"}'"""Basket Margin
Requires: pip install requests
"""
import json
import requests
ACCESS_TOKEN = "YOUR_ACCESS_TOKEN"
URL = "https://api.infinn.in/NorenWClientAPI/GetBasketMargin"
payload = {
"uid": "IN001",
"actid": "IN001",
"exch": "NSE",
"tsym": "RELIANCE-EQ",
"qty": "1",
"prc": "1000",
"prd": "C",
"trantype": "B",
"prctyp": "LMT"
}
response = requests.post(
URL,
headers={
"Authorization": f"Bearer {ACCESS_TOKEN}",
"Content-Type": "text/plain",
},
# The body is a form field named jData whose value is a JSON string.
data="jData=" + json.dumps(payload),
timeout=10,
)
# Layer 1: transport. A rejected token or an unregistered IP gives a
# an error with an EMPTY body, so calling .json() first would raise a
# decode error that hides the real cause.
if response.status_code != 200:
raise SystemExit(
f"HTTP {response.status_code}. "
"If 403: check the token, and that this machine's public IP "
"is the one registered on your Infinn profile."
)
data = response.json()
# Layer 2: HTTP 200 does not mean success. Always check stat.
if data.get("stat") != "Ok":
raise RuntimeError(data.get("emsg", "request failed"))
print(json.dumps(data, indent=2))// Basket Margin
// Runs on Node 18+ (global fetch) and in the browser.
const ACCESS_TOKEN = 'YOUR_ACCESS_TOKEN';
const URL = 'https://api.infinn.in/NorenWClientAPI/GetBasketMargin';
const payload = {
"uid": "IN001",
"actid": "IN001",
"exch": "NSE",
"tsym": "RELIANCE-EQ",
"qty": "1",
"prc": "1000",
"prd": "C",
"trantype": "B",
"prctyp": "LMT"
};
async function main() {
const response = await fetch(URL, {
method: 'POST',
headers: {
Authorization: `Bearer ${ACCESS_TOKEN}`,
'Content-Type': 'text/plain',
},
// jData is a form field; its value is a JSON string.
body: 'jData=' + JSON.stringify(payload),
});
// Layer 1: transport. A rejected token or an unregistered IP
// gives an error with an EMPTY body, so parsing first would throw a
// misleading JSON error instead.
if (!response.ok) {
throw new Error(
`HTTP ${response.status}. If 403: check the token, and that `
+ `this machine's public IP is registered on your profile.`,
);
}
const data = await response.json();
// Layer 2: HTTP 200 does not mean success.
if (data.stat !== 'Ok') throw new Error(data.emsg || 'request failed');
console.log(JSON.stringify(data, null, 2));
}
main().catch((err) => console.error('Request failed:', err.message));// Basket Margin
// .NET 6 or later.
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
const string AccessToken = "YOUR_ACCESS_TOKEN";
const string Url = "https://api.infinn.in/NorenWClientAPI/GetBasketMargin";
static async Task Main()
{
var payload = new Dictionary<string, string>
{
["uid"] = "IN001",
["actid"] = "IN001",
["exch"] = "NSE",
["tsym"] = "RELIANCE-EQ",
["qty"] = "1",
["prc"] = "1000",
["prd"] = "C",
["trantype"] = "B",
["prctyp"] = "LMT"
};
var body = "jData=" + JsonSerializer.Serialize(payload);
using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, Url);
request.Headers.TryAddWithoutValidation(
"Authorization", "Bearer " + AccessToken);
request.Content = new StringContent(body, Encoding.UTF8, "text/plain");
using var response = await client.SendAsync(request);
var text = await response.Content.ReadAsStringAsync();
// Layer 1: an error arrives with an empty body.
if (!response.IsSuccessStatusCode)
{
throw new Exception($"HTTP {(int)response.StatusCode}");
}
// Layer 2: inspect stat / emsg in the payload.
Console.WriteLine(text);
}
}// Basket Margin
// Java 11 or later -- java.net.http is in the JDK, no dependencies.
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class InfinnExample {
private static final String ACCESS_TOKEN = "YOUR_ACCESS_TOKEN";
private static final String URL = "https://api.infinn.in/NorenWClientAPI/GetBasketMargin";
public static void main(String[] args) throws Exception {
String body = "jData={\"uid\":\"IN001\",\"actid\":\"IN001\",\"exch\":\"NSE\",\"tsym\":\"RELIANCE-EQ\",\"qty\":\"1\",\"prc\":\"1000\",\"prd\":\"C\",\"trantype\":\"B\",\"prctyp\":\"LMT\"}";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(URL))
.header("Authorization", "Bearer " + ACCESS_TOKEN)
.header("Content-Type", "text/plain")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
// Layer 1: transport status. error responses have an empty body.
if (response.statusCode() != 200) {
throw new RuntimeException("HTTP " + response.statusCode());
}
// Layer 2: check stat / emsg in the JSON payload.
System.out.println(response.body());
}
}<?php
// Basket Margin
// PHP 7.4 or later, with the cURL extension.
$accessToken = 'YOUR_ACCESS_TOKEN';
$url = 'https://api.infinn.in/NorenWClientAPI/GetBasketMargin';
$payload = [
'uid' => 'IN001',
'actid' => 'IN001',
'exch' => 'NSE',
'tsym' => 'RELIANCE-EQ',
'qty' => '1',
'prc' => '1000',
'prd' => 'C',
'trantype' => 'B',
'prctyp' => 'LMT',
];
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $accessToken,
'Content-Type: text/plain',
],
// jData is a form field whose value is a JSON string.
CURLOPT_POSTFIELDS => 'jData=' . json_encode($payload),
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Layer 1: transport. Error responses have an empty body.
if ($status !== 200) {
throw new RuntimeException("HTTP {$status}");
}
// Layer 2: inspect stat / emsg.
$data = json_decode($body, true);
print_r($data);Response
On success the body is a JSON object. Infinn omits fields rather than returning null, so check that a field is present before reading it.
| Field | Type | Description |
|---|---|---|
| stat | string | Ok on success, Not_Ok on failure. Always check this before reading anything else. Did it work? Ok means yes, Not_Ok means no. |
| request_time | string | The time Infinn processed the request, formatted HH:MM:SS dd-mm-yyyy. PresencePresent on success. |
| remarks | string | Rejection reason, when there is one. |
| marginused | string | Total margin used. |
| marginusedtrade | string | Margin used after the trade. |
| emsg | string | Human-readable reason for the failure. If something went wrong, this says what. PresencePresent only when stat is Not_Ok. |
basketlists object
Each entry is one further order in the basket.
| Field | Type | Description |
|---|---|---|
| exch | string | Exchange. Required. |
| tsym | string | Trading symbol. Required. |
| qty | string | Order quantity. Required. |
| prc | string | Order price. Required. |
| trgprc | string | Trigger price, for SL orders. |
| prd | string | Product. Required. |
| trantype | string | B or S. Required. |
| prctyp | string | Price type. Required. |
Errors
This endpoint can fail at either layer. A transport failure returns a 4xx or 5xx with an empty body; an application failure returns 200 with stat: "Not_Ok" and an emsg.