Option Contracts
Get option contracts of an instrument key
- Curl
- Python
- Node.js
- Java
- PHP
curl --location 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050'
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
response = requests.get(url, headers=headers)
# Print the response content
print(response.text)
const axios = require('axios');
const url = 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050';
const headers = {
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
axios.get(url, { headers })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error('Error:', error);
});
import java.io.IOException;
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 IOException, InterruptedException {
String url = "https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050";
String token = "{your_access_token}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Accept", "application/json")
.header("Authorization", "Bearer " + token)
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Response Code: " + response.statusCode());
System.out.println("Response Content: " + response.body());
}
}
<?php
$url = 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050';
$token = '{your_access_token}';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: application/json',
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Response Code: $httpCode\n";
echo "Response Content: $response\n";
?>
Get option contracts of an instrument key with expiry date
- Curl
- Python
- Node.js
- Java
- PHP
curl --location 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-03-28' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}'
import requests
url = 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-03-28'
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
}
response = requests.get(url, headers=headers)
# Print the response content
print(response.text)
const axios = require('axios');
const url = 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-03-28';
const headers = {
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}'
};
axios.get(url, { headers })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error('Error:', error);
});
import java.io.IOException;
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 IOException, InterruptedException {
String url = "https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-03-28";
String token = "{your_access_token}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Accept", "application/json")
.header("Authorization", "Bearer " + token)
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Response Code: " + response.statusCode());
System.out.println("Response Content: " + response.body());
}
}
<?php
$url = 'https://api.upstox.com/v2/option/contract?instrument_key=NSE_INDEX%7CNifty%2050&expiry_date=2024-03-28';
$token = '{your_access_token}';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: application/json',
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Response Code: $httpCode\n";
echo "Response Content: $response\n";
?>