Skip to main content

Order & Report

Basket Margin

Required margin is the amount required to place all the orders in the basket of multiple stocks.

Method: POST

https://connect.thefirstock.com/api/V4/basketMargin

Request details

API Parameters
Parameter Description Example
userId
string
Identifier for the user upon login, unique
to each user in the system.
AA0013
basket
string
Basket list with trading order details { "exchange": "",
"tradingSymbol": "",
"quantity": "",
"transactionType": "",
"price": "",
"product": "",
"priceType": "" }
jKey
string
A unique key obtained upon successful login,
used for session identification and security.
d9b4e1b1c790424

Request details for Data

API Parameters
Parameter Description Example
exchange
String
Exchange on which the order is placed
(e.g., NSE, BSE, NFO, BFO)
NSE
tradingSymbol
String
Encoded trading symbol of the security. SAIL01DEC22P99
quantity
String
The number of units or shares
to be traded in the order.
1
transactionType
String
Indicates whether the transaction
is a Buy (B) or Sell (S).
S
price
String
The specified price at which
the order is to be executed.
260
product
String
Product code indicating the type of trade
C -> Cash and Carry,
M -> F&O Normal,
I -> Intraday
C
priceType
String
Type of pricing for the order
(e.g., LMT, MKT, SL-LMT, SL-MKT)
LMT

Libraries and SDKs

Tabbed Interface
from thefirstock import thefirstock

basketMargin = thefirstock.firstock_BasketMargin(
    userId="{{userId}}",
    basket=[
        {
            "exchange": "NFO",
            "tradingSymbol": "NIFTY16NOV23P19600",
            "quantity": "50",
            "transactionType": "S",
            "price": "0",
            "product": "M",
            "priceType": "LMT"
        },
        {
            "exchange": "NFO",
            "tradingSymbol": "NIFTY16NOV23P19400",
            "quantity": "50",
            "transactionType": "S",
            "price": "0",
            "product": "M",
            "priceType": "LMT"
        },
        {
            "exchange": "NFO",
            "tradingSymbol": "NIFTY16NOV23P20000",
            "quantity": "50",
            "transactionType": "S",
            "price": "0",
            "product": "M",
            "priceType": "LMT"
        }
    ]
)
curl --location --request POST 'https://connect.thefirstock.com/api/V4/basketMargin' \
--header 'Content-Type: application/json' \
--data-raw '{
  "userId": "{{userID}}",
  "jKey": "{{jKey}}",
  "basket": [
                {
                    "exchange": "NSE",
                    "tradingSymbol": "NESTLEIND-EQ",
                    "quantity": "1",
                    "transactionType": "S",
                    "price": "1200",
                    "product": "I",
                    "priceType": "LMT"
                },
                {
                    "exchange": "NSE",
                    "tradingSymbol": "NESTLEIND-EQ",
                    "quantity": "1",
                    "transactionType": "S",
                    "price": "1300",
                    "product": "I",
                    "priceType": "LMT"
                }
        ]    
  
}'
const Firstock = require("thefirstock");

const firstock = new Firstock();

firstock.basketMargin(
  {
    basket: [
      {
          userId: {{userId}},
        exchange: "NSE",
        tradingSymbol: "NESTLEIND-EQ",
        quantity: "1",
        transactionType: "S",
        price: "1200",
        product: "I",
        priceType: "LMT",
      },
      {
          userId: {{userId}},
        exchange: "NSE",
        tradingSymbol: "NESTLEIND-EQ",
        quantity: "1",
        transactionType: "S",
        price: "1300",
        product: "I",
        priceType: "LMT",
      },
    ],
  },
  (err, result) => {
    console.log("Error, ", err);
    console.log("Result: ", result);
  }
);
using thefirstock;

class Progrom
{
    public static void Main()
    {
        Firstock firstock = new Firstock(userId: {{userId}});
        var result = firstock.basketMargin(basket: new List() {

        new basketMarginObject{
        exchange="NSE",
        tradingSymbol="NESTLEIND-EQ",
        quantity="1",
        transactionType="S",
        price="1200",
        product="I",
        priceType="LMT",
            },
        new basketMarginObject{
        exchange= "NSE",
        tradingSymbol= "NESTLEIND-EQ",
        quantity= "1",
        transactionType= "S",
        price= "1300",
        product= "I",
        priceType= "LMT",

        }
        });
    }
}

Success response details

API Parameters
Parameter Description Example
status
String
Indicates the status of the API
operation, typically 'success' for a
successful operation or 'failed' for an
unsuccessful one.
success
data.request_time
String
The exact time when the API
response was generated and sent,
providing a timestamp for the
operation.
18:00:27 16-02-2023
data.remarks
String
Provides additional information or
comments about the API response,
such as reasons for rejection
or other notes.
basketMargin
data.marginused
String
Represents the total margin
amount that has been utilized for
the transaction, indicating the funds
required to hold the position.
19150.45
data.marginusedtrade
String
Shows the margin amount used
after the completion of the trade,
reflecting the updated margin
requirement post-transaction.
22.95
data.stat
String
Indicates the status of order
placement, such as 'ok'
for successful order processing
or an error message if there's
an issue.
ok
{
  "status": "success",
  "data": {
      "request_time": "18:00:27 16-02-2023",
      "stat": "Ok",
      "marginused": "19150.45",
      "marginusedtrade": "22.95",
      "remarks": "basketMargin"
  }
}

Failure response details

API Error Parameters
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_USERID
error.field
String
Field in the request that triggered the error. userid
error.message
String
Detailed message describing the error. userid parameter is invalid
{
  "status": "failed",
  "code": "401",
  "name": "INVALID_USERID",
  "error": {
      "field": "userid",
      "message": "userid parameter is invalid"
  }
}