Portfolio Stream Feed WebSocket Client

Hi, I am try to get the Portfolio Stream websocket Feed as the code available in

But connection is established , no data is coming. I have holding position of stocks but No position

Hi @SRIKANTA_1078821 , You need to enable update_types (order, holding, position, gtt), by default only order updates are enabled.

Please check for the update types GitHub - upstox/upstox-nodejs: Official NodeJS library for accessing Upstox APIs

Please try using the latest code as below:

let UpstoxClient = require("upstox-js-sdk");
let defaultClient = UpstoxClient.ApiClient.instance;
var OAUTH2 = defaultClient.authentications["OAUTH2"];
OAUTH2.accessToken = "<ACCESS_TOKEN>";

// Enable all update types: orders, positions, holdings, and GTT orders
const streamer = new UpstoxClient.PortfolioDataStreamer(true, true, true, true);
streamer.connect();

streamer.on("message", (data) => {
  const feed = data.toString("utf-8");
  console.log(feed);
});

Let us know if you still faced the same issue, Thanks

Thanks for Reply.

I tried with that code but still not get any response from API

let UpstoxClient = require(“upstox-js-sdk”);

let defaultClient = UpstoxClient.ApiClient.instance;

var OAUTH2 = defaultClient.authentications[“OAUTH2”];

OAUTH2.accessToken =

“eyJ0eXAiOiJKV1QiLCJrZXlfaWQiOiJza192MS4wIiwiYWxnIjoiSFMyNTYifQ.eyJzdWIiOiIxNTY5NzAiLCJqdGkiOiI2OTFmZTRkNWMwODY2NzU4YmIwMWMzNTQiLCJpc011bHRpQ2xpZW50IjpmYWxzZSwiaXNQbHVzUGxhbiI6ZmFsc2UsImlhdCI6MTc2MzY5Nzg3NywiaXNzIjoidWRhcGktZ2F0ZXdheS1zZXJ2aWNlIiwiZXhwIjoxNzYzNzYyNDAwfQ.GTLVxMPSWW3Xf7PmqXtwv_7T2fOQ_uG0x9_qmvXuK”;

const streamer = new UpstoxClient.PortfolioDataStreamer(true, true, true, true);

streamer.connect(() => {

console.log(“Connected to portfolio feed”);

});

streamer.on(“message”, (data) => {

const feed = data.toString(“utf-8”);

console.log(feed);

});

please reply…..

Hi @SRIKANTA_1078821, Did you try this during market hours? The portfolio feeder provides live updates over WebSocket. If there is no change in your position, you won’t receive any updates.

Please try creating a new position (when order gets completed), exiting an existing one, or converting a position — you should then see the live updates.

If you are looking to fetch the existing position, you can try retrieving it using Get Positions API

Thanks

Yes for current day position is coming. But Holding position is not coming.