It looks like you're new here. If you want to get involved, click one of these buttons!
inst_token = [13206274,13260546]
def on_connect(ws, response):
ws.subscribe(inst_token)
ws.set_mode(ws.MODE_FULL, inst_token)
def on_ticks(ws, ticks):
if (ticks[0]['instrument_token'] == 13206274):
symobl1_price = ticks[0]['last_price'] ##### get symbol1 tick price
print(symobl1_price)
symobl1_sell_price= ticks[0]['depth']['buy'][0]['price']
symobl1_buy_price = ticks[0]['depth']['sell'][0]['price']
if (ticks[1]['instrument_token'] == 13260546):
symobl2_price = ticks[1]['last_price'] ##### get symbol2 tick price
print(symobl2_price)
symobl2_sell_price = ticks[1]['depth']['buy'][0]['price']
symobl2_buy_price = ticks[1]['depth']['sell'][0]['price']
if len(ticks) == 2:
if (ticks[0]['instrument_token'] == 13206274):
symobl1_price = ticks[0]['last_price'] ##### get axis tick
print(symobl1_price)
symobl1_sell_price= ticks[0]['depth']['buy'][0]['price']
symobl1_buy_price = ticks[0]['depth']['sell'][0]['price']
if (ticks[1]['instrument_token'] == 13260546):
symobl2_price = ticks[1]['last_price'] ##### get icici tick
print(symobl2_price)
symobl2_sell_price = ticks[1]['depth']['buy'][0]['price']
symobl2_buy_price = ticks[1]['depth']['sell'][0]['price']
else:
print('Hi from else')
When i run this code,i can see that it goes into the else block frequently.
Once you subscribe for a tick, the first time you will get a cached tick for every subscribed token if a tick exists at the Kite Ticker. Post that, you will receive ticks only when there is a change in any of the values.
An ideal way is to check the length of the incoming array of ticks and then loop those many times. Each tick object will have an instrument token value using which you can do the operations.
Thank you for your response.I will update the code accordingly.
Thanks a lot!