OHLC Quotes V3โ
This API retrieves Open, High, Low, Close (OHLC) quotes for one or more instruments. V3 introduces the following enhancements:
live_ohlc
: Provides the current OHLC candle.prev_ohlc
: Delivers the previous minute's OHLC candle.volume
: Includes trading volume data.ts
: Returns the OHLC candle's start time.
Requestโ
curl --location 'https://api.upstox.com/v3/market-quote/ohlc?instrument_key=NSE_EQ%7CINE669E01016&interval=1d' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
For additional samples in various languages, please refer to the Sample code section on this page.
Query Parametersโ
Name | Required | Type | Description |
---|---|---|---|
instrument_key | true | string | Comma separated list of instrument keys. For the regex pattern applicable to this field, see the Field Pattern Appendix. |
interval | true | string | Interval to get ohlc data. Possible values: 1d , I1 , I30 . Here 1d is 1 day, I1 and I30 are 1-minute and 30-minute intervals respectively. |
Responses
- 200
- 4XX
Response Bodyโ
{
"status": "success",
"data": {
"NSE_FO:NIFTY2543021600PE": {
"last_price": 303.9,
"instrument_token": "NSE_FO|51834",
"prev_ohlc": {
"open": 303.9,
"high": 304.3,
"low": 303.85,
"close": 304.3,
"volume": 300,
"ts": 1744019880000
},
"live_ohlc": {
"open": 304.45,
"high": 304.45,
"low": 302.75,
"close": 303.9,
"volume": 2250,
"ts": 1744019940000
}
}
}
}
Name | Type | Description |
---|---|---|
status | string | A string indicating the outcome of the request. Typically success for successful operations. |
data | object | Data object holding OHLC information |
data.last_price | number | The last traded price of symbol |
data.instrument_token | string | Key of the instrument. For the regex pattern applicable to this field, see the Field Pattern Appendix. |
data.prev_ohlc.open | number | Previous trading session open price |
data.prev_ohlc.high | number | Previous trading session high price |
data.prev_ohlc.low | number | Previous trading session low price |
data.prev_ohlc.close | number | Previous trading session close price |
data.prev_ohlc.volume | number | Total volume traded in previous trading session |
data.prev_ohlc.ts | number | Start time of previous trading session |
data.live_ohlc.open | number | Current trading session open price |
data.live_ohlc.high | number | Current trading session high price |
data.live_ohlc.low | number | Current trading session low price |
data.live_ohlc.close | number | Current trading session close price |
data.live_ohlc.volume | number | Total volume traded in current trading session |
data.live_ohlc.ts | number | Start time of current trading session |
Error codesโ
Error code | Description |
---|---|
UDAPI1009 | symbol is required - The symbol parameter is missing. |
UDAPI1011 | symbol is of invalid format - The provided symbol does not conform to the accepted format. |
UDAPI1028 | Invalid interval - The specified interval doesn't match any of the recognized values. |
UDAPI1027 | interval is required - You must specify the 'interval' for this operation. |
UDAPI1087 | Invalid Instrument key - The provided instrument_key is invalid. |
UDAPI100043 | Maximum instrument key limit exceeded - The request exceeds the maximum number of instrument keys allowed. |
Sample Codeโ
Get ohlc (open, high, low, close) market quotesโ
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v3/market-quote/ohlc?instrument_key=NSE_EQ%7CINE669E01016&interval=1d' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v3/market-quote/ohlc'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
"instrument_key": "NSE_EQ|INE669E01016",
"interval": "1d"
}
response = requests.get(url, headers=headers, params=data)
print(response.status_code)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v3/market-quote/ohlc';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const params = {
instrument_key: 'NSE_EQ|INE669E01016',
interval: '1d',
};
axios.get(url, { headers, params })
.then(response => {
console.log('Response Status Code:', response.status);
console.log('Response Data:', response.data);
})
.catch(error => {
console.error('Error:', error.message);
});
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
// Set the API endpoint URL
String apiUrl = "https://api.upstox.com/v3/market-quote/ohlc?instrument_key=NSE_EQ%7CINE669E01016&interval=1d";
// Set the request headers
String contentTypeHeader = "application/json";
String acceptHeader = "application/json";
String authorizationHeader = "Bearer {your_access_token}";
// Build the URI
URI uri = URI.create(apiUrl);
// Create the HttpClient
HttpClient httpClient = HttpClient.newHttpClient();
// Build the HttpRequest
HttpRequest request = HttpRequest.newBuilder()
.uri(uri)
.header("Content-Type", contentTypeHeader)
.header("Accept", acceptHeader)
.header("Authorization", authorizationHeader)
.build();
// Send the request and retrieve the response
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
// Print the response
System.out.println("Response Code: " + response.statusCode());
System.out.println("Response Body: " + response.body());
}
}
<?php
$url = 'https://api.upstox.com/v3/market-quote/ohlc';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'instrument_key' => 'NSE_EQ|INE669E01016',
'interval' => '1d',
];
$ch = curl_init($url . '?' . http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo 'Response Status Code: ' . $status_code . PHP_EOL;
echo 'Response Data: ' . $response . PHP_EOL;
?>
import upstox_client
from upstox_client.rest import ApiException
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
apiInstance = upstox_client.MarketQuoteV3Api(upstox_client.ApiClient(configuration))
try:
# For a single instrument
response = apiInstance.get_market_quote_ohlc("1d", instrument_key="NSE_EQ|INE669E01016")
print(response)
except ApiException as e:
print("Exception when calling MarketQuoteV3Api->get_market_quote_ohlc: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
let marketQuoteApiInstance = new UpstoxClient.MarketQuoteV3Api();
marketQuoteApiInstance.getMarketQuoteOHLC("1d", {instrumentKey: "NSE_EQ|INE669E01016"}, (error, data, response) => {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.MarketQuoteV3Api;
import com.upstox.model.GetMarketQuoteOHLCResponseV3;
import com.upstox.auth.*;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
MarketQuoteV3Api marketQuoteV3Api = new MarketQuoteV3Api();
try {
GetMarketQuoteOHLCResponseV3 result = marketQuoteV3Api.getMarketQuoteOHLC("1d", "NSE_EQ|INE669E01016");
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling MarketQuoteV3Api#getMarketQuoteOHLC");
e.printStackTrace();
}
}
}
Get ohlc (open, high, low, close) market quotes for multiple instrument keysโ
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location 'https://api.upstox.com/v3/market-quote/ohlc?instrument_key=NSE_EQ%7CINE669E01016%2CNSE_EQ%7CINE848E01016&interval=1d' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v3/market-quote/ohlc'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
}
data = {
"instrument_key": "NSE_EQ|INE669E01016,NSE_EQ|INE848E01016",
"interval": "1d"
}
response = requests.get(url, headers=headers, params=data)
print(response.status_code)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v3/market-quote/ohlc';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}',
};
const params = {
instrument_key: 'NSE_EQ|INE669E01016,NSE_EQ|INE848E01016',
interval: '1d',
};
axios.get(url, { headers, params })
.then(response => {
console.log('Response Status Code:', response.status);
console.log('Response Data:', response.data);
})
.catch(error => {
console.error('Error:', error.message);
});
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
// Set the API endpoint URL
String apiUrl = "https://api.upstox.com/v3/market-quote/ohlc?instrument_key=NSE_EQ%7CINE669E01016%2CNSE_EQ%7CINE848E01016&interval=1d";
// Set the request headers
String contentTypeHeader = "application/json";
String acceptHeader = "application/json";
String authorizationHeader = "Bearer {your_access_token}";
// Build the URI
URI uri = URI.create(apiUrl);
// Create the HttpClient
HttpClient httpClient = HttpClient.newHttpClient();
// Build the HttpRequest
HttpRequest request = HttpRequest.newBuilder()
.uri(uri)
.header("Content-Type", contentTypeHeader)
.header("Accept", acceptHeader)
.header("Authorization", authorizationHeader)
.build();
// Send the request and retrieve the response
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
// Print the response
System.out.println("Response Code: " + response.statusCode());
System.out.println("Response Body: " + response.body());
}
}
<?php
$url = 'https://api.upstox.com/v3/market-quote/ohlc';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'instrument_key' => 'NSE_EQ|INE669E01016,NSE_EQ|INE848E01016',
'interval' => '1d',
];
$ch = curl_init($url . '?' . http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo 'Response Status Code: ' . $status_code . PHP_EOL;
echo 'Response Data: ' . $response . PHP_EOL;
?>
import upstox_client
from upstox_client.rest import ApiException
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
apiInstance = upstox_client.MarketQuoteV3Api(upstox_client.ApiClient(configuration))
try:
# For multiple instruments
response = apiInstance.get_market_quote_ohlc("1d", instrument_key="NSE_EQ|INE669E01016,NSE_EQ|INE848E01016")
print(response)
except ApiException as e:
print("Exception when calling MarketQuoteV3Api->get_market_quote_ohlc: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = "{your_access_token}";
let marketQuoteApiInstance = new UpstoxClient.MarketQuoteV3Api();
marketQuoteApiInstance.getMarketQuoteOHLC("1d", {instrumentKey: "NSE_EQ|INE669E01016,NSE_EQ|INE848E01016"}, (error, data, response) => {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.MarketQuoteV3Api;
import com.upstox.model.GetMarketQuoteOHLCResponseV3;
import com.upstox.auth.*;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
MarketQuoteV3Api marketQuoteV3Api = new MarketQuoteV3Api();
try {
GetMarketQuoteOHLCResponseV3 result = marketQuoteV3Api.getMarketQuoteOHLC("1d", "NSE_EQ|INE669E01016,NSE_EQ|INE848E01016");
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling MarketQuoteV3Api#getMarketQuoteOHLC");
e.printStackTrace();
}
}
}
Loading...