Does any body have idea how to extract Positions live data to excel… so that it would be easy to adjust positions based on LTP …
Hey Laxman,
I wrote a simple script for for extracting ltp data from websockets and saving it into a csv file. You may modify it according to your convenience.
from fyers_api.websocket import ws
import csv
access_token = "" #appid:accesstoken
data_type = "symbolData"
symbol = ["NSE:SBIN-EQ"]
with open('test.csv', 'w') as file:
writer = csv.writer(file)
writer.writerow(["LTP"])
def custom_message(self):
try:
writer.writerow([str(self.response[0]["ltp"])])
except Exception:
pass
ws.FyersSocket.websocket_data = custom_message
fyersSocket = ws.FyersSocket(access_token=access_token, data_type=data_type,symbol=symbol)
val = True
while(val==True):
data = fyersSocket.subscribe()
val = False
fyersSocket.unsubscribe(symbol=symbol)