OHLC Market Quotes
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 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/market-quote/ohlc'
headers = {
'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 = {
'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 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("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 = [
'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 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/market-quote/ohlc'
headers = {
'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 = {
'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 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("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 = [
'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();
}
}
}