Getting ssl eof error..how to fix this..plz help
Can you please DM the code / Python version used
Hello Sir…I have used Python 3.12.3
import time
from fyers_apiv3.FyersWebsocket import data_ws
Initialize an empty dictionary to store the data
data = {}
def onmessage(message, data, ce_otm_strike, pe_otm_strike):
"""
Callback function to handle incoming messages from the FyersDataSocket WebSocket.
Parameters:
message (dict): The received message from the WebSocket.
"""
#print("Response:", message)
global tot_buy_qty
global data
global tot_sell_qty
global symbol
while 'symbol' in message and 'tot_buy_qty' in message and 'tot_sell_qty' in message:
symbol = message['symbol']
total_buy_quantity = message['tot_buy_qty']
total_sell_quantity = message['tot_sell_qty']
if any(strike in symbol for strike in ce_otm_strike + pe_otm_strike):
# Store the data in the dictionary
strike_price = int(symbol.split(':')[1].split('2')[0])
if strike_price in ce_otm_strike:
strike_type = 'CE'
elif strike_price in pe_otm_strike:
strike_type = 'PE'
else:
strike_type = 'Other'
if strike_type not in data:
data[strike_type] = {}
if strike_price not in data[strike_type]:
data[strike_type][strike_price] = {
'Total Buy Quantity': 0,
'Total Sell Quantity': 0
}
data[strike_type][strike_price]['Total Buy Quantity'] += total_buy_quantity
data[strike_type][strike_price]['Total Sell Quantity'] += total_sell_quantity
# Print the updated data
print(data)
def onerror(message):
"""
Callback function to handle WebSocket errors.
Parameters:
message (dict): The error message received from the WebSocket.
"""
print("Error:", message)
def onclose(message):
"""
Callback function to handle WebSocket connection close events.
"""
print("Connection closed:", message)
def onopen():
"""
Callback function to subscribe to data type and symbols upon WebSocket connection.
"""
# Specify the data type and symbols you want to subscribe to
data_type = "SymbolUpdate"
# Subscribe to the specified symbols and data type
symbols = []
for strike in ce_otm_strike:
symbols.append(f"NSE:BANKNIFTY24430{strike}")
for strike in pe_otm_strike:
symbols.append(f"NSE:BANKNIFTY24430{strike}")
fyers.subscribe(symbols=symbols, data_type=data_type)
Keep the socket running to receive real-time data
fyers.keep_running()
Replace the sample access token with your actual access token obtained from Fyers
access_token = client_id+“:”+tk
Create a FyersDataSocket instance with the provided parameters
fyers = data_ws.FyersDataSocket(
access_token=tk, # Access token in the format "appid:accesstoken"
log_path="", # Path to save logs. Leave empty to auto-create logs in the current directory.
litemode=False, # Lite mode disabled. Set to True if you want a lite response.
write_to_file=False, # Save response in a log file instead of printing it.
reconnect=True, # Enable auto-reconnection to WebSocket on disconnection.
on_connect=onopen, # Callback function to subscribe to data upon connection.
on_close=onclose,
)
Establish a connection to the Fyers WebSocket
fyers.connect()
THIS IS MY CODE SIR..
Sirr plz check ur dm..i have shared the code
