Skip to content

This library helps you get started with integration of your app to XTS OMS to place orders and query trades and other information.

Notifications You must be signed in to change notification settings

AshutoshBuilds/xts-interactive-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XTS-Interactive-API

Welcome to the XTS-Interactive-API SDK, This repository is Official Node.js library for Symphony XTS-Interactive-API.

API Documentation for XTS-trading API can be found in the below link.

https://symphonyfintech.com/xts-trading-front-end-api/

The XTS Trading API provides developer, data-scientist, financial analyst and investor the functionality necessary to create automated trading strategies, as well as other trading related applications with support of XTS OEMS hosted by Financial Institutions to trade with Indian electronic exchanges.

With the use of the socket.io-client library (v4.x), the API has streaming capability and will push data notifications in a JSON format. Your application can place orders and receive real-time trade notification.

There is also an examples folder available which illustrates how to create a connection to XTS OEMS hosted by Brokers to subscribe to real-time events. Please request for apikeys with Symphony Fintech developer support team to start integrating your application with XTS OEMS.

Installation

npm install xts-interactive-api

Usage

Access the interactive component of xts-interactive-api like below.

var XTSInteractive = require('xts-interactive-api').Interactive;

Creating the instance of xtsInteractive

xtsInteractive = new XTSInteractive("https://api.symphonyfintech.com");   

call the login API to generate the token

var loginRequest ={
	"userID": "PAVAN",
	"password": "Abcd@123",
	"publicKey": "5a75a3616cabe678",
	"source": "WEBAPI",
}

let logIn = await xtsInteractive.logIn(loginRequest);

Once the token is generated you can call any api provided in the documentation. All API's are easy to integrate and implemented with async-await mechanism. Below is the sample Code snippet which calls the balance API.

let balance = await xtsInteractive.getBalance();

console.log(balance);

Alternatively, if you already have a valid session token and user ID (e.g., from a previous session or a different authentication mechanism), you can initialize the SDK using loginWithToken:

// Assuming xtsInteractive is already instantiated: const xtsInteractive = new XTSInteractive("YOUR_API_URL_OR_LEAVE_UNDEFINED_FOR_DEFAULT");
const userIDForTokenLogin = "YOUR_USER_ID";
const existingToken = "YOUR_EXISTING_TOKEN";

try {
  const loginResponseWithToken = await xtsInteractive.loginWithToken(userIDForTokenLogin, existingToken);
  if (loginResponseWithToken.type === 'success') {
    console.log("Successfully logged in with token.");
    // You can now use other API methods, e.g., xtsInteractive.getProfile();
  } else {
    console.error("Failed to login with token:", loginResponseWithToken);
  }
} catch (error) {
  console.error("Error during loginWithToken:", error);
}

Instantiating the XTSInteractiveWS

This component provides functionality to access the socket related events. All real-time events can be registered via XTSInteractiveWS. After token is generated, you can access the socket component and instantiate the socket Instance and call the init method of the socket like below

var XTSInteractiveWS = require('xts-interactive-api').WS;
xtsInteractiveWS = new XTSInteractiveWS("https://api.symphonyfintech.com");
var socketInitRequest = {
	userID: "PAVAN",
	token: logIn.result.token   // Token Generated after successful LogIn
}
xtsInteractiveWS.init(socketInitRequest);

You can now register events to listen to the real time order and trade updates and will be receiving the json objects in the response.

xtsInteractiveWS.onConnect((connectData) => {
	console.log(connectData);
});
xtsInteractiveWS.onJoined((joinedData) => {
	console.log(joinedData);    
});
xtsInteractiveWS.onError((errorData) => {
	console.log(errorData); 
});
xtsInteractiveWS.onDisconnect((disconnectData) => {   
	console.log(disconnectData);
});
xtsInteractiveWS.onOrder((orderData) => {
	console.log(orderData);
});
xtsInteractiveWS.onTrade((tradeData) => {
	console.log(tradeData);
});
xtsInteractiveWS.onPosition((positionData) => {
	console.log(positionData);
});
xtsInteractiveWS.onLogout((logoutData) => {
	console.log(logoutData);
});

Detailed explanation of API and socket related events

Below is the brief information related to APIs provided by XTS-Interactive-API SDK.

Orders API

placeOrder

Calls POST /order.

let response = await xtsInteractive.placeOrder({
	exchangeSegment: xtsInteractive.exchangeInfo.NSECM,
	exchangeInstrumentID: 22,
	productType: xtsInteractive.productTypes.MIS,
	orderType: xtsInteractive.orderTypes.Limit,
	orderSide: xtsInteractive.orderSide.BUY,
	timeInForce: xtsInteractive.dayOrNet.DAY,
	disclosedQuantity: 0,
	orderQuantity: 20,
	limitPrice: 1500.00,
	stopPrice: 1600.00,
	orderUniqueIdentifier: "45485"
});

modifyOrder

Calls PUT /order.

let response = await xtsInteractive.modifyOrder({
	appOrderID: 1991237756,
	modifiedProductType: xtsInteractive.productTypes.NRML,
	modifiedOrderType: xtsInteractive.orderTypes.Limit,
	modifiedOrderQuantity: 100,
	modifiedDisclosedQuantity: 0,
	modifiedLimitPrice: 300,
	modifiedStopPrice: 300,
	modifiedTimeInForce: xtsInteractive.dayOrNet.DAY,
	orderUniqueIdentifier: "5656"
});

cancelOrder

Calls DELETE /order.

let response = await xtsInteractive.cancelOrder({
	appOrderID: 1828071433,
	orderUniqueIdentifier: 155151
});

placeCoverOrder

Calls POST /order/cover.

let response = await xtsInteractive.placeCoverOrder({
	exchangeSegment: xtsInteractive.exchangeInfo.NSECM,
	exchangeInstrumentID: 22,
	orderSide: xtsInteractive.orderSide.BUY,
	orderQuantity: 2,
	disclosedQuantity: 2,
	limitPrice: 2054,
	stopPrice: 2054,
	orderUniqueIdentifier: "45485"
});

exitCoverOrder

Calls PUT /order/cover.

let response = await xtsInteractive.exitCoverOrder({ appOrderID: "2426016103" });

getOrderBook

calls GET /order

let response = await xtsInteractive.getOrderBook();

getTradeBook

calls GET /order/trade

let response = await xtsInteractive.getTradeBook();

Positions API

getPositions

calls GET /portfolio/position

let response = await xtsInteractive.getPositions( {
	dayOrNet: xtsInteractive.dayOrNet.DAY
});

positionConversion

Calls PUT /portfolio/position/convert

let response = await xtsInteractive.positionConversion({
	appOrderID: 1991237756,
	executionID: 1556,
	oldProductType: xtsInteractive.productTypes.NRML,
	newProductType: xtsInteractive.productTypes.MIS
});

squareOff

Calls PUT /portfolio/squareoff

let response = await xtsInteractive.squareOff({
	exchangeSegment: xtsInteractive.exchangeInfo.NSECM,
	exchangeInstrumentID: 22,
	productType: xtsInteractive.productTypes.NRML,
	squareoffMode: xtsInteractive.positionSqureOffMode.DayWise,
	positionSquareOffQuantityType: xtsInteractive.positionSquareOffQuantityType.ExactQty,
	squareOffQtyValue: 5
});

Holdings API

getHoldings

Calls GET /portfolio/holding

let response = await xtsInteractive.getHoldings();

Balance API

getBalance

Calls GET /users/balance

let response = await xtsInteractive.getBalance();

Profile API

getProfile

Calls GET /users/profile

let response = await xtsInteractive.getProfile();

Below is the brief information related to streaming events provided by XTS-Interactive-API SDK.

xtsInteractiveWS.init(socketInitRequest); // Init the socket instance
xtsInteractiveWS.onConnect((connectData) => {}); //registering for Connect event
xtsInteractiveWS.onJoined((joinedData) => {});//registering for Joined event
xtsInteractiveWS.onError((errorData) => {});//registering for Error event
xtsInteractiveWS.onDisconnect((disconnectData) => { });//registering for Disconnect event
xtsInteractiveWS.onOrder((orderData) => {});//registering for Order event
xtsInteractiveWS.onTrade((tradeData) => {});//registering for Trade event
xtsInteractiveWS.onPosition((positionData) => { });//registering for Position event
xtsInteractiveWS.onLogout((logoutData) => {});//registering for Logout event

We do have a market data component which will provide the streaming of our real-time streaming market data. For more info please check the following link.

https://symphonyfintech.com/xts-market-data-front-end-api/

getOrderHistory

Retrieves the history for a specific order.

const appOrderID = "YOUR_APP_ORDER_ID"; // Replace with the actual AppOrderID
let response = await xtsInteractive.getOrderHistory(appOrderID);
console.log(response);

Testing

This library uses Jest for testing. To run the tests:

  1. Ensure you have installed the development dependencies: npm install (if you haven't already).
  2. Run the test script: npm test

This will execute all test suites and provide a summary of the results.

About

This library helps you get started with integration of your app to XTS OMS to place orders and query trades and other information.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%