diff --git a/README.md b/README.md index 298792c..9bf9432 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Add this dependency to your project's POM: com.upstox.api upstox-java-sdk - 1.20 + 1.21 compile ``` @@ -40,7 +40,7 @@ Add this dependency to your project's POM: Add this dependency to your project's build file: ```groovy -compile "com.upstox.api:upstox-java-sdk:1.19" +compile "com.upstox.api:upstox-java-sdk:1.21" ``` ## Sandbox Mode diff --git a/pom.xml b/pom.xml index a0adf2d..bfeb8e3 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ upstox-java-sdk jar upstox-java-sdk - 1.20 + 1.21 https://upstox.com/uplink/ The official Java client for communicating with the Upstox API diff --git a/src/main/java/com/upstox/ApiClient.java b/src/main/java/com/upstox/ApiClient.java index 1beb85b..a23ddc3 100644 --- a/src/main/java/com/upstox/ApiClient.java +++ b/src/main/java/com/upstox/ApiClient.java @@ -1014,7 +1014,7 @@ public Call buildCall(String path, String method, List queryParams, List

queryParams, List collectionQueryParams, Object body, Map headerParams, Map formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { updateParamsForAuth(authNames, queryParams, headerParams); headerParams.put("X-Upstox-SDK-Language","java"); - headerParams.put("X-Upstox-SDK-Version","1.20"); + headerParams.put("X-Upstox-SDK-Version","1.21"); final String url = buildUrl(path, queryParams, collectionQueryParams); final Request.Builder reqBuilder = new Request.Builder().url(url); processHeaderParams(headerParams, reqBuilder); diff --git a/src/main/java/com/upstox/api/SearchInstrumentResponse.java b/src/main/java/com/upstox/api/SearchInstrumentResponse.java new file mode 100644 index 0000000..82bb8e1 --- /dev/null +++ b/src/main/java/com/upstox/api/SearchInstrumentResponse.java @@ -0,0 +1,139 @@ +/* + * OpenAPI definition + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: v0 + * + * + * 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 com.upstox.api; + +import java.util.Objects; +import java.util.Arrays; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.upstox.api.SearchMetaData; +import io.swagger.v3.oas.annotations.media.Schema; +import java.io.IOException; +/** + * SearchInstrumentResponse + */ + +@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2026-03-18T13:23:00.662556+05:30[Asia/Kolkata]") + +public class SearchInstrumentResponse { + @SerializedName("status") + private Object status = null; + + @SerializedName("data") + private Object data = null; + + @SerializedName("meta_data") + private SearchMetaData metaData = null; + + public SearchInstrumentResponse status(Object status) { + this.status = status; + return this; + } + + /** + * Get status + * @return status + **/ + @Schema(description = "") + public Object getStatus() { + return status; + } + + public void setStatus(Object status) { + this.status = status; + } + + public SearchInstrumentResponse data(Object data) { + this.data = data; + return this; + } + + /** + * Response data for search instrument request + * @return data + **/ + @Schema(description = "Response data for search instrument request") + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + + public SearchInstrumentResponse metaData(SearchMetaData metaData) { + this.metaData = metaData; + return this; + } + + /** + * Meta data for search instrument response + * @return metaData + **/ + @Schema(description = "Meta data for search instrument response") + public SearchMetaData getMetaData() { + return metaData; + } + + public void setMetaData(SearchMetaData metaData) { + this.metaData = metaData; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + SearchInstrumentResponse searchInstrumentResponse = (SearchInstrumentResponse) o; + return Objects.equals(this.status, searchInstrumentResponse.status) && + Objects.equals(this.data, searchInstrumentResponse.data) && + Objects.equals(this.metaData, searchInstrumentResponse.metaData); + } + + @Override + public int hashCode() { + return Objects.hash(status, data, metaData); + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SearchInstrumentResponse {\n"); + + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" data: ").append(toIndentedString(data)).append("\n"); + sb.append(" metaData: ").append(toIndentedString(metaData)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} diff --git a/src/main/java/com/upstox/api/SearchMetaData.java b/src/main/java/com/upstox/api/SearchMetaData.java new file mode 100644 index 0000000..ec586e2 --- /dev/null +++ b/src/main/java/com/upstox/api/SearchMetaData.java @@ -0,0 +1,93 @@ +/* + * OpenAPI definition + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: v0 + * + * + * 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 com.upstox.api; + +import java.util.Objects; +import java.util.Arrays; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.upstox.api.SearchPage; +import io.swagger.v3.oas.annotations.media.Schema; +import java.io.IOException; +/** + * SearchMetaData + */ + +@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2026-03-18T13:23:00.662556+05:30[Asia/Kolkata]") + +public class SearchMetaData { + @SerializedName("page") + private SearchPage page = null; + + public SearchMetaData page(SearchPage page) { + this.page = page; + return this; + } + + /** + * Get page + * @return page + **/ + @Schema(description = "") + public SearchPage getPage() { + return page; + } + + public void setPage(SearchPage page) { + this.page = page; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + SearchMetaData searchMetaData = (SearchMetaData) o; + return Objects.equals(this.page, searchMetaData.page); + } + + @Override + public int hashCode() { + return Objects.hash(page); + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SearchMetaData {\n"); + + sb.append(" page: ").append(toIndentedString(page)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} diff --git a/src/main/java/com/upstox/api/SearchPage.java b/src/main/java/com/upstox/api/SearchPage.java new file mode 100644 index 0000000..f785b0b --- /dev/null +++ b/src/main/java/com/upstox/api/SearchPage.java @@ -0,0 +1,161 @@ +/* + * OpenAPI definition + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: v0 + * + * + * 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 com.upstox.api; + +import java.util.Objects; +import java.util.Arrays; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import io.swagger.v3.oas.annotations.media.Schema; +import java.io.IOException; +/** + * SearchPage + */ + +@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2026-03-18T13:23:00.662556+05:30[Asia/Kolkata]") + +public class SearchPage { + @SerializedName("page_number") + private Object pageNumber = null; + + @SerializedName("total_pages") + private Object totalPages = null; + + @SerializedName("records") + private Object records = null; + + @SerializedName("total_records") + private Object totalRecords = null; + + public SearchPage pageNumber(Object pageNumber) { + this.pageNumber = pageNumber; + return this; + } + + /** + * Get pageNumber + * @return pageNumber + **/ + @Schema(description = "") + public Object getPageNumber() { + return pageNumber; + } + + public void setPageNumber(Object pageNumber) { + this.pageNumber = pageNumber; + } + + public SearchPage totalPages(Object totalPages) { + this.totalPages = totalPages; + return this; + } + + /** + * Get totalPages + * @return totalPages + **/ + @Schema(description = "") + public Object getTotalPages() { + return totalPages; + } + + public void setTotalPages(Object totalPages) { + this.totalPages = totalPages; + } + + public SearchPage records(Object records) { + this.records = records; + return this; + } + + /** + * Get records + * @return records + **/ + @Schema(description = "") + public Object getRecords() { + return records; + } + + public void setRecords(Object records) { + this.records = records; + } + + public SearchPage totalRecords(Object totalRecords) { + this.totalRecords = totalRecords; + return this; + } + + /** + * Get totalRecords + * @return totalRecords + **/ + @Schema(description = "") + public Object getTotalRecords() { + return totalRecords; + } + + public void setTotalRecords(Object totalRecords) { + this.totalRecords = totalRecords; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + SearchPage searchPage = (SearchPage) o; + return Objects.equals(this.pageNumber, searchPage.pageNumber) && + Objects.equals(this.totalPages, searchPage.totalPages) && + Objects.equals(this.records, searchPage.records) && + Objects.equals(this.totalRecords, searchPage.totalRecords); + } + + @Override + public int hashCode() { + return Objects.hash(pageNumber, totalPages, records, totalRecords); + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SearchPage {\n"); + + sb.append(" pageNumber: ").append(toIndentedString(pageNumber)).append("\n"); + sb.append(" totalPages: ").append(toIndentedString(totalPages)).append("\n"); + sb.append(" records: ").append(toIndentedString(records)).append("\n"); + sb.append(" totalRecords: ").append(toIndentedString(totalRecords)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} diff --git a/src/main/java/com/upstox/api/TokenRequest.java b/src/main/java/com/upstox/api/TokenRequest.java index 9140339..8cd77ae 100644 --- a/src/main/java/com/upstox/api/TokenRequest.java +++ b/src/main/java/com/upstox/api/TokenRequest.java @@ -43,9 +43,6 @@ public class TokenRequest { @SerializedName("grant_type") private String grantType = null; - @SerializedName("refresh_extended_token") - private Boolean refreshExtendedToken = null; - public TokenRequest code(String code) { this.code = code; return this; @@ -136,25 +133,6 @@ public void setGrantType(String grantType) { this.grantType = grantType; } - public TokenRequest refreshExtendedToken(Boolean refreshExtendedToken) { - this.refreshExtendedToken = refreshExtendedToken; - return this; - } - - /** - * Whether to generate an extended token along with the access token - * @return refreshExtendedToken - **/ - @Schema(description = "Whether to generate an extended token along with the access token") - public Boolean isRefreshExtendedToken() { - return refreshExtendedToken; - } - - public void setRefreshExtendedToken(Boolean refreshExtendedToken) { - this.refreshExtendedToken = refreshExtendedToken; - } - - @Override public boolean equals(java.lang.Object o) { if (this == o) { @@ -168,13 +146,12 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.clientId, tokenRequest.clientId) && Objects.equals(this.clientSecret, tokenRequest.clientSecret) && Objects.equals(this.redirectUri, tokenRequest.redirectUri) && - Objects.equals(this.grantType, tokenRequest.grantType) && - Objects.equals(this.refreshExtendedToken, tokenRequest.refreshExtendedToken); + Objects.equals(this.grantType, tokenRequest.grantType); } @Override public int hashCode() { - return Objects.hash(code, clientId, clientSecret, redirectUri, grantType, refreshExtendedToken); + return Objects.hash(code, clientId, clientSecret, redirectUri, grantType); } @@ -188,7 +165,6 @@ public String toString() { sb.append(" clientSecret: ").append(toIndentedString(clientSecret)).append("\n"); sb.append(" redirectUri: ").append(toIndentedString(redirectUri)).append("\n"); sb.append(" grantType: ").append(toIndentedString(grantType)).append("\n"); - sb.append(" refreshExtendedToken: ").append(toIndentedString(refreshExtendedToken)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/src/main/java/io/swagger/client/api/InstrumentsApi.java b/src/main/java/io/swagger/client/api/InstrumentsApi.java new file mode 100644 index 0000000..f850587 --- /dev/null +++ b/src/main/java/io/swagger/client/api/InstrumentsApi.java @@ -0,0 +1,233 @@ +/* + * OpenAPI definition + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: v0 + * + * + * 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.SearchInstrumentResponse; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class InstrumentsApi { + private ApiClient apiClient; + private Map headers; + + public InstrumentsApi() { + this(Configuration.getDefaultApiClient()); + } + + public InstrumentsApi(ApiClient apiClient) { + this.apiClient = apiClient; + } + + public ApiClient getApiClient() { + return apiClient; + } + + public void setApiClient(ApiClient apiClient) { + this.apiClient = apiClient; + } + + public void setHeadersOverrides(Map headers) { + this.headers = headers; + } + + /** + * Build call for searchInstrument + * @param query natural language query (required) + * @param exchanges Comma separated exchanges (optional) + * @param segments Comma separated segments (optional) + * @param instrumentTypes Comma separated instrument types (optional) + * @param expiry expiry in format: yyyy-MM-dd (optional) + * @param atmOffset page number greater than or equal to 1 (optional) + * @param pageNumber ATM offset number for queries like ATM, ATM+1, ATM-1, etc. (optional, default to 1) + * @param records no of records in a single page (optional, default to 10) + * @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 searchInstrumentCall(Object query, Object exchanges, Object segments, Object instrumentTypes, Object expiry, Object atmOffset, Object pageNumber, Object records, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { + Object localVarPostBody = null; + + // create path and map variables + String localVarPath = "/v2/instruments/search"; + + List localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); + if (query != null) + localVarQueryParams.addAll(apiClient.parameterToPair("query", query)); + if (exchanges != null) + localVarQueryParams.addAll(apiClient.parameterToPair("exchanges", exchanges)); + if (segments != null) + localVarQueryParams.addAll(apiClient.parameterToPair("segments", segments)); + if (instrumentTypes != null) + localVarQueryParams.addAll(apiClient.parameterToPair("instrument_types", instrumentTypes)); + if (expiry != null) + localVarQueryParams.addAll(apiClient.parameterToPair("expiry", expiry)); + if (atmOffset != null) + localVarQueryParams.addAll(apiClient.parameterToPair("atm_offset", atmOffset)); + if (pageNumber != null) + localVarQueryParams.addAll(apiClient.parameterToPair("page_number", pageNumber)); + if (records != null) + localVarQueryParams.addAll(apiClient.parameterToPair("records", records)); + + Map localVarHeaderParams = new HashMap(); + + 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" }; + if (headers != null) { + localVarHeaderParams.putAll(headers); + } + return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); + } + + @SuppressWarnings("rawtypes") + private com.squareup.okhttp.Call searchInstrumentValidateBeforeCall(Object query, Object exchanges, Object segments, Object instrumentTypes, Object expiry, Object atmOffset, Object pageNumber, Object records, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { + // verify the required parameter 'query' is set + if (query == null) { + throw new ApiException("Missing the required parameter 'query' when calling searchInstrument(Async)"); + } + + com.squareup.okhttp.Call call = searchInstrumentCall(query, exchanges, segments, instrumentTypes, expiry, atmOffset, pageNumber, records, progressListener, progressRequestListener); + return call; + + + + + + } + + /** + * Search instruments + * This API provides the functionality to retrieve the instrument details for searched query + * @param query natural language query (required) + * @param exchanges Comma separated exchanges (optional) + * @param segments Comma separated segments (optional) + * @param instrumentTypes Comma separated instrument types (optional) + * @param expiry expiry in format: yyyy-MM-dd (optional) + * @param atmOffset page number greater than or equal to 1 (optional) + * @param pageNumber ATM offset number for queries like ATM, ATM+1, ATM-1, etc. (optional, default to 1) + * @param records no of records in a single page (optional, default to 10) + * @return SearchInstrumentResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public SearchInstrumentResponse searchInstrument(Object query, Object exchanges, Object segments, Object instrumentTypes, Object expiry, Object atmOffset, Object pageNumber, Object records) throws ApiException { + ApiResponse resp = searchInstrumentWithHttpInfo(query, exchanges, segments, instrumentTypes, expiry, atmOffset, pageNumber, records); + return resp.getData(); + } + + /** + * Search instruments + * This API provides the functionality to retrieve the instrument details for searched query + * @param query natural language query (required) + * @param exchanges Comma separated exchanges (optional) + * @param segments Comma separated segments (optional) + * @param instrumentTypes Comma separated instrument types (optional) + * @param expiry expiry in format: yyyy-MM-dd (optional) + * @param atmOffset page number greater than or equal to 1 (optional) + * @param pageNumber ATM offset number for queries like ATM, ATM+1, ATM-1, etc. (optional, default to 1) + * @param records no of records in a single page (optional, default to 10) + * @return ApiResponse<SearchInstrumentResponse> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse searchInstrumentWithHttpInfo(Object query, Object exchanges, Object segments, Object instrumentTypes, Object expiry, Object atmOffset, Object pageNumber, Object records) throws ApiException { + com.squareup.okhttp.Call call = searchInstrumentValidateBeforeCall(query, exchanges, segments, instrumentTypes, expiry, atmOffset, pageNumber, records, null, null); + Type localVarReturnType = new TypeToken(){}.getType(); + return apiClient.execute(call, localVarReturnType); + } + + /** + * Search instruments (asynchronously) + * This API provides the functionality to retrieve the instrument details for searched query + * @param query natural language query (required) + * @param exchanges Comma separated exchanges (optional) + * @param segments Comma separated segments (optional) + * @param instrumentTypes Comma separated instrument types (optional) + * @param expiry expiry in format: yyyy-MM-dd (optional) + * @param atmOffset page number greater than or equal to 1 (optional) + * @param pageNumber ATM offset number for queries like ATM, ATM+1, ATM-1, etc. (optional, default to 1) + * @param records no of records in a single page (optional, default to 10) + * @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 searchInstrumentAsync(Object query, Object exchanges, Object segments, Object instrumentTypes, Object expiry, Object atmOffset, Object pageNumber, Object records, 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 = searchInstrumentValidateBeforeCall(query, exchanges, segments, instrumentTypes, expiry, atmOffset, pageNumber, records, progressListener, progressRequestListener); + Type localVarReturnType = new TypeToken(){}.getType(); + apiClient.executeAsync(call, localVarReturnType, callback); + return call; + } +} diff --git a/src/main/java/io/swagger/client/api/LoginApi.java b/src/main/java/io/swagger/client/api/LoginApi.java index c31961d..6af2aa8 100644 --- a/src/main/java/io/swagger/client/api/LoginApi.java +++ b/src/main/java/io/swagger/client/api/LoginApi.java @@ -628,148 +628,4 @@ public void onRequestProgress(long bytesWritten, long contentLength, boolean don apiClient.executeAsync(call, localVarReturnType, callback); return call; } - - // Overloaded token methods with refreshExtendedToken - - public com.squareup.okhttp.Call tokenCall(String apiVersion, String code, String clientId, String clientSecret, String redirectUri, String grantType, Boolean refreshExtendedToken, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - Object localVarPostBody = null; - - String localVarPath = "/v2/login/authorization/token"; - - 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(); - if (code != null) - localVarFormParams.put("code", code); - if (clientId != null) - localVarFormParams.put("client_id", clientId); - if (clientSecret != null) - localVarFormParams.put("client_secret", clientSecret); - if (redirectUri != null) - localVarFormParams.put("redirect_uri", redirectUri); - if (grantType != null) - localVarFormParams.put("grant_type", grantType); - if (refreshExtendedToken != null) - localVarFormParams.put("refresh_extended_token", refreshExtendedToken); - - final String[] localVarAccepts = { - "application/json", "*/*" - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); - - final String[] localVarContentTypes = { - "application/x-www-form-urlencoded" - }; - 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[] { }; - return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); - } - - @SuppressWarnings("rawtypes") - private com.squareup.okhttp.Call tokenValidateBeforeCall(String apiVersion, String code, String clientId, String clientSecret, String redirectUri, String grantType, Boolean refreshExtendedToken, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { - if (apiVersion == null) { - throw new ApiException("Missing the required parameter ‘apiVersion’ when calling token(Async)"); - } - - com.squareup.okhttp.Call call = tokenCall(apiVersion, code, clientId, clientSecret, redirectUri, grantType, refreshExtendedToken, progressListener, progressRequestListener); - return call; - } - - /** - * Get token API - * This API provides the functionality to obtain opaque token from authorization_code exchange and also provides the user’s profile in the same response. - * @param apiVersion API Version Header (required) - * @param code (optional) - * @param clientId (optional) - * @param clientSecret (optional) - * @param redirectUri (optional) - * @param grantType (optional) - * @param refreshExtendedToken (optional) - * @return TokenResponse - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public TokenResponse token(String apiVersion, String code, String clientId, String clientSecret, String redirectUri, String grantType, Boolean refreshExtendedToken) throws ApiException { - ApiResponse resp = tokenWithHttpInfo(apiVersion, code, clientId, clientSecret, redirectUri, grantType, refreshExtendedToken); - return resp.getData(); - } - - /** - * Get token API - * This API provides the functionality to obtain opaque token from authorization_code exchange and also provides the user’s profile in the same response. - * @param apiVersion API Version Header (required) - * @param code (optional) - * @param clientId (optional) - * @param clientSecret (optional) - * @param redirectUri (optional) - * @param grantType (optional) - * @param refreshExtendedToken (optional) - * @return ApiResponse<TokenResponse> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse tokenWithHttpInfo(String apiVersion, String code, String clientId, String clientSecret, String redirectUri, String grantType, Boolean refreshExtendedToken) throws ApiException { - com.squareup.okhttp.Call call = tokenValidateBeforeCall(apiVersion, code, clientId, clientSecret, redirectUri, grantType, refreshExtendedToken, null, null); - Type localVarReturnType = new TypeToken(){}.getType(); - return apiClient.execute(call, localVarReturnType); - } - - /** - * Get token API (asynchronously) - * This API provides the functionality to obtain opaque token from authorization_code exchange and also provides the user’s profile in the same response. - * @param apiVersion API Version Header (required) - * @param code (optional) - * @param clientId (optional) - * @param clientSecret (optional) - * @param redirectUri (optional) - * @param grantType (optional) - * @param refreshExtendedToken (optional) - * @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 tokenAsync(String apiVersion, String code, String clientId, String clientSecret, String redirectUri, String grantType, Boolean refreshExtendedToken, 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 = tokenValidateBeforeCall(apiVersion, code, clientId, clientSecret, redirectUri, grantType, refreshExtendedToken, progressListener, progressRequestListener); - Type localVarReturnType = new TypeToken(){}.getType(); - apiClient.executeAsync(call, localVarReturnType, callback); - return call; - } } diff --git a/src/test/java/com/upstox/sanity/InstrumentSearchTest.java b/src/test/java/com/upstox/sanity/InstrumentSearchTest.java new file mode 100644 index 0000000..20192c0 --- /dev/null +++ b/src/test/java/com/upstox/sanity/InstrumentSearchTest.java @@ -0,0 +1,69 @@ +package com.upstox.sanity; + +import com.upstox.ApiClient; +import com.upstox.ApiException; +import com.upstox.Configuration; +import com.upstox.api.SearchInstrumentResponse; +import com.upstox.auth.OAuth; +import io.swagger.client.api.InstrumentsApi; + +public class InstrumentSearchTest { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + + OAuth OAUTH2 = (OAuth) defaultClient.getAuthentication("OAUTH2"); + OAUTH2.setAccessToken(DataToken.accessToken); + + InstrumentsApi apiInstance = new InstrumentsApi(); + + // Basic search with just query + try { + SearchInstrumentResponse result = apiInstance.searchInstrument("Nifty 50", null, null, null, null, null, null, null); + System.out.println(result); + } catch (ApiException e) { + System.out.println("Exception when calling InstrumentsApi#searchInstrument"); + System.out.println("Status code: " + e.getCode()); + System.out.println("Error message: " + e.getResponseBody()); + } + + // Search with exchange filter + try { + SearchInstrumentResponse result = apiInstance.searchInstrument("Reliance", "NSE", null, null, null, null, null, null); + System.out.println(result); + } catch (ApiException e) { + System.out.println("Exception when calling InstrumentsApi#searchInstrument with exchange"); + System.out.println("Status code: " + e.getCode()); + System.out.println("Error message: " + e.getResponseBody()); + } + + // Search with segment filter + try { + SearchInstrumentResponse result = apiInstance.searchInstrument("TCS", null, "EQ", null, null, null, null, null); + System.out.println(result); + } catch (ApiException e) { + System.out.println("Exception when calling InstrumentsApi#searchInstrument with segment"); + System.out.println("Status code: " + e.getCode()); + System.out.println("Error message: " + e.getResponseBody()); + } + + // Search with instrument type filter + try { + SearchInstrumentResponse result = apiInstance.searchInstrument("Nifty", null, null, "INDEX", null, null, null, null); + System.out.println(result); + } catch (ApiException e) { + System.out.println("Exception when calling InstrumentsApi#searchInstrument with instrumentTypes"); + System.out.println("Status code: " + e.getCode()); + System.out.println("Error message: " + e.getResponseBody()); + } + + // Search with pagination + try { + SearchInstrumentResponse result = apiInstance.searchInstrument("HDFC", null, null, null, null, null, 1, 5); + System.out.println(result); + } catch (ApiException e) { + System.out.println("Exception when calling InstrumentsApi#searchInstrument with pagination"); + System.out.println("Status code: " + e.getCode()); + System.out.println("Error message: " + e.getResponseBody()); + } + } +} diff --git a/src/test/java/com/upstox/sanity/TokenTest.java b/src/test/java/com/upstox/sanity/TokenTest.java index 5069119..c60b08a 100644 --- a/src/test/java/com/upstox/sanity/TokenTest.java +++ b/src/test/java/com/upstox/sanity/TokenTest.java @@ -14,7 +14,7 @@ public static void main(String[] args) { String redirectUri = "{redirect_url}"; String grantType = "authorization_code"; try { - TokenResponse result = apiInstance.token(apiVersion, code, clientId, clientSecret, redirectUri, grantType,true); + TokenResponse result = apiInstance.token(apiVersion, code, clientId, clientSecret, redirectUri, grantType); System.out.println(result); } catch (ApiException e) { if(!e.getResponseBody().contains("UDAPI100069")){ diff --git a/src/test/java/io/swagger/client/api/InstrumentsApiTest.java b/src/test/java/io/swagger/client/api/InstrumentsApiTest.java new file mode 100644 index 0000000..6ad7c59 --- /dev/null +++ b/src/test/java/io/swagger/client/api/InstrumentsApiTest.java @@ -0,0 +1,57 @@ +/* + * OpenAPI definition + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) + * + * OpenAPI spec version: v0 + * + * + * 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.api.ApiGatewayErrorResponse; +import com.upstox.api.SearchInstrumentResponse; +import org.junit.Test; +import org.junit.Ignore; + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + * API tests for InstrumentsApi + */ +@Ignore +public class InstrumentsApiTest { + + private final InstrumentsApi api = new InstrumentsApi(); + + /** + * Search instruments + * + * This API provides the functionality to retrieve the instrument details for searched query + * + * @throws Exception + * if the Api call fails + */ + @Test + public void searchInstrumentTest() throws Exception { + Object query = null; + Object exchanges = null; + Object segments = null; + Object instrumentTypes = null; + Object expiry = null; + Object atmOffset = null; + Object pageNumber = null; + Object records = null; + SearchInstrumentResponse response = api.searchInstrument(query, exchanges, segments, instrumentTypes, expiry, atmOffset, pageNumber, records); + + // TODO: test validations + } +}