UNPKG

upstox-js-sdk

Version:

The official Node Js client for communicating with the Upstox API

247 lines (209 loc) 9.91 kB
/* * Upstox Developer API * Build your App on the Upstox platform ![Banner](https://api.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 <a href=\"http://account.upstox.com/developer/apps\" target=\"_blank\">account.upstox.com/developer/apps</a>.</br> 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 * * Swagger Codegen version: 3.0.46 * * Do not edit the class manually. * */ import {ApiClient} from "../ApiClient"; import {ApiGatewayErrorResponse} from '../model/ApiGatewayErrorResponse'; import {ConvertPositionRequest} from '../model/ConvertPositionRequest'; import {ConvertPositionResponse} from '../model/ConvertPositionResponse'; import {GetHoldingsResponse} from '../model/GetHoldingsResponse'; import {GetPositionResponse} from '../model/GetPositionResponse'; /** * Portfolio service. * @module api/PortfolioApi * @version v2 */ export class PortfolioApi { /** * Constructs a new PortfolioApi. * @alias module:api/PortfolioApi * @class * @param {module:ApiClient} [apiClient] Optional API client implementation to use, * default to {@link module:ApiClient#instanc e} if unspecified. */ constructor(apiClient) { this.apiClient = apiClient || ApiClient.instance; } /** * Callback function to receive the result of the convertPositions operation. * @callback moduleapi/PortfolioApi~convertPositionsCallback * @param {String} error Error message, if any. * @param {module:model/ConvertPositionResponse{ data The data returned by the service call. * @param {String} response The complete HTTP response. */ mapToConvertPositionRequest(data) { let obj = {}; if (data) { if (data.hasOwnProperty('instrumentToken')) obj.instrument_token = ApiClient.convertToType(data['instrumentToken'], 'String'); if (data.hasOwnProperty('newProduct')) obj.new_product = ApiClient.convertToType(data['newProduct'], 'String'); if (data.hasOwnProperty('oldProduct')) obj.old_product = ApiClient.convertToType(data['oldProduct'], 'String'); if (data.hasOwnProperty('transactionType')) obj.transaction_type = ApiClient.convertToType(data['transactionType'], 'String'); if (data.hasOwnProperty('quantity')) obj.quantity = ApiClient.convertToType(data['quantity'], 'Number'); } return obj; } /** * Convert Positions * Convert the margin product of an open position * @param {module:model/ConvertPositionRequest} body * @param {String} apiVersion API Version Header * @param {module:api/PortfolioApi~convertPositionsCallback} callback The callback function, accepting three arguments: error, data, response * data is of type: {@link <&vendorExtensions.x-jsdoc-type>} */ convertPositions(body, apiVersion, callback) { let postBody = this.mapToConvertPositionRequest(body); // verify the required parameter 'body' is set if (body === undefined || body === null) { throw new Error("Missing the required parameter 'body' when calling convertPositions"); } // verify the required parameter 'apiVersion' is set if (apiVersion === undefined || apiVersion === null) { throw new Error("Missing the required parameter 'apiVersion' when calling convertPositions"); } let pathParams = { }; let queryParams = { }; let headerParams = { 'Api-Version': apiVersion }; let formParams = { }; let authNames = ['OAUTH2']; let contentTypes = ['application/json']; let accepts = ['*/*', 'application/json']; let returnType = ConvertPositionResponse; return this.apiClient.callApi( '/v2/portfolio/convert-position', 'PUT', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback ); } /** * Callback function to receive the result of the getHoldings operation. * @callback moduleapi/PortfolioApi~getHoldingsCallback * @param {String} error Error message, if any. * @param {module:model/GetHoldingsResponse{ data The data returned by the service call. * @param {String} response The complete HTTP response. */ /** * Get Holdings * Fetches the holdings which the user has bought/sold in previous trading sessions. * @param {String} apiVersion API Version Header * @param {module:api/PortfolioApi~getHoldingsCallback} callback The callback function, accepting three arguments: error, data, response * data is of type: {@link <&vendorExtensions.x-jsdoc-type>} */ getHoldings(apiVersion, callback) { let postBody = null; // verify the required parameter 'apiVersion' is set if (apiVersion === undefined || apiVersion === null) { throw new Error("Missing the required parameter 'apiVersion' when calling getHoldings"); } let pathParams = { }; let queryParams = { }; let headerParams = { 'Api-Version': apiVersion }; let formParams = { }; let authNames = ['OAUTH2']; let contentTypes = []; let accepts = ['*/*', 'application/json']; let returnType = GetHoldingsResponse; return this.apiClient.callApi( '/v2/portfolio/long-term-holdings', 'GET', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback ); } /** * Callback function to receive the result of the getMtfPositions operation. * @callback moduleapi/PortfolioApi~getMtfPositionsCallback * @param {String} error Error message, if any. * @param {module:model/GetPositionResponse{ data The data returned by the service call. * @param {String} response The complete HTTP response. */ /** * Get MTF positions * This API allows you to get MTF positions. * @param {module:api/PortfolioApi~getMtfPositionsCallback} callback The callback function, accepting three arguments: error, data, response * data is of type: {@link <&vendorExtensions.x-jsdoc-type>} */ getMtfPositions(callback) { let postBody = null; let pathParams = { }; let queryParams = { }; let headerParams = { }; let formParams = { }; let authNames = ['OAUTH2']; let contentTypes = []; let accepts = ['*/*', 'application/json']; let returnType = GetPositionResponse; return this.apiClient.callApi( '/v3/portfolio/mtf-positions', 'GET', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback ); } /** * Callback function to receive the result of the getPositions operation. * @callback moduleapi/PortfolioApi~getPositionsCallback * @param {String} error Error message, if any. * @param {module:model/GetPositionResponse{ data The data returned by the service call. * @param {String} response The complete HTTP response. */ /** * Get Positions * Fetches the current positions for the user for the current day. * @param {String} apiVersion API Version Header * @param {module:api/PortfolioApi~getPositionsCallback} callback The callback function, accepting three arguments: error, data, response * data is of type: {@link <&vendorExtensions.x-jsdoc-type>} */ getPositions(apiVersion, callback) { let postBody = null; // verify the required parameter 'apiVersion' is set if (apiVersion === undefined || apiVersion === null) { throw new Error("Missing the required parameter 'apiVersion' when calling getPositions"); } let pathParams = { }; let queryParams = { }; let headerParams = { 'Api-Version': apiVersion }; let formParams = { }; let authNames = ['OAUTH2']; let contentTypes = []; let accepts = ['*/*', 'application/json']; let returnType = GetPositionResponse; return this.apiClient.callApi( '/v2/portfolio/short-term-positions', 'GET', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback ); } }