Skip to content

Historical Data

Historical Data APIs

method path description
GET https://api.mstock.trade/openapi/typea/instruments/historical/{exchange}/{instrument_token}/{interval}?from={2024-08-02+09:15:00}&to={2024-08-04+09:20:00} View historical Data

The historical data API provides the historical data for instruments across various exchange segment.

Historical Data Limit

The maximum number of historical data bars retrievable per request is 1000, regardless of the timeframe. Please adjust your queries accordingly.

Query Parameter -

Field Type Description
exchange string Exchange segment. Supported values: NSE, NFO, BSE, and BFO.
instrument_token string Instrument token from the Script Master CSV. Download the file scriptmaster.
interval string Interval frame (minute, day, 3minute, 5minute, 10minute, 15minute, 30minute and 60minute)

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/instruments/historical/NSE/11536/60minute?from=2024-08-02+09%3A15%3A00&to=2024-08-04+09%3A20%3A00' \
--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/instruments/historical/NSE/11536/60minute', {
params: {
    'from': '2024-08-02 09:15:00',
    'to': '2024-08-04 09:20:00'
},
headers: {
    'X-Mirae-Version': '1',
    'Authorization': 'token api_key:access_token'
}
});
import http.client

conn = http.client.HTTPSConnection('api.mstock.trade')
headers = {
    'X-Mirae-Version': '1',
    'Authorization': 'token api_key:access_token',
}
conn.request(
    'GET',
    'openapi/typea/instruments/historical/NSE/11536/60minute?from=2024-08-02+09%3A15%3A00&to=2024-08-04+09%3A20%3A00',
    headers=headers
)
response = conn.getresponse()
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/instruments/historical/NSE/11536/60minute?from=2024-08-02+09%3A15%3A00&to=2024-08-04+09%3A20%3A00"))
    .GET()
    .setHeader("X-Mirae-Version", "1")
    .setHeader("Authorization", "token api_key:access_token")
    .build();

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

Query Parameter -

Field Type Description
exchange string NSE
instrument_token string 11536
interval string 60minute
fromdate string 2024-08-02
todate string 2024-08-04

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

Request Response -

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

  • Success (HTTP Status 200): On successful request the server will returns a JSON object.
{
    "status": "success",
    "data": {
        "candles": [
            [
                "2024-01-01T09:15:00+05",
                3790,
                3832,
                3773.35,
                3803,
                825219
            ],
            [
                "2024-01-02T09:15:00+05",
                3811.1,
                3811.1,
                3767.25,
                3781.15,
                1343722
            ]
        ]
    }
}
  • Failure (HTTP Status 400): If the request fails due to invalid parameters the server will return an error message with below json format.

{
    "status": "error",
    "message": "Invalid request. Please try again.",
    "error_type": "InputException",
    "data": null
}
- Failure (HTTP Status 401): If the request fails due to authentication issues 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 403): 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
}