Net Position
Net Position APIs
| method | path | description | 
|---|---|---|
| GET | https://api.mstock.trade/openapi/typea/portfolio/positions | view all their existing orders | 
| POST | https://api.mstock.trade/openapi/typea/portfolio/convertposition | Convert position | 
Net Position
This endpoint allows users to retrieve a list of their trading orders. Users can view all their existing orders
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. 
curl --location 'https://api.mstock.trade/openapi/typea/portfolio/positions' \
    --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/portfolio/positions', {
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/portfolio/positions', 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/portfolio/positions"))
    .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 retrieval, the server returns a JSON array of client positions.
{
    "status": "success",
    "data": {
        "net": [
            {
                "tradingsymbol": "YESBANK",
                "exchange": "NSE",
                "instrument_token": 11915,
                "product": "",
                "quantity": 100,
                "overnight_quantity": 0,
                "multiplier": 1,
                "average_price": 19.05,
                "close_price": 27.65,
                "last_price": 27.65,
                "value": 1905,
                "pnl": 0,
                "m2m": 860,
                "unrealised": 0,
                "realised": 0,
                "buy_quantity": 100,
                "buy_price": 19.05,
                "buy_value": 1905,
                "buy_m2m": 0,
                "sell_quantity": 0,
                "sell_price": 0,
                "sell_value": 0,
                "sell_m2m": 0,
                "day_buy_quantity": 100,
                "day_buy_price": 19.05,
                "day_buy_value": 1905,
                "day_sell_quantity": 0,
                "day_sell_price": 0,
                "day_sell_value": 0
            },
            {
                "tradingsymbol": "IDEA",
                "exchange": "NSE",
                "instrument_token": 14366,
                "product": "",
                "quantity": 4,
                "overnight_quantity": 0,
                "multiplier": 1,
                "average_price": 100,
                "close_price": 16.55,
                "last_price": 16.55,
                "value": 400,
                "pnl": 0,
                "m2m": -333.8,
                "unrealised": 0,
                "realised": 0,
                "buy_quantity": 4,
                "buy_price": 100,
                "buy_value": 400,
                "buy_m2m": 0,
                "sell_quantity": 0,
                "sell_price": 0,
                "sell_value": 0,
                "sell_m2m": 0,
                "day_buy_quantity": 4,
                "day_buy_price": 100,
                "day_buy_value": 400,
                "day_sell_quantity": 0,
                "day_sell_price": 0,
                "day_sell_value": 0
            }
        ],
        "day": null
    }
}
{
    "status": "error",
    "message": "Please provide valid api version.",
    "error_type": "VersionException",
    "data": null
}
Position Converstion
Each position has one margin product. These products affect how the user's margin usage and free cash values are computed, and a user may wish to convert or change a position's margin product on timely basis.
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. 
curl --location 'https://api.mstock.trade/openapi/typea/portfolio/convertposition' \
    --header 'X-Mirae-Version: 1' \
    --header 'Authorization: token api_key:access_token'\
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'tradingsymbol=ACC' \
    --data-urlencode 'exchange=NSE' \
    --data-urlencode 'transaction_type=BUY' \
    --data-urlencode 'position_type=DAY' \
    --data-urlencode 'quantity=1' \
    --data-urlencode 'old_product=CNC' \
    --data-urlencode 'new_product=MIS'
import axios from 'axios';
const response = await axios.post(
'https://api.mstock.trade/openapi/typea/portfolio/convertposition',
new URLSearchParams({
    'tradingsymbol': 'ACC',
    'exchange': 'NSE',
    'transaction_type': 'BUY',
    'position_type': 'DAY',
    'quantity': '1',
    'old_product': 'CNC',
    'new_product': 'MIS'
}),
{
    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 = {
    'tradingsymbol': 'ACC',
    'exchange': 'NSE',
    'transaction_type': 'BUY',
    'position_type': 'DAY',
    'quantity': '1',
    'old_product': 'CNC',
    'new_product': 'MIS',
}
response = requests.post('https://api.mstock.trade/openapi/typea/portfolio/convertposition', 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/portfolio/convertposition"))
    .POST(BodyPublishers.ofString("tradingsymbol=ACC&exchange=NSE&transaction_type=BUY&position_type=DAY&quantity=1&old_product=CNC&new_product=MIS"))
    .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 -
This endpoint does not require a request body or additional parameters in the query string for the retrieval of orders.
| Field | Type | Description | 
|---|---|---|
| tradingsymbol | string | Refer Trading Symbol in Tables | 
| exchange | string | Exchange Name : NSEBSE | 
| transaction_type | string | The trading side of transaction : BUYSELL | 
| position_type | string | Position Type : DAY | 
| quantity | string | Number of shares for the order | 
| old_product | string | Product type CNCMISMTF | 
| new_product | string | Product type CNCMISMTF | 
Response Structure -
The response of the request will be based on authentication outcome.
- Success (HTTP Status 200): On successful retrieval, the server returns a JSON array of client positions.
instrument_token,exchange_token,tradingsymbol,name,last_price,expiry,strike,
  tick_size,lot_size,instrument_type,segment,exchange
1,1,GOLDSTAR,GOLDSTAR POWER LIMITED,,,,,1,SM,SM,NSE
2,2,91D101220,GOI TBILL 91D-10/12/20,,,,,1,TB,TB,NSE
- 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
}