OHLC Quotes Deprecatedโ
API to retrieve the OHLC (Open, High, Low, Close) quotes for one or more instruments. Provides OHLC snapshots of up to 500 instruments in one go.
This API supports a maximum of 500 instrument keys in a single request. For a time interval of 1d
, the API returns only the live_ohlc
. Previous day OHLC data is available in Historical Candle Data.
Requestโ
curl --location 'https://api.upstox.com/v2/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}'
Additional samples in various languages are available in 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โ
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.ohlc | object | Data object with OHLC information |
data.ohlc.open | number | The open price of the trading session |
data.ohlc.high | number | The high price of the trading session |
data.ohlc.low | number | The low price of the trading session |
data.ohlc.close | number | The most recent closing price of the symbol |
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. |
Error codesโ
Error code | Description |
---|---|
UDAPI1087 | One of either symbol or instrument_key is invalid - The provided symbol or instrument_key does not confirm 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. |
UDAPI100043 | Data of only 500 instrument keys can be requested in single API call - Limit your request to 500 instrument keys at a time. |
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/v2/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/v2/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/v2/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/v2/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/v2/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}'
api_version = '2.0'
symbol = 'NSE_EQ|INE669E01016'
api_instance = upstox_client.MarketQuoteApi(upstox_client.ApiClient(configuration))
interval='1d'
try:
api_response = api_instance.get_market_quote_ohlc(symbol,interval,api_version)
print(api_response)
except ApiException as e:
print("Exception when calling MarketQuoteApi->get_full_market_quote: %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 apiInstance = new UpstoxClient.MarketQuoteApi();
let apiVersion = "2.0";
let symbol = "NSE_EQ|INE669E01016";
let interval = "1d";
apiInstance.getMarketQuoteOHLC(symbol, interval,apiVersion, (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.GetMarketQuoteOHLCResponse;
import com.upstox.auth.*;
import io.swagger.client.api.MarketQuoteApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
MarketQuoteApi apiInstance = new MarketQuoteApi();
String apiVersion = "2.0";
String symbol = "NSE_EQ|INE669E01016";
String interval = "1d";
try {
GetMarketQuoteOHLCResponse result = apiInstance.getMarketQuoteOHLC(symbol, interval, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling MarketQuoteApi#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/v2/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/v2/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/v2/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/v2/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/v2/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}'
api_version = '2.0'
symbol = 'NSE_EQ|INE669E01016,NSE_EQ|INE848E01016'
api_instance = upstox_client.MarketQuoteApi(upstox_client.ApiClient(configuration))
interval='1d'
try:
api_response = api_instance.get_market_quote_ohlc(symbol,interval,api_version)
print(api_response)
except ApiException as e:
print("Exception when calling MarketQuoteApi->get_full_market_quote: %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 apiInstance = new UpstoxClient.MarketQuoteApi();
let apiVersion = "2.0";
let symbol = "NSE_EQ|INE669E01016,NSE_EQ|INE848E01016";
let interval = "1d";
apiInstance.getMarketQuoteOHLC(symbol, interval,apiVersion, (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.GetMarketQuoteOHLCResponse;
import com.upstox.auth.*;
import io.swagger.client.api.MarketQuoteApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
MarketQuoteApi apiInstance = new MarketQuoteApi();
String apiVersion = "2.0";
String symbol = "NSE_EQ|INE669E01016,NSE_EQ|INE848E01016";
String interval = "1d";
try {
GetMarketQuoteOHLCResponse result = apiInstance.getMarketQuoteOHLC(symbol, interval, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling MarketQuoteApi#getMarketQuoteOHLC");
e.printStackTrace();
}
}
}
Loading...