Can we fetch current positions with websocket?

Hello,

can we fetch current positions using a socket?

If I ferch manually then I get a timeout error and the data is not consistent.

Position retrieval is exclusively possible through the REST API.

Could you please provide the code you’re using to fetch positions and the accompanying response data?

Hello @Pradeep_Jaiswar ,

It was my code mistake. Data is getting consistent.

Can you please share code for rest api for fetching position data using socket

Please find Python code for Rest API for fetching the position details.

import requests

shortTermPositionsUrl  = "https://api-v2.upstox.com/portfolio/short-term-positions"
accessToken = "{your_access_token}"

headers = {
    "accept": "application/json",
    "Api-Version": "2.0",
    "Content-Type": "application/x-www-form-urlencoded",
    "Authorization" : f"Bearer {accessToken}"
}
response = requests.get(shortTermPositionsUrl, headers=headers)

print(response)

Hello @Pradeep_Jaiswar ,

It looks like same what I am using as of now.

How to implement with socket? Can you please provide an example of that?

Currently using the below code and manually calling function for every second.
image

WebSockets are for real-time and have support for instant updates on orders and market data feeds only.

On the other hand, the Position API exclusively relies on RESTful APIs. It’s important to highlight that WebSocket connections cannot access position details. After placing an order, you can obtain order-related status updates via WebSocket communication immediately.