def on_connect(ws, response): # noqa # Callback on successful connect. # Subscribe to a list of instrument_tokens (RELIANCE and ACC here). ws.subscribe([738561, 5633])
# Set RELIANCE to tick in `full` mode. ws.set_mode(ws.MODE_FULL, [738561])
def on_connect(ws, response): # Callback on successful connect. # Subscribe to a list of instrument_tokens (RELIANCE and ACC here). ws.subscribe([738561, 5633])
# Set RELIANCE to tick in `full` mode. ws.set_mode(ws.MODE_FULL, [738561])
from kiteconnect import KiteTicker
logging.basicConfig(level=logging.DEBUG)
# Construct WebSocket URL with API key and access token
websocket_url = "wss://ws.kite.trade?api_key=YOUR_API_KEY&access_token=YOUR_ACCESS_TOKEN"
# Initialise KiteTicker with the WebSocket URL
kws = KiteTicker("YOUR_API_KEY", "YOUR_ACCESS_TOKEN", websocket=websocket_url)
# Define callback functions
def on_ticks(ws, ticks):
# Callback to receive ticks.
logging.info("Ticks: {}".format(ticks))
def on_connect(ws, response):
# Callback on successful connect.
# Subscribe to a list of instrument_tokens (RELIANCE and ACC here).
ws.subscribe([738561, 5633])
# Set RELIANCE to tick in `full` mode.
ws.set_mode(ws.MODE_FULL, [738561])
def on_order_update(ws, data):
logging.debug("Order update : {}".format(data))
def on_close(ws, close_status_code, close_msg):
# Handle WebSocket close event
print("WebSocket connection closed with status code:", close_status_code)
print("Close message:", close_msg)
# Assign the callbacks
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_order_update = on_order_update
kws.on_close = on_close
# Connect to the WebSocket server
kws.connect()
STILL SHOWING
runfile('D:/VruAlgo/untitled2.py', wdir='D:/VruAlgo')
ERROR:websocket:Handshake status 400 Bad Request -+-+- {'date': 'Sun, 12 May 2024 11:59:20 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '50', 'connection': 'keep-alive'} -+-+- b'{"status":"error","message":"Invalid auth token."}' - goodbye
WebSocket error: Handshake status 400 Bad Request -+-+- {'date': 'Sun, 12 May 2024 11:59:20 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '50', 'connection': 'keep-alive'} -+-+- b'{"status":"error","message":"Invalid auth token."}'
WebSocket connection closed with status code: None
Close message: None