How to get open, high, low, close value in pandas dataframe from websocket api
i will give you one sample code, modify the custom function to get the required data, currently i gave only for open price,
from fyers_api.Websocket import ws
import time
import threading
access_token = "" # appid:accesstoken
fs = ws.FyersSocket(access_token=access_token,run_background=False,log_path="")
def run_process_foreground_symbol_data(access_token):
'''This function is used for running the symbolData in foreground
1. log_path here is configurable this specifies where the output will be stored for you
2. data_type == symbolData this specfies while using this function you will be able to connect to symbolwebsocket to get the symbolData
3. run_background = False specifies that the process will be running in foreground'''
data_type = "symbolData"
symbol = ["NSE:SBIN-EQ"]
fs = ws.FyersSocket(access_token=access_token,run_background=False,log_path="")
fs.websocket_data = custom_message
fs.subscribe(symbol=symbol,data_type=data_type)
fs.keep_running()
def custom_message(msg):
print (f"open:{msg[0]['open_price']}")
def main():
run_process_foreground_symbol_data(access_token)
if __name__ == '__main__':
main()
Thanks Bro
Web socket data feed if considered for API call limit ???
Hey, No not considered under API call limit.
Sir, how to get LTP of 2 symbol in a variable, I altered your above code in symbol and custom_message function as below
symbol = [“NSE:SBIN-EQ”, “NSE:NIFTY22SEP17000CE”]
def custom_message(msg):
LTPFirstSymbol = msg[0]['ltp']
LTPSecondSymbol = msg[1]['ltp']}")
but I am getting error
ERROR:websocket:error from callback <function FyersSocket.init_connection.. at 0x7f175abeb830>: list index out of range
unable to pass 2 variable value to next logic .
Please help