Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Upstox Developer API
* Build your App on the Upstox platform ![Banner](https://api-v2.upstox.com/api-docs/images/banner.jpg \"banner\") # Introduction Upstox API is a set of rest APIs that provide data required to build a complete investment and trading platform. Execute orders in real time, manage user portfolio, stream live market data (using Websocket), and more, with the easy to understand API collection. All requests are over HTTPS and the requests are sent with the content-type ‘application/json’. Developers have the option of choosing the response type as JSON or CSV for a few API calls. To be able to use these APIs you need to create an App in the Developer Console and generate your **apiKey** and **apiSecret**. You can use a redirect URL which will be called after the login flow. If you are a **trader**, you can directly create apps from Upstox mobile app or the desktop platform itself from **Apps** sections inside the **Account** Tab. Head over to account.upstox.com/developer/apps. If you are a **business** looking to integrate Upstox APIs, reach out to us and we will get a custom app created for you in no time. It is highly recommended that you do not embed the **apiSecret** in your frontend app. Create a remote backend which does the handshake on behalf of the frontend app. Marking the apiSecret in the frontend app will make your app vulnerable to threats and potential issues.
*
* OpenAPI spec version: v2
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package io.swagger.client.api;
import com.upstox.ApiCallback;
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.ApiResponse;
import com.upstox.Configuration;
import com.upstox.Pair;
import com.upstox.ProgressRequestBody;
import com.upstox.ProgressResponseBody;
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import com.upstox.api.ApiGatewayErrorResponse;
import com.upstox.api.ConvertPositionRequest;
import com.upstox.api.ConvertPositionResponse;
import com.upstox.api.GetHoldingsResponse;
import com.upstox.api.GetPositionResponse;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PortfolioApi {
private ApiClient apiClient;
public PortfolioApi() {
this(Configuration.getDefaultApiClient());
}
public PortfolioApi(ApiClient apiClient) {
this.apiClient = apiClient;
}
public ApiClient getApiClient() {
return apiClient;
}
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
/**
* Build call for convertPositions
* @param body (required)
* @param apiVersion API Version Header (required)
* @param progressListener Progress listener
* @param progressRequestListener Progress request listener
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
*/
public com.squareup.okhttp.Call convertPositionsCall(ConvertPositionRequest body, String apiVersion, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
Object localVarPostBody = body;
// create path and map variables
String localVarPath = "/v2/portfolio/convert-position";
List localVarQueryParams = new ArrayList();
List localVarCollectionQueryParams = new ArrayList();
Map localVarHeaderParams = new HashMap();
if (apiVersion != null)
localVarHeaderParams.put("Api-Version", apiClient.parameterToString(apiVersion));
Map localVarFormParams = new HashMap();
final String[] localVarAccepts = {
"*/*", "application/json"
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);
final String[] localVarContentTypes = {
"application/json"
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
localVarHeaderParams.put("Content-Type", localVarContentType);
if(progressListener != null) {
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder()
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
.build();
}
});
}
String[] localVarAuthNames = new String[] { "OAUTH2" };
return apiClient.buildCall(localVarPath, "PUT", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
}
@SuppressWarnings("rawtypes")
private com.squareup.okhttp.Call convertPositionsValidateBeforeCall(ConvertPositionRequest body, String apiVersion, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
// verify the required parameter 'body' is set
if (body == null) {
throw new ApiException("Missing the required parameter 'body' when calling convertPositions(Async)");
}
// verify the required parameter 'apiVersion' is set
if (apiVersion == null) {
throw new ApiException("Missing the required parameter 'apiVersion' when calling convertPositions(Async)");
}
com.squareup.okhttp.Call call = convertPositionsCall(body, apiVersion, progressListener, progressRequestListener);
return call;
}
/**
* Convert Positions
* Convert the margin product of an open position
* @param body (required)
* @param apiVersion API Version Header (required)
* @return ConvertPositionResponse
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ConvertPositionResponse convertPositions(ConvertPositionRequest body, String apiVersion) throws ApiException {
ApiResponse resp = convertPositionsWithHttpInfo(body, apiVersion);
return resp.getData();
}
/**
* Convert Positions
* Convert the margin product of an open position
* @param body (required)
* @param apiVersion API Version Header (required)
* @return ApiResponse<ConvertPositionResponse>
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse convertPositionsWithHttpInfo(ConvertPositionRequest body, String apiVersion) throws ApiException {
com.squareup.okhttp.Call call = convertPositionsValidateBeforeCall(body, apiVersion, null, null);
Type localVarReturnType = new TypeToken(){}.getType();
return apiClient.execute(call, localVarReturnType);
}
/**
* Convert Positions (asynchronously)
* Convert the margin product of an open position
* @param body (required)
* @param apiVersion API Version Header (required)
* @param callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
*/
public com.squareup.okhttp.Call convertPositionsAsync(ConvertPositionRequest body, String apiVersion, final ApiCallback callback) throws ApiException {
ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
if (callback != null) {
progressListener = new ProgressResponseBody.ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
callback.onDownloadProgress(bytesRead, contentLength, done);
}
};
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
callback.onUploadProgress(bytesWritten, contentLength, done);
}
};
}
com.squareup.okhttp.Call call = convertPositionsValidateBeforeCall(body, apiVersion, progressListener, progressRequestListener);
Type localVarReturnType = new TypeToken(){}.getType();
apiClient.executeAsync(call, localVarReturnType, callback);
return call;
}
/**
* Build call for getHoldings
* @param apiVersion API Version Header (required)
* @param progressListener Progress listener
* @param progressRequestListener Progress request listener
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
*/
public com.squareup.okhttp.Call getHoldingsCall(String apiVersion, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
Object localVarPostBody = null;
// create path and map variables
String localVarPath = "/v2/portfolio/long-term-holdings";
List localVarQueryParams = new ArrayList();
List localVarCollectionQueryParams = new ArrayList();
Map localVarHeaderParams = new HashMap();
if (apiVersion != null)
localVarHeaderParams.put("Api-Version", apiClient.parameterToString(apiVersion));
Map localVarFormParams = new HashMap();
final String[] localVarAccepts = {
"*/*", "application/json"
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);
final String[] localVarContentTypes = {
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
localVarHeaderParams.put("Content-Type", localVarContentType);
if(progressListener != null) {
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder()
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
.build();
}
});
}
String[] localVarAuthNames = new String[] { "OAUTH2" };
return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
}
@SuppressWarnings("rawtypes")
private com.squareup.okhttp.Call getHoldingsValidateBeforeCall(String apiVersion, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
// verify the required parameter 'apiVersion' is set
if (apiVersion == null) {
throw new ApiException("Missing the required parameter 'apiVersion' when calling getHoldings(Async)");
}
com.squareup.okhttp.Call call = getHoldingsCall(apiVersion, progressListener, progressRequestListener);
return call;
}
/**
* Get Holdings
* Fetches the holdings which the user has bought/sold in previous trading sessions.
* @param apiVersion API Version Header (required)
* @return GetHoldingsResponse
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public GetHoldingsResponse getHoldings(String apiVersion) throws ApiException {
ApiResponse resp = getHoldingsWithHttpInfo(apiVersion);
return resp.getData();
}
/**
* Get Holdings
* Fetches the holdings which the user has bought/sold in previous trading sessions.
* @param apiVersion API Version Header (required)
* @return ApiResponse<GetHoldingsResponse>
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse getHoldingsWithHttpInfo(String apiVersion) throws ApiException {
com.squareup.okhttp.Call call = getHoldingsValidateBeforeCall(apiVersion, null, null);
Type localVarReturnType = new TypeToken(){}.getType();
return apiClient.execute(call, localVarReturnType);
}
/**
* Get Holdings (asynchronously)
* Fetches the holdings which the user has bought/sold in previous trading sessions.
* @param apiVersion API Version Header (required)
* @param callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
*/
public com.squareup.okhttp.Call getHoldingsAsync(String apiVersion, final ApiCallback callback) throws ApiException {
ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
if (callback != null) {
progressListener = new ProgressResponseBody.ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
callback.onDownloadProgress(bytesRead, contentLength, done);
}
};
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
callback.onUploadProgress(bytesWritten, contentLength, done);
}
};
}
com.squareup.okhttp.Call call = getHoldingsValidateBeforeCall(apiVersion, progressListener, progressRequestListener);
Type localVarReturnType = new TypeToken(){}.getType();
apiClient.executeAsync(call, localVarReturnType, callback);
return call;
}
/**
* Build call for getPositions
* @param apiVersion API Version Header (required)
* @param progressListener Progress listener
* @param progressRequestListener Progress request listener
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
*/
public com.squareup.okhttp.Call getPositionsCall(String apiVersion, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
Object localVarPostBody = null;
// create path and map variables
String localVarPath = "/v2/portfolio/short-term-positions";
List localVarQueryParams = new ArrayList();
List localVarCollectionQueryParams = new ArrayList();
Map localVarHeaderParams = new HashMap();
if (apiVersion != null)
localVarHeaderParams.put("Api-Version", apiClient.parameterToString(apiVersion));
Map localVarFormParams = new HashMap();
final String[] localVarAccepts = {
"*/*", "application/json"
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);
final String[] localVarContentTypes = {
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
localVarHeaderParams.put("Content-Type", localVarContentType);
if(progressListener != null) {
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder()
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
.build();
}
});
}
String[] localVarAuthNames = new String[] { "OAUTH2" };
return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
}
@SuppressWarnings("rawtypes")
private com.squareup.okhttp.Call getPositionsValidateBeforeCall(String apiVersion, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
// verify the required parameter 'apiVersion' is set
if (apiVersion == null) {
throw new ApiException("Missing the required parameter 'apiVersion' when calling getPositions(Async)");
}
com.squareup.okhttp.Call call = getPositionsCall(apiVersion, progressListener, progressRequestListener);
return call;
}
/**
* Get Positions
* Fetches the current positions for the user for the current day.
* @param apiVersion API Version Header (required)
* @return GetPositionResponse
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public GetPositionResponse getPositions(String apiVersion) throws ApiException {
ApiResponse resp = getPositionsWithHttpInfo(apiVersion);
return resp.getData();
}
/**
* Get Positions
* Fetches the current positions for the user for the current day.
* @param apiVersion API Version Header (required)
* @return ApiResponse<GetPositionResponse>
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse getPositionsWithHttpInfo(String apiVersion) throws ApiException {
com.squareup.okhttp.Call call = getPositionsValidateBeforeCall(apiVersion, null, null);
Type localVarReturnType = new TypeToken(){}.getType();
return apiClient.execute(call, localVarReturnType);
}
/**
* Get Positions (asynchronously)
* Fetches the current positions for the user for the current day.
* @param apiVersion API Version Header (required)
* @param callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
*/
public com.squareup.okhttp.Call getPositionsAsync(String apiVersion, final ApiCallback callback) throws ApiException {
ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
if (callback != null) {
progressListener = new ProgressResponseBody.ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
callback.onDownloadProgress(bytesRead, contentLength, done);
}
};
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
callback.onUploadProgress(bytesWritten, contentLength, done);
}
};
}
com.squareup.okhttp.Call call = getPositionsValidateBeforeCall(apiVersion, progressListener, progressRequestListener);
Type localVarReturnType = new TypeToken(){}.getType();
apiClient.executeAsync(call, localVarReturnType, callback);
return call;
}
}