krishnavelu / alice_blue

Official Python library for Alice Blue API trading
GNU General Public License v3.0
134 stars 82 forks source link

Websocket not able to fetch the data #490

Closed abhishekanne closed 1 year ago

abhishekanne commented 1 year ago

I tried the exact same example as in the readme file for fetching the tick data however nothing was happening no callback function getting called. I have to manually close the app and then produce this error. I can able to fetch the other API correctly.

File "F:\alicebluetest.py", line 66, in alice.subscribe(alice.get_instrument_by_symbol('NSE', 'TATASTEEL-EQ'), LiveFeedType.TICK_DATA) File "C:\Users\Hp\AppData\Local\Programs\Python\Python311\Lib\site-packages\alice_blue\alice_blue.py", line 791, in subscribe self.__ws_send(data) File "C:\Users\Hp\AppData\Local\Programs\Python\Python311\Lib\site-packages\alice_blue\alice_blue.py", line 503, in __ws_send sleep(0.05) # sleep for 50ms if websocket is not connected, wait for reconnection ^^^^^^^^^^^ KeyboardInterrupt

krishnavelu commented 1 year ago

show me what you are trying.

abhishekanne commented 1 year ago

` import logging import alice_blue import datetime from alice_blue import * from time import sleep

logging.basicConfig(level=logging.DEBUG) username='XXXXXX' password='XXXXXXX' app_id='XXXXXXX' api_secret='XXXXXXXXXX' twoFA='XXXXXXX' session_id = AliceBlue.login_and_get_sessionID( username = username, password = password, twoFA = twoFA, app_id = app_id, api_secret = api_secret) alice = AliceBlue(username = username, session_id = session_id,master_contracts_to_download=['NSE', 'NFO'])

This is working

scrip_info=alice.get_scrip_info(alice.get_instrument_by_symbol("NSE", "INFY-EQ")) logging.info(scrip_info)

Websocket

def event_handler_quote_update(message): print(f"quote update {message}")

alice.start_websocket(subscribe_callback=event_handler_quote_update)

alice.subscribe(alice.get_instrument_by_symbol('NSE', 'ONGC-EQ'), LiveFeedType.DEPTH_DATA) count=0 while True: count+=1 sleep(1) `

krishnavelu commented 1 year ago

What is the output for this? Why don't you read this and follow? https://github.com/krishnavelu/alice_blue#read-this-before-creating-an-issue I've clearly given what I need to help you. If I don't have enough information I cannot help you.

amfnecr commented 1 year ago

when we try websocket as shown in documentation, it shows warning " Websocket run forever ended in exception, run_forever()got an unexpected keyword argument "ping_payload""

code used is

import datetime import sys from datetime import date, timedelta,datetime,time import statistics from time import sleep from alice_blue import *

session_id = AliceBlue.login_and_get_sessionID( username = "XXXXXX", password = "XXXXXXX", twoFA = "XXXXXX", app_id = "XXXXXXXXXXX", api_secret = "XXXXXXXXX") alice = AliceBlue(username = "XXXXXXXX", session_id = session_id, master_contracts_to_download=['NSE'])

def event_handler_quote_update(message): print(f"quote update {message}")

alice.start_websocket(subscribe_callback=event_handler_quote_update)

alice.subscribe(alice.get_instrument_by_symbol('NSE', 'ONGC-EQ'), LiveFeedType.TICK_DATA) sleep(10)

krishnavelu commented 1 year ago

update your websocket-client library version.