upstox-js-sdk
Version:
The official Node Js client for communicating with the Upstox API
333 lines (318 loc) • 16.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.OrderApiV3 = void 0;
var _ApiClient = require("../ApiClient");
var _ApiGatewayErrorResponse = require("../model/ApiGatewayErrorResponse");
var _CancelOrderV3Response = require("../model/CancelOrderV3Response");
var _GetGttOrderResponse = require("../model/GetGttOrderResponse");
var _GttCancelOrderRequest = require("../model/GttCancelOrderRequest");
var _GttModifyOrderRequest = require("../model/GttModifyOrderRequest");
var _GttPlaceOrderRequest = require("../model/GttPlaceOrderRequest");
var _GttTriggerOrderResponse = require("../model/GttTriggerOrderResponse");
var _ModifyOrderRequest = require("../model/ModifyOrderRequest");
var _ModifyOrderV3Response = require("../model/ModifyOrderV3Response");
var _PlaceOrderV3Request = require("../model/PlaceOrderV3Request");
var _PlaceOrderV3Response = require("../model/PlaceOrderV3Response");
/*
* 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
*
* Swagger Codegen version: 3.0.66
*
* Do not edit the class manually.
*
*/
/**
* OrderControllerV3 service.
* @module api/OrderControllerV3Api
* @version v0
*/
class OrderApiV3 {
/**
* Constructs a new OrderControllerV3Api.
* @alias module:api/OrderControllerV3Api
* @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.ApiClient.instance;
}
mapToGttOrderRequest(data) {
let obj = {};
if (data) {
if (data.hasOwnProperty('quantity')) obj.quantity = _ApiClient.ApiClient.convertToType(data['quantity'], 'Number');
if (data.hasOwnProperty('product')) obj.product = _ApiClient.ApiClient.convertToType(data['product'], 'String');
if (data.hasOwnProperty('type')) obj.type = _ApiClient.ApiClient.convertToType(data['type'], 'String');
if (data.hasOwnProperty('rules')) {
obj.rules = [];
data['rules'].forEach(userRule => {
const rule = {};
if (userRule.hasOwnProperty('strategy')) rule.strategy = _ApiClient.ApiClient.convertToType(userRule['strategy'], 'String');
if (userRule.hasOwnProperty('triggerType')) rule.trigger_type = _ApiClient.ApiClient.convertToType(userRule['triggerType'], 'String');
if (userRule.hasOwnProperty('triggerPrice')) rule.trigger_price = _ApiClient.ApiClient.convertToType(userRule['triggerPrice'], 'Number');
if (userRule.hasOwnProperty('trailingGap')) rule.trailing_gap = _ApiClient.ApiClient.convertToType(userRule['trailingGap'], 'Number');
obj.rules.push(rule);
});
}
if (data.hasOwnProperty('instrumentToken')) obj.instrument_token = _ApiClient.ApiClient.convertToType(data['instrumentToken'], 'String');
if (data.hasOwnProperty('transactionType')) obj.transaction_type = _ApiClient.ApiClient.convertToType(data['transactionType'], 'String');
if (data.hasOwnProperty('gttOrderId')) obj.gtt_order_id = _ApiClient.ApiClient.convertToType(data['gttOrderId'], 'String');
}
return obj;
}
/**
* Callback function to receive the result of the cancelGTTOrder operation.
* @callback moduleapi/OrderControllerV3Api~cancelGTTOrderCallback
* @param {String} error Error message, if any.
* @param {module:model/GttTriggerOrderResponse{ data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Cancel GTT order
* This API allows you to cancel GTT orders.
* @param {module:model/GttCancelOrderRequest} body
* @param {module:api/OrderControllerV3Api~cancelGTTOrderCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link <&vendorExtensions.x-jsdoc-type>}
*/
cancelGTTOrder(body, callback) {
let postBody = this.mapToGttOrderRequest(body);
// verify the required parameter 'body' is set
if (body === undefined || body === null) {
throw new Error("Missing the required parameter 'body' when calling cancelGTTOrder");
}
let pathParams = {};
let queryParams = {};
let headerParams = {};
let formParams = {};
let authNames = ['OAUTH2'];
let contentTypes = ['application/json'];
let accepts = ['*/*', 'application/json'];
let returnType = _GttTriggerOrderResponse.GttTriggerOrderResponse;
return this.apiClient.callApi('/v3/order/gtt/cancel', 'DELETE', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback);
}
/**
* Callback function to receive the result of the cancelOrder operation.
* @callback moduleapi/OrderControllerV3Api~cancelOrderCallback
* @param {String} error Error message, if any.
* @param {module:model/CancelOrderV3Response{ data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* @param {String} orderId
* @param {module:api/OrderControllerV3Api~cancelOrderCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link <&vendorExtensions.x-jsdoc-type>}
*/
cancelOrder(orderId, callback) {
let postBody = null;
// verify the required parameter 'orderId' is set
if (orderId === undefined || orderId === null) {
throw new Error("Missing the required parameter 'orderId' when calling cancelOrder");
}
let pathParams = {};
let queryParams = {
'order_id': orderId
};
let headerParams = {};
let formParams = {};
let authNames = ['OAUTH2'];
let contentTypes = [];
let accepts = ['*/*'];
let returnType = _CancelOrderV3Response.CancelOrderV3Response;
return this.apiClient.callApi('/v3/order/cancel', 'DELETE', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback);
}
/**
* Callback function to receive the result of the getGttOrderDetails operation.
* @callback moduleapi/OrderControllerV3Api~getGttOrderDetailsCallback
* @param {String} error Error message, if any.
* @param {module:model/GetGttOrderResponse{ data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Get GTT order details
* GTT_ORDER_DESCRIPTION
* @param {Object} opts Optional parameters
* @param {String} opts.gttOrderId Unique identifier of the GTT order for which the order history is required
* @param {module:api/OrderControllerV3Api~getGttOrderDetailsCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link <&vendorExtensions.x-jsdoc-type>}
*/
getGttOrderDetails(opts, callback) {
opts = opts || {};
let postBody = null;
let pathParams = {};
let queryParams = {
'gtt_order_id': opts['gttOrderId']
};
let headerParams = {};
let formParams = {};
let authNames = ['OAUTH2'];
let contentTypes = [];
let accepts = ['*/*', 'application/json'];
let returnType = _GetGttOrderResponse.GetGttOrderResponse;
return this.apiClient.callApi('/v3/order/gtt', 'GET', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback);
}
/**
* Callback function to receive the result of the modifyGTTOrder operation.
* @callback moduleapi/OrderControllerV3Api~modifyGTTOrderCallback
* @param {String} error Error message, if any.
* @param {module:model/GttTriggerOrderResponse{ data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Modify GTT order
* This API allows you to modify GTT orders.
* @param {module:model/GttModifyOrderRequest} body
* @param {module:api/OrderControllerV3Api~modifyGTTOrderCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link <&vendorExtensions.x-jsdoc-type>}
*/
modifyGTTOrder(body, callback) {
let postBody = this.mapToGttOrderRequest(body);
// verify the required parameter 'body' is set
if (body === undefined || body === null) {
throw new Error("Missing the required parameter 'body' when calling modifyGTTOrder");
}
let pathParams = {};
let queryParams = {};
let headerParams = {};
let formParams = {};
let authNames = ['OAUTH2'];
let contentTypes = ['application/json'];
let accepts = ['*/*', 'application/json'];
let returnType = _GttTriggerOrderResponse.GttTriggerOrderResponse;
return this.apiClient.callApi('/v3/order/gtt/modify', 'PUT', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback);
}
mapToModifyOrderRequest(data) {
let obj = {};
if (data) {
if (data.hasOwnProperty('quantity')) obj.quantity = _ApiClient.ApiClient.convertToType(data['quantity'], 'Number');
if (data.hasOwnProperty('validity')) obj.validity = _ApiClient.ApiClient.convertToType(data['validity'], 'String');
if (data.hasOwnProperty('price')) obj.price = _ApiClient.ApiClient.convertToType(data['price'], 'Number');
if (data.hasOwnProperty('orderId')) obj.order_id = _ApiClient.ApiClient.convertToType(data['orderId'], 'String');
if (data.hasOwnProperty('orderType')) obj.order_type = _ApiClient.ApiClient.convertToType(data['orderType'], 'String');
if (data.hasOwnProperty('disclosedQuantity')) obj.disclosed_quantity = _ApiClient.ApiClient.convertToType(data['disclosedQuantity'], 'Number');
if (data.hasOwnProperty('triggerPrice')) obj.trigger_price = _ApiClient.ApiClient.convertToType(data['triggerPrice'], 'Number');
}
return obj;
}
/**
* Callback function to receive the result of the modifyOrder operation.
* @callback moduleapi/OrderControllerV3Api~modifyOrderCallback
* @param {String} error Error message, if any.
* @param {module:model/ModifyOrderV3Response{ data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* @param {module:model/ModifyOrderRequest} body
* @param {module:api/OrderControllerV3Api~modifyOrderCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link <&vendorExtensions.x-jsdoc-type>}
*/
modifyOrder(body, callback) {
let postBody = this.mapToModifyOrderRequest(body);
// verify the required parameter 'body' is set
if (body === undefined || body === null) {
throw new Error("Missing the required parameter 'body' when calling modifyOrder");
}
let pathParams = {};
let queryParams = {};
let headerParams = {};
let formParams = {};
let authNames = ['OAUTH2'];
let contentTypes = ['application/json'];
let accepts = ['*/*'];
let returnType = _ModifyOrderV3Response.ModifyOrderV3Response;
return this.apiClient.callApi('/v3/order/modify', 'PUT', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback);
}
mapToPlaceOrderV3Request(data) {
let obj = {};
if (data) {
if (data.hasOwnProperty('quantity')) obj.quantity = _ApiClient.ApiClient.convertToType(data['quantity'], 'Number');
if (data.hasOwnProperty('product')) obj.product = _ApiClient.ApiClient.convertToType(data['product'], 'String');
if (data.hasOwnProperty('validity')) obj.validity = _ApiClient.ApiClient.convertToType(data['validity'], 'String');
if (data.hasOwnProperty('price')) obj.price = _ApiClient.ApiClient.convertToType(data['price'], 'Number');
if (data.hasOwnProperty('tag')) obj.tag = _ApiClient.ApiClient.convertToType(data['tag'], 'String');
if (data.hasOwnProperty('instrumentToken')) obj.instrument_token = _ApiClient.ApiClient.convertToType(data['instrumentToken'], 'String');
if (data.hasOwnProperty('orderType')) obj.order_type = _ApiClient.ApiClient.convertToType(data['orderType'], 'String');
if (data.hasOwnProperty('transactionType')) obj.transaction_type = _ApiClient.ApiClient.convertToType(data['transactionType'], 'String');
if (data.hasOwnProperty('disclosedQuantity')) obj.disclosed_quantity = _ApiClient.ApiClient.convertToType(data['disclosedQuantity'], 'Number');
if (data.hasOwnProperty('triggerPrice')) obj.trigger_price = _ApiClient.ApiClient.convertToType(data['triggerPrice'], 'Number');
if (data.hasOwnProperty('isAmo')) obj.is_amo = _ApiClient.ApiClient.convertToType(data['isAmo'], 'Boolean');
if (data.hasOwnProperty('slice')) obj.is_amo = _ApiClient.ApiClient.convertToType(data['slice'], 'Boolean');
}
return obj;
}
/**
* Callback function to receive the result of the placeGTTOrder operation.
* @callback moduleapi/OrderControllerV3Api~placeGTTOrderCallback
* @param {String} error Error message, if any.
* @param {module:model/GttTriggerOrderResponse{ data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Place GTT order
* This API allows you to place GTT orders.
* @param {module:model/GttPlaceOrderRequest} body
* @param {module:api/OrderControllerV3Api~placeGTTOrderCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link <&vendorExtensions.x-jsdoc-type>}
*/
placeGTTOrder(body, callback) {
let postBody = this.mapToGttOrderRequest(body);
// verify the required parameter 'body' is set
if (body === undefined || body === null) {
throw new Error("Missing the required parameter 'body' when calling placeGTTOrder");
}
let pathParams = {};
let queryParams = {};
let headerParams = {};
let formParams = {};
let authNames = ['OAUTH2'];
let contentTypes = ['application/json'];
let accepts = ['*/*', 'application/json'];
let returnType = _GttTriggerOrderResponse.GttTriggerOrderResponse;
return this.apiClient.callApi('/v3/order/gtt/place', 'POST', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback);
}
/**
* Callback function to receive the result of the placeOrder operation.
* @callback moduleapi/OrderControllerV3Api~placeOrderCallback
* @param {String} error Error message, if any.
* @param {module:model/PlaceOrderV3Response{ data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* @param {module:model/PlaceOrderV3Request} body
* @param {Object} opts Optional parameters
* @param {String} opts.origin
* @param {module:api/OrderControllerV3Api~placeOrderCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link <&vendorExtensions.x-jsdoc-type>}
*/
placeOrder(body, opts, callback) {
opts = opts || {};
let postBody = this.mapToPlaceOrderV3Request(body);
// verify the required parameter 'body' is set
if (body === undefined || body === null) {
throw new Error("Missing the required parameter 'body' when calling placeOrder");
}
if (opts['slice']) {
postBody.slice = opts['slice'];
}
let pathParams = {};
let queryParams = {};
let headerParams = {
'Origin': opts['origin']
};
let formParams = {};
let authNames = ['OAUTH2'];
let contentTypes = ['application/json'];
let accepts = ['*/*'];
let returnType = _PlaceOrderV3Response.PlaceOrderV3Response;
return this.apiClient.callApi('/v3/order/place', 'POST', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback);
}
}
exports.OrderApiV3 = OrderApiV3;