Skip to content

Instantly share code, notes, and snippets.

@vividvilla
Created April 20, 2017 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vividvilla/10a5ca6e5a479a904e0fdb66dfd6a108 to your computer and use it in GitHub Desktop.
Save vividvilla/10a5ca6e5a479a904e0fdb66dfd6a108 to your computer and use it in GitHub Desktop.
Pykiteconnect websocket streaming test
import logging
from kiteconnect import WebSocket
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Initialise.
kws = WebSocket("api_key", "public_token", "zerodha_user_id")
# RELIANCE BSE and RELIANCE NSE
tokens = [128083204, 738561]
print("Tokens length", len(tokens))
# Callback for tick reception.
def on_tick(tick, ws):
print(tick)
# Callback for successful connection.
def on_connect(ws):
ws.subscribe(tokens)
ws.set_mode(ws.MODE_FULL, tokens)
def on_close():
print("closed")
def on_error():
print("error")
# Assign the callbacks.
kws.on_tick = on_tick
kws.on_connect = on_connect
# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect()
# kws.connect(disable_ssl_verification=True) # for ubuntu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment