Last active
October 16, 2022 12:32
Kite Connect Python client websocket streaming example - https://github.com/rainmattertech/pykiteconnect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from kiteconnect import WebSocket | |
logging.basicConfig(filename='ticks.log', level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
# Initialise. | |
kws = WebSocket("api_key", "public_token", "user_id") | |
tokens = [5215745, 633601, 1195009, 779521, 758529, 1256193, 194561, 1837825, 952577, 1723649, 3930881, 4451329, 593665, 3431425, 2905857, 3771393, 3789569, 3463169, 381697, 54273, 415745, 2933761, 3580417, 49409, 3060993, 4464129, 3375873, 4574465, 636673, 3721473, 2796801] | |
print("Tokens length", len(tokens)) | |
# Callback for tick reception. | |
def on_tick(tick, ws): | |
logging.debug(tick) | |
# Callback for successful connection. | |
def on_connect(ws): | |
ws.subscribe(tokens) | |
ws.set_mode(ws.MODE_FULL, tokens) | |
# 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