How to set stop loss after the order

use this websocket Api Link :-

  1. Portfolio Stream Feed Authorize Url | Upstox Developer API
  2. Portfolio Stream Feed | Upstox Developer API

can anyone please help set stop loss

using this code:-
useEffect(() => {
const url =
“ahttps://api.upstox.com/v2/feed/portfolio-stream-feed/authorize?update_types=order%2Cposition%2Cholding”;
const headers = {
“Api-Version”: “2.0”,
Accept: “application/json”,
Authorization: "Bearer " + token,
};

// Fetching WebSocket URL
fetch(url, {
  method: "GET",
  headers: headers,
})
  .then((response) => {
    if (!response.ok) {
      throw new Error(
        `Network response was not ok: ${response.statusText}`
      );
    }
    return response.json();
  })
  .then((data) => {
    // Initialize WebSocket with URL obtained from API
    const ws = new WebSocket(data.data.authorized_redirect_uri);

    ws.onopen = () => {
      setIsConnected(true);
      console.log("WebSocket connection established");
    };

    ws.onmessage = (event) => {
      console.log("Received message:", event.data);
      setFeedData((currentData) => [...currentData, event.data]);
      console.log('event.data -: ', event.data)
      console.log('feedData -: ', feedData)
    };

    ws.onclose = () => {
      setIsConnected(false);
      console.log("Disconnected");
    };

    ws.onerror = (error) => {
      setIsConnected(false);
      console.log("WebSocket error:", error);
    };

    // Cleanup function to close WebSocket connection when component unmounts
    return () => {
      ws.close();
    };
  })
  .catch((error) => {
    console.error(error.message);
  });

}, [token]);

websocket connect is succeeding. But how to set the stop loss

Hi @Gurpreet_46880926
It is not possible to set a stop loss directly through the WebSocket. You need to place a Stop Loss order separately or modify your existing order accordingly.

Alternatively, you can place a GTT (Good Till Triggered) order, which allows you to include a stop loss leg.
For more details, refer to the documentation:

Thanks!


this is my upstox portal postion and postion api response screenshot
can you please help set stop loss using any api