Skip to content

Basket Orders

Basket APIs

The Basket Order APIs let you create, fetch, update and delete existing baskets.

method path description
POST https://api.mstock.trade/openapi/typea/CreateBasket Create new basket
PUT https://api.mstock.trade/openapi/typea/FetchBasket Fetch all basket
DELETE https://api.mstock.trade/openapi/typea/RenameBasket Rename existing basket
POST https://api.mstock.trade/openapi/typea/DeleteBasket Delete existing basket
GET https://api.mstock.trade/openapi/typea/CalculateBasket Calculate Basket

Create Basket

This endpoint allows users to create new basket. Users must provide relevant basket details such as basket name and description of basket.

Request Headers -

  • X-Mirae-Version: Specifies the version of the API being used. In this case, it is set to 1.
  • Authorization: A token-based authentication header. The format is token api_key:access_token
  • Content-Type: For this request, it is set to application/x-www-form-urlencoded, which is used for submiting form data.
curl --location 'https://api.mstock.trade/openapi/typea/CreateBasket' \
    --header 'X-Mirae-Version: 1' \
    --header ''Authorization: token api_key:access_token \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'BaskName=BasketTest-1' \
    --data-urlencode 'BaskDesc=Basket Description'
import axios from 'axios';

const response = await axios.post(
'https://api.mstock.trade/openapi/typea/CreateBasket',
new URLSearchParams({
    'BaskName': 'BasketTest-1',
    'BaskDesc': 'Basket Description'
}),
{
    headers: {
    'X-Mirae-Version': '1',
    'Authorization': 'token api_key:access_token'
    }
}
);
import requests

headers = {
    'X-Mirae-Version': '1',
    'Authorization': 'token api_key:access_token',
    'Content-Type': 'application/x-www-form-urlencoded',
}

data = {
    'BaskName': 'BasketTest-1',
    'BaskDesc': 'Basket Description'
}

response = requests.post('https://api.mstock.trade/openapi/typea/CreateBasket', headers=headers, data=data)
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newBuilder()
    .followRedirects(HttpClient.Redirect.NORMAL)
    .build();

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.mstock.trade/openapi/typea/CreateBasket"))
    .POST(BodyPublishers.ofString("BaskName=BasketTest-1&BaskDesc=Basket Description"))
    .setHeader("X-Mirae-Version", "1")
    .setHeader("Authorization", "token api_key:access_token")
    .setHeader("Content-Type", "application/x-www-form-urlencoded")
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

Request Body - The body of the request must be URL-encoded and include the following parameters:

Field Type Description
BaskName string Name of the basket
BaskDesc string Descrition of the basket

Response Structure -

The response of the request will be based on authentication outcome.

  • Success (HTTP Status 200): On successful basket creation, the server returns a JSON object as shown below
{
    "status": "success",
    "data": "Basket Created Successfully"
}
  • Failure (HTTP Status 401): If the order fails due to invalid parameters, authentication issues, or other errors, the server will return an error message with below json format.
{
    "status": "error",
    "message": "Invalid request. Please try again.",
    "error_type": "TokenException",
    "data": null
}
  • Failure (HTTP Status 200): If basket is already exists then api will return an error message with below json format.
{
    "status": "error",
    "message": "Basket Already Added For This Name",
    "error_type": "MiraeException",
    "data": null
}
  • Failure (HTTP Status 400): If the API Key is Invalid or expired.
{
    "status": "error",
    "message": "API is suspended/expired for use. Please check your API subscription and try again.",
    "error_type": "APIKeyException",
    "data": null
}

Fetch Basket

This endpoint allows users to create new basket. Users must provide relevant basket details such as basket name and description of basket.

Request Headers -

  • X-Mirae-Version: Specifies the version of the API being used. In this case, it is set to 1.
  • Authorization: A token-based authentication header. The format is token api_key:access_token
  • Content-Type: For this request, it is set to application/x-www-form-urlencoded, which is used for submiting form data.
curl --location 'https://api.mstock.trade/openapi/typea/FetchBasket' \
    --header 'X-Mirae-Version: 1' \
    --header 'Authorization: token api_key:access_token'
import axios from 'axios';

const response = await axios.get('https://api.mstock.trade/openapi/typea/FetchBasket', {
headers: {
    'X-Mirae-Version': '1',
    'Authorization': 'token api_key:access_token'
}
});
import requests

headers = {
    'X-Mirae-Version': '1',
    'Authorization': 'token api_key:access_token',
}

response = requests.get('https://api.mstock.trade/openapi/typea/FetchBasket', headers=headers)
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newBuilder()
    .followRedirects(HttpClient.Redirect.NORMAL)
    .build();

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.mstock.trade/openapi/typea/FetchBasket"))
    .GET()
    .setHeader("X-Mirae-Version", "1")
    .setHeader("Authorization", "token api_key:access_token")
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

Request Body - This endpoint does not require a request body or additional parameters in the query string for the retrieval of orders.

Response Structure -

The response of the request will be based on authentication outcome.

  • Success (HTTP Status 200): On successful basket fetch, the server returns a JSON object as shown below
{
    "status": "success",
    "data": [
        {
            "BASKET_ID": 215,
            "BASKET_NAME": "ABC Update",
            "COUNT": 4,
            "CREATE_DATE": "2024-11-19T05:40:07Z",
            "DESCRIPTOR": ""
        },
        {
            "BASKET_ID": 209,
            "BASKET_NAME": "BANKEX",
            "COUNT": 1,
            "CREATE_DATE": "2024-11-13T06:42:37Z",
            "DESCRIPTOR": ""
        }
    ]
}
  • Failure (HTTP Status 401): If the order fails due to invalid parameters, authentication issues, or other errors, the server will return an error message with below json format.

{
    "status": "error",
    "message": "Invalid request. Please try again.",
    "error_type": "TokenException",
    "data": null
}
- Failure (HTTP Status 400): If the API Key is Invalid or expired.

{
    "status": "error",
    "message": "API is suspended/expired for use. Please check your API subscription and try again.",
    "error_type": "APIKeyException",
    "data": null
}

Rename Basket

This endpoint allows users to rename an existing baslet by specifying the new basket name and existing basket ID.

Request Headers -

  • X-Mirae-Version: Specifies the version of the API being used. In this case, it is set to 1.
  • Authorization: A token-based authentication header. The format is token api_key:access_token.
  • Content-Type: Indicated the media type of the resource. For this request, it is set to application/x-www-form-urlencoded, which is used for submiting form data.
curl --location --request PUT 'https://api.mstock.trade/openapi/typea/RenameBasket' \
--header 'X-Mirae-Version: 1' \
--header 'Authorization: token api_key:access_token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'basketName=New Basket Name Updated' \
--data-urlencode 'BasketId=255'
import axios from 'axios';

const response = await axios.post(
'https://api.mstock.trade/openapi/typea/RenameBasket',
new URLSearchParams({
    'basketName': 'New Basket Name Updated',
    'BasketId': '255'
}),
{
    headers: {
    'X-Mirae-Version': '1',
    'Authorization': 'token api_key:access_token
    }
}
);
import requests

headers = {
    'X-Mirae-Version': '1',
    'Authorization: token api_key:access_token',
    'Content-Type': 'application/x-www-form-urlencoded',
}

data = {
    'basketName': 'New Basket Name Updated',
    'BasketId': '255'
}

response = requests.post('https://api.mstock.trade/openapi/typea/RenameBasket', headers=headers, data=data)
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newBuilder()
    .followRedirects(HttpClient.Redirect.NORMAL)
    .build();

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.mstock.trade/openapi/typea/RenameBasket"))
    .PUT(BodyPublishers.ofString("basketName=New Basket Name Updated&BasketId=255"))
    .setHeader("X-Mirae-Version", "1")
    .setHeader("Authorization", "token api_key:access_token")
    .setHeader("Content-Type", "application/x-www-form-urlencoded")
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

Request Body - The body of the request must be URL-encoded and include the following parameters:

Field Type Description
basketName string New name for the basket
BasketId string The unique identifier of the basket to be renamed

Request Response -

The response of the request will be based on authentication outcome.

  • Success (HTTP Status 200): On successful rename of basket, the server returns a JSON object containing the status.
{
    "status": "success",
    "data": null
}
  • Failure (HTTP Status 401): If the order fails due to invalid parameters, authentication issues, or other errors, the server will return an error message with below json format.
{
    "status": "error",
    "message": "Invalid request. Please try again.",
    "error_type": "TokenException",
    "data": null
}
  • Failure (HTTP Status 200): If basket name is already exists then server will return below json reponse.

{
    "status": "error",
    "message": "Invalid request. Please check and try again.",
    "error_type": "MiraeException",
    "data": null
}
- Failure (HTTP Status 400): If the API Key is Invalid or expired.

{
    "status": "error",
    "message": "API is suspended/expired for use. Please check your API subscription and try again.",
    "error_type": "APIKeyException",
    "data": null
}

Delete Basket

This endpoint allows users to delete an existing basket by specifying the basket ID.

Request Headers -

  • X-Mirae-Version: Specifies the version of the API being used. In this case, it is set to 1.
  • Authorization: A token-based authentication header. The format is token api_key:access_token.
  • Content-Type: Indicated the media type of the resource. For this request, it is set to application/x-www-form-urlencoded, which is used for submiting form data.
curl --location --request DELETE 'https://api.mstock.trade/openapi/typea/DeleteBasket' \
    --header 'X-Mirae-Version: 1' \
    --header 'Authorization: token api_key:access_token'
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'BasketId=255'
import axios from 'axios';

const response = await axios.delete('https://api.mstock.trade/openapi/typea/DeleteBasket', {
    new URLSearchParams({
    'BasketId': '255'
}),
headers: {
    'X-Mirae-Version': '1',
    'Authorization': 'token api_key:access_token',
    'Content-Type': 'application/x-www-form-urlencoded'
}
});
import requests

headers = {
    'X-Mirae-Version': '1',
    'Authorization': 'token api_key:access_token',
}

data = {
    'BasketId': '255'
}

response = requests.delete('https://api.mstock.trade/openapi/typea/DeleteBasket', headers=headers, data=data)
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newBuilder()
    .followRedirects(HttpClient.Redirect.NORMAL)
    .build();

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.mstock.trade/openapi/typea/DeleteBasket"))
    .DELETE(BodyPublishers.ofString("BasketIds=255"))
    .setHeader("X-Mirae-Version", "1")
    .setHeader("Authorization", "token api_key:access_token")
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

Path Parameter -

Field Description
BasketId The unique identifier of the basket to be deleted.

Response Structure -

The response of the request will be based on authentication outcome.

  • Success (HTTP Status 200): On successful order deletion, the server returns a JSON object containing the order ID and status.
{
    "status": "success",
    "data": "Basket Deleted Successfully"
}
  • Failure (HTTP Status 401): If the order fails due to invalid parameters, authentication issues, or other errors, the server will return an error message with below json format.
{
    "status": "error",
    "message": "Invalid request. Please try again.",
    "error_type": "TokenException",
    "data": null
}
  • Failure (HTTP Status 400): If the API Key is Invalid or expired.
{
    "status": "error",
    "message": "API is suspended/expired for use. Please check your API subscription and try again.",
    "error_type": "APIKeyException",
    "data": null
}

Calculate Basket

This endpoint allows users to calculate the basket. Users must provide relevant such as basket id, product, segment, script code, basekt name, etc.

Request Headers -

  • X-Mirae-Version: Specifies the version of the API being used. In this case, it is set to 1.
  • Authorization: A token-based authentication header. The format is token api_key:access_token
  • Content-Type: For this request, it is set to application/x-www-form-urlencoded, which is used for submiting form data.
curl --location 'https://api.mstock.trade/openapi/typea/CalculateBasket' \
    --header 'X-Mirae-Version: 1' \
    --header ''Authorization: token api_key:access_token \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'include_exist_pos=0' \
    --data-urlencode 'ord_product=C' \
    --data-urlencode 'disc_qty=0' \
    --data-urlencode 'segment=E' \
    --data-urlencode 'trigger_price=0' \
    --data-urlencode 'scriptcode=11915' \
    --data-urlencode 'ord_type=LMT' \
    --data-urlencode 'basket_name=ZRDTest_New' \
    --data-urlencode 'operation=I' \
    --data-urlencode 'order_validity=DAY' \
    --data-urlencode 'order_qty=1' \
    --data-urlencode 'script_stat=A' \
    --data-urlencode 'buy_sell_indi=B' \
    --data-urlencode 'basket_priority=1' \
    --data-urlencode 'order_price=19.02' \
    --data-urlencode 'basket_id=251' \
    --data-urlencode 'exch_id=NSE'
import axios from 'axios';

const response = await axios.post(
'https://api.mstock.trade/openapi/typea/CalculateBasket',
new URLSearchParams({
    'include_exist_pos': '0',
    'ord_product': 'C',
    'disc_qty': '0',
    'segment': 'E',
    'trigger_price': '0',
    'scriptcode': '11915',
    'ord_type': 'LMT',
    'basket_name': 'ZRDTest_New',
    'operation': 'I',
    'order_validity': 'DAY',
    'order_qty': '1',
    'script_stat': 'A',
    'buy_sell_indi': 'B',
    'basket_priority': '1',
    'order_price': '19.02',
    'basket_id': '251',
    'exch_id': 'NSE'
}),
{
    headers: {
    'X-Mirae-Version': '1',
    'Authorization': 'token api_key:access_token',
    'Content-Type': 'application/x-www-form-urlencoded'
    }
}
);
import requests

headers = {
    'X-Mirae-Version': '1',
    'Authorization': 'token api_key:access_token',
    'Content-Type': 'application/x-www-form-urlencoded',
}

data = {
    'include_exist_pos': '0',
    'ord_product': 'C',
    'disc_qty': '0',
    'segment': 'E',
    'trigger_price': '0',
    'scriptcode': '11915',
    'ord_type': 'LMT',
    'basket_name': 'ZRDTest_New',
    'operation': 'I',
    'order_validity': 'DAY',
    'order_qty': '1',
    'script_stat': 'A',
    'buy_sell_indi': 'B',
    'basket_priority': '1',
    'order_price': '19.02',
    'basket_id': '251',
    'exch_id': 'NSE'
}

response = requests.post('https://api.mstock.trade/openapi/typea/CalculateBasket', headers=headers, data=data)
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newBuilder()
    .followRedirects(HttpClient.Redirect.NORMAL)
    .build();

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.mstock.trade/openapi/typea/CalculateBasket"))
    .POST(BodyPublishers.ofString("include_exist_pos=0&ord_product=C&disc_qty=0&segment=E&trigger_price=0&scriptcode=11915&ord_type=LMT&basket_name=Test%20Basket%20Updated%20Renamed&operation=I&order_validity=DAY&order_qty=1&script_stat=A&buy_sell_indi=B&basket_priority=1&order_price=19.02&basket_id=269&exch_id=NSE"))
    .setHeader("X-Mirae-Version", "1")
    .setHeader("Authorization", "token api_key:access_token")
    .setHeader("Content-Type", "application/x-www-form-urlencoded")
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

Request Body - The body of the request must be URL-encoded and include the following parameters:

Field Type Description
include_exist_pos string whether to include existing position or not (0)
ord_product string Product type (C)
disc_qty string Disclosed Quantity (0)
segment string Segment (E-Equity)
trigger_price string Trigger Price
scriptcode string Script Code of underlying
ord_type string Order Type (LMT-LIMIT and MKT-MARKET)
basket_name string Basket Name
operation string Operation Type (I-Insert, E-Modify, G-Get)
order_validity string Validaty or duration of order (DAY)
order_qty string Quantity of order
script_stat string Script Stat (A)
buy_sell_indi string Transaction Type (B-BUY and S-SELL)
basket_priority string Basket Priority (1)
order_price string Order Price
basket_id string Basket ID
exch_id string Exchange (NSE and BSE)

Response Structure -

The response of the request will be based on authentication outcome.

  • Success (HTTP Status 200): On successful API call, the server returns a JSON object as shown below
{
    "status": "success",
    "data": {
        "TOTAL_FINAL_MARGIN": 19.02,
        "TOTAL_REQ_MARGIN": 19.02,
        "BASKET_DETAILS": [
            {
                "BASKET_ID": "269",
                "BASKET_NAME": "Test Basket Updated Renamed",
                "BASKET_PRIORITY": 1,
                "BROKERAGE": 0,
                "BUY_SELL_IND": "B",
                "EQ_VARELM_MARGIN": 19.02,
                "EXCH_ID": "NSE",
                "OPT_BUY_PREM": 0,
                "ORD_DISC_QTY": 0,
                "ORD_PRICE": 19.02,
                "ORD_QTY": 1,
                "ORD_SYMBOL": "YESBANK",
                "ORD_SYM_NAME": "YESBANK",
                "ORD_TRIGG_PRICE": 0,
                "ORD_TYPE": "LMT",
                "ORD_VALIDITY": "DAY",
                "PRODUCT": "C",
                "REQ_EXP": 0,
                "REQ_MARGIN": 19.02,
                "REQ_SPAN": 0,
                "SCRIPT_CODE": "11915",
                "SCRIPT_STATUS": "A",
                "SEGMENT": "E"
            }
        ]
    }
}
  • Failure (HTTP Status 401): If the API request fails due to invalid parameters, authentication issues, or other errors, the server will return an error message with below json format.
{
    "status": "error",
    "message": "Invalid request. Please try again.",
    "error_type": "TokenException",
    "data": null
}
  • Failure (HTTP Status 200): If basket calculation is already done then below response will be done.
{
    "status": "error",
    "message": "Script Already Added",
    "error_type": "MiraeException",
    "data": null
}
  • Failure (HTTP Status 400): If the API Key is Invalid or expired.
{
    "status": "error",
    "message": "API is suspended/expired for use. Please check your API subscription and try again.",
    "error_type": "APIKeyException",
    "data": null
}