Span Calculator
The Span Calculator API provides you with the capability to determine the margin requirement for your portfolio prior to executing any trades.
Method: POST
https://connect.thefirstock.com/api/V4/spanCalculators
Request details
Parameter | Description | Example |
---|---|---|
userId string |
Identifier for the user upon login, unique to each user in the system. | AA1999 |
exchange string |
Exchange on which the order is placed (e.g., NSE, BSE, NFO, BFO) | NFO |
instname string |
Instrument type (e.g., FUTSTK, FUTIDX, OPTSTK, OPTIDX) |
OPTIDX |
symbolName string |
Symbol Name (e.g., ACC, ABB, NIFTY, BANKNIFTY) |
BANKNIFTY |
expireDate string |
Expiration Date in DD-MMM-YY format |
21-DEC-2023 |
optionType string |
Option type (CE, PE) | CE |
strikePrice string |
Strike price | 21500 |
netQuantity string |
Net traded quantity | 1700 |
jKey string |
Authentication token obtained from the login API | d4180daa72ea70885 |
Libraries and SDKs
from thefirstock import thefirstock
spanCalculator = thefirstock.firstock_SpanCalculator(
dataList=[
{
"exchange": "NFO",
"symbolName": "NIFTY",
"expireDate": "21-DEC-2023",
"instrumentName": "OPTIDX",
"optionType": "CE",
"strikePrice": "21500",
"netQuantity": "50"
}
],
userId="{{userId}}"
)
curl --location --request POST 'https://connect.thefirstock.com/api/V4/spanCalculators' \
--header 'User-Agent: Apidog/1.0.0 (https://apidog.com)' \
--header 'Content-Type: application/json' \
--data-raw '{
"userId": "{{userID}}",
"jKey": "{{jKey}}",
"data": [
{
"exchange": "NFO",
"symbolName": "NIFTY",
"expireDate": "21-DEC-2023",
"instrumentName": "OPTIDX",
"optionType": "CE",
"strikePrice": "21500",
"netQuantity": "50"
}
]
}'
const Firstock = require("thefirstock");
const firstock = new Firstock();
firstock.spanCalculator(
[
{
userId: {{userId}},
exchange: "NFO",
instrumentName: "",
symbolName: "NIFTY",
expireDate: "23-FEB-2023",
optionType: "CE",
strikePrice: "17000",
netQuantity: "50",
},
{
exchange: "NFO",
instrumentName: "",
symbolName: "BANKNIFTY",
expireDate: "23-FEB-2023",
optionType: "PE",
strikePrice: "40000",
netQuantity: "-25",
},
],
(err, result) => {
console.log("Error, ", err);
console.log("Result: ", result);
}
);
using thefirstock;
class Program
{
public static void Main()
{
Firstock firstock = new Firstock();
var result = firstock.spanCalculator(userId: {{userId}},list: new List() {
new spanCalculatorObject{
exchange="NFO",
instrumentName="OPTIDX",
symbolName="NIFTY",
expireDate="02-MAR-2023",
optionType="CE",
strikePrice="17000",
netQuantity="50"
}
}
);
}
}
Success response details
Parameter | Description | Example |
---|---|---|
status string |
Status of the API request indicating success |
success |
data.status string |
Specific status of the response, indicating 'Ok' |
ok |
data.requestTime string |
Time at which the response was received |
17:38:33 17-02-2023 |
data.span string |
Span margin value | 83866.00 |
data.expo string |
Exposure margin value | 17954.10 |
data.span_trade string |
Span margin after trade | 83866.00 |
data.expo_trade String |
Exposure margin after trade | 17954.10 |
{
"status": "success",
"data": {
"marginList": [
{
"requestTime": "17:38:33 17-02-2023",
"span": "83866.00",
"expo": "17954.10",
"span_trade": "83866.00",
"expo_trade": "17954.10"
},
{
"requestTime": "17:38:34 17-02-2023",
"span": "115909.00",
"expo": "20602.53",
"span_trade": "115909.00",
"expo_trade": "20602.53"
}
],
"totalValue": {
"requestTime": "17:38:34 17-02-2023",
"span": "199775.00",
"expo": "38556.62",
"span_trade": "199775.00",
"expo_trade": "38556.62"
}
}
}
Failure response details
Parameter | Description | Example |
---|---|---|
status String |
Indicates the result status of the API operation | failed |
code String |
HTTP status code associated with the error | 401 |
name String |
Specifies the type or category of the error encountered | INVALID_JKEY |
error.field String |
Field in the request that triggered the error | jkey |
error.message String |
Detailed message describing the error | jKey parameter is invalid |
{
"status": "failed",
"code": "401",
"name": "SESSION_EXPIRED",
"error": {
"field": "jKey",
"message": "Session key has been expired, please login in again"
}
}