pya3 icon indicating copy to clipboard operation
pya3 copied to clipboard

Socket is not getting connected

Open Kurukshetran opened this issue 2 years ago • 0 comments

Socket is not getting connected, no callback function is getting triggered. Below is the code.

`from pya3 import *

alice = Aliceblue(user_id='<<USER_ID>>',api_key='<<KEY>>') print(alice.get_session_id())

LTP = 0 socket_opened = False subscribe_flag = False subscribe_list = [] unsubscribe_list = []

def socket_open(): # Socket open callback function print("Connected") global socket_opened socket_opened = True if subscribe_flag: # This is used to resubscribe the script when reconnect the socket. alice.subscribe(subscribe_list)

def socket_close(): # On Socket close this callback function will trigger global socket_opened, LTP socket_opened = False LTP = 0 print("Closed")

def socket_error(message): # Socket Error Message will receive in this callback function global LTP LTP = 0 print("Error :", message)

def feed_data(message): # Socket feed data will receive in this callback function global LTP, subscribe_flag feed_message = json.loads(message) if feed_message["t"] == "ck": print("Connection Acknowledgement status :%s (Websocket Connected)" % feed_message["s"]) subscribe_flag = True print("subscribe_flag :", subscribe_flag) print("-------------------------------------------------------------------------------") pass elif feed_message["t"] == "tk": print("Token Acknowledgement status :%s " % feed_message) print("-------------------------------------------------------------------------------") pass else: print("Feed :", feed_message) LTP = feed_message[ 'lp'] if 'lp' in feed_message else LTP # If LTP in the response it will store in LTP variable

alice.start_websocket(socket_open_callback=socket_open, socket_close_callback=socket_close, socket_error_callback=socket_error, subscription_callback=feed_data, run_in_background=True,market_depth=False)

print(alice)

while not socket_opened: pass

subscribe_list = [alice.get_instrument_by_token('INDICES', 26000)] alice.subscribe(subscribe_list) print(alice)`

Kurukshetran avatar May 31 '23 12:05 Kurukshetran