-
Notifications
You must be signed in to change notification settings - Fork 474
/
ticker.py
41 lines (32 loc) · 1.26 KB
/
ticker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
###############################################################################
#
# The MIT License (MIT)
#
# Copyright (c) Zerodha Technology Pvt. Ltd.
#
# This example shows how to subscribe and get ticks from Kite Connect ticker,
# For more info read documentation - https://kite.trade/docs/connect/v1/#streaming-websocket
###############################################################################
import logging
from kiteconnect import KiteTicker
logging.basicConfig(level=logging.DEBUG)
# Initialise
kws = KiteTicker("your_api_key", "your_access_token")
def on_ticks(ws, ticks): # noqa
# Callback to receive ticks.
logging.info("Ticks: {}".format(ticks))
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_order_update(ws, data):
logging.debug("Order update : {}".format(data))
# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_order_update = on_order_update
# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect()