Convert Positions
Convert a position from intraday to delivery
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location --request PUT 'https://api.upstox.com/v2/portfolio/convert-position' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"instrument_token": "NSE_EQ|INE528G01035",
"new_product": "D",
"old_product": "I",
"transaction_type": "BUY",
"quantity": 1
}'
import requests
url = 'https://api.upstox.com/v2/portfolio/convert-position'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}', # Replace {your_access_token} with your actual access token
}
data = {
"instrument_token": "NSE_EQ|INE528G01035",
"new_product": "D",
"old_product": "I",
"transaction_type": "BUY",
"quantity": 1
}
response = requests.put(url, headers=headers, json=data)
print(response.status_code)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/portfolio/convert-position';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}', // Replace {your_access_token} with your actual access token
};
const data = {
"instrument_token": "NSE_EQ|INE528G01035",
"new_product": "D",
"old_product": "I",
"transaction_type": "BUY",
"quantity": 1
};
axios.put(url, data, { headers })
.then(response => {
console.log('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;
import java.nio.charset.StandardCharsets;
public class Main {
public static void main(String[] args) {
try {
String url = "https://api.upstox.com/v2/portfolio/convert-position";
// Building the request payload
String payload = "{\n" +
" \"instrument_token\": \"NSE_EQ|INE528G01035\",\n" +
" \"new_product\": \"D\",\n" +
" \"old_product\": \"I\",\n" +
" \"transaction_type\": \"BUY\",\n" +
" \"quantity\": 1\n" +
"}";
// Replace {your_access_token} with your actual access token
String accessToken = "{your_access_token}";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("Authorization", "Bearer " + accessToken)
.method("PUT", HttpRequest.BodyPublishers.ofString(payload, StandardCharsets.UTF_8))
.build();
HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
// Reading the response
int responseCode = response.statusCode();
System.out.println("Response Code: " + responseCode);
// Printing the response body
System.out.println("Response Body: " + response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/portfolio/convert-position';
// Replace {your_access_token} with your actual access token
$accessToken = '{your_access_token}';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer ' . $accessToken,
];
$data = [
"instrument_token" => "NSE_EQ|INE528G01035",
"new_product" => "D",
"old_product" => "I",
"transaction_type" => "BUY",
"quantity" => 1
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Output the response code and body
echo "Response Code: " . $httpCode . PHP_EOL;
echo "Response Body: " . $response . PHP_EOL;
?>
import upstox_client
from upstox_client.rest import ApiException
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
api_instance = upstox_client.PortfolioApi(upstox_client.ApiClient(configuration))
body = upstox_client.ConvertPositionRequest(instrument_token= "NSE_EQ|INE528G01035",quantity=1,new_product="D",old_product="I",transaction_type="BUY")
api_version = '2.0'
try:
# Convert Positions
api_response = api_instance.convert_positions(body, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling PortfolioApi->convert_positions: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
// Configure OAuth2 access token for authorization: OAUTH2
let OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = '{your_access_token}';
let apiInstance = new UpstoxClient.PortfolioApi();
let body = new UpstoxClient.ConvertPositionRequest("NSE_EQ|INE528G01035",UpstoxClient.ConvertPositionRequest.NewProductEnum.D,UpstoxClient.ConvertPositionRequest.OldProductEnum.I,UpstoxClient.ConvertPositionRequest.TransactionTypeEnum.BUY,1); // ConvertPositionRequest |
let apiVersion = "2.0"; // String | API Version Header
apiInstance.convertPositions(body, 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.ConvertPositionRequest;
import com.upstox.api.ConvertPositionResponse;
import com.upstox.auth.*;
import io.swagger.client.api.PortfolioApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
PortfolioApi apiInstance = new PortfolioApi();
ConvertPositionRequest body = new ConvertPositionRequest();
body.setInstrumentToken("NSE_EQ|INE528G01035");
body.setNewProduct(ConvertPositionRequest.NewProductEnum.D);
body.setOldProduct(ConvertPositionRequest.OldProductEnum.I);
body.setQuantity(2);
body.setTransactionType(ConvertPositionRequest.TransactionTypeEnum.BUY);
String apiVersion = "2.0";
try {
ConvertPositionResponse result = apiInstance.convertPositions(body, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PortfolioApi#convertPositions");
e.printStackTrace();
}
}
}
Convert a position from delivery to intraday
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl --location --request PUT 'https://api.upstox.com/v2/portfolio/convert-position' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {your_access_token}' \
--data '{
"instrument_token": "NSE_EQ|INE528G01035",
"new_product": "I",
"old_product": "D",
"transaction_type": "BUY",
"quantity": 1
}'
import requests
url = 'https://api.upstox.com/v2/portfolio/convert-position'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}', # Replace {your_access_token} with your actual access token
}
data = {
"instrument_token": "NSE_EQ|INE528G01035",
"new_product": "I",
"old_product": "D",
"transaction_type": "BUY",
"quantity": 1
}
response = requests.put(url, headers=headers, json=data)
print(response.status_code)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v2/portfolio/convert-position';
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {your_access_token}', // Replace {your_access_token} with your actual access token
};
const data = {
"instrument_token": "NSE_EQ|INE528G01035",
"new_product": "I",
"old_product": "D",
"transaction_type": "BUY",
"quantity": 1
};
axios.put(url, data, { headers })
.then(response => {
console.log('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;
import java.nio.charset.StandardCharsets;
public class Main {
public static void main(String[] args) {
try {
String url = "https://api.upstox.com/v2/portfolio/convert-position";
// Building the request payload
String payload = "{\n" +
" \"instrument_token\": \"NSE_EQ|INE528G01035\",\n" +
" \"new_product\": \"I\",\n" +
" \"old_product\": \"D\",\n" +
" \"transaction_type\": \"BUY\",\n" +
" \"quantity\": 1\n" +
"}";
// Replace {your_access_token} with your actual access token
String accessToken = "{your_access_token}";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("Authorization", "Bearer " + accessToken)
.method("PUT", HttpRequest.BodyPublishers.ofString(payload, StandardCharsets.UTF_8))
.build();
HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
// Reading the response
int responseCode = response.statusCode();
System.out.println("Response Code: " + responseCode);
// Printing the response body
System.out.println("Response Body: " + response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$url = 'https://api.upstox.com/v2/portfolio/convert-position';
// Replace {your_access_token} with your actual access token
$accessToken = '{your_access_token}';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer ' . $accessToken,
];
$data = [
"instrument_token" => "NSE_EQ|INE528G01035",
"new_product" => "I",
"old_product" => "D",
"transaction_type" => "BUY",
"quantity" => 1
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Output the response code and body
echo "Response Code: " . $httpCode . PHP_EOL;
echo "Response Body: " . $response . PHP_EOL;
?>
import upstox_client
from upstox_client.rest import ApiException
configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'
api_instance = upstox_client.PortfolioApi(upstox_client.ApiClient(configuration))
body = upstox_client.ConvertPositionRequest(instrument_token= "NSE_EQ|INE528G01035",quantity=1,new_product="I",old_product="D",transaction_type="BUY")
api_version = '2.0'
try:
# Convert Positions
api_response = api_instance.convert_positions(body, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling PortfolioApi->convert_positions: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let defaultClient = UpstoxClient.ApiClient.instance;
// Configure OAuth2 access token for authorization: OAUTH2
let OAUTH2 = defaultClient.authentications['OAUTH2'];
OAUTH2.accessToken = '{your_access_token}';
let apiInstance = new UpstoxClient.PortfolioApi();
let body = new UpstoxClient.ConvertPositionRequest("NSE_EQ|INE528G01035",UpstoxClient.ConvertPositionRequest.NewProductEnum.I,UpstoxClient.ConvertPositionRequest.OldProductEnum.D,UpstoxClient.ConvertPositionRequest.TransactionTypeEnum.BUY,1); // ConvertPositionRequest |
let apiVersion = "2.0"; // String | API Version Header
apiInstance.convertPositions(body, 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.ConvertPositionRequest;
import com.upstox.api.ConvertPositionResponse;
import com.upstox.auth.*;
import io.swagger.client.api.PortfolioApi;
public class Main {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("{your_access_token}");
PortfolioApi apiInstance = new PortfolioApi();
ConvertPositionRequest body = new ConvertPositionRequest();
body.setInstrumentToken("NSE_EQ|INE528G01035");
body.setNewProduct(ConvertPositionRequest.NewProductEnum.I);
body.setOldProduct(ConvertPositionRequest.OldProductEnum.D);
body.setQuantity(2);
body.setTransactionType(ConvertPositionRequest.TransactionTypeEnum.BUY);
String apiVersion = "2.0";
try {
ConvertPositionResponse result = apiInstance.convertPositions(body, apiVersion);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PortfolioApi#convertPositions");
e.printStackTrace();
}
}
}