ok..Looks like I need to implement the on_message() callback handler to get the new packet structure. I am using on_ticks() which sends data in old format.
Hi @ansumanm, The pykiteconnect library already does all of this. You don't have to actually do it. For your reference, you can check out parse_binary method
You need to connect first then only you will get ticks.
>python3 ws.py
DEBUG:kiteconnect.ticker:Start WebSocket connection.
2018-01-31 01:27:33+0530 [-] Log opened.
2018-01-31 01:27:34+0530 [-] Subscribing to:
2018-01-31 01:27:34+0530 [-] [11038466]
2018-01-31 01:27:34+0530 [-]
2018-01-31 01:27:34+0530 [-]
DEBUG:kiteconnect.ticker:ping =>
DEBUG:kiteconnect.ticker:pong => b''
DEBUG:root:Ticks: [{'tradable': True, 'mode': 'quote', 'instrument_token': 11038466, 'last_price': 74.0, 'last_quantity': 40, 'ave
rage_price': 95.34, 'volume': 1400, 'buy_quantity': 12800, 'sell_quantity': 280, 'ohlc': {'open': 108.0, 'high': 109.8, 'low': 74.
0, 'close': 150.0}, 'change': -50.666666666666664}]
DEBUG:kiteconnect.ticker:ping =>
DEBUG:kiteconnect.ticker:last ping was 2.5034165382385254 seconds back.
DEBUG:kiteconnect.ticker:last pong was 2.5040879249572754 seconds back.
DEBUG:kiteconnect.ticker:pong => b''
>python3 ws_threaded.py [86/1240]2018-01-31 02:37:58+0530 [-] Log opened.
INFO:root:This is main thread. Will change webosocket mode every 5 seconds.
INFO:root:Successfully connected. Response: {"peer": "tcp4:35.154.180.164:443", "headers": {"date": "Tue, 30 Jan 2018 21:07:59 GMT
", "connection": "upgrade", "upgrade": "websocket", "sec-websocket-accept": "uOHKpAfxsRGQp1nFsMQwRwgJ5mE="}, "version": 18, "protocol": null, "extensions": []}
INFO:root:Subscribe to tokens in Full mode: [11038466]
INFO:root:[on_message]Binary message received. INFO:root:Ticks: [{'tradable': True, 'mode': 'full', 'instrument_token': 11038466, 'last_price': 74.0, 'last_quantity': 40, 'avera
ge_price': 95.34, 'volume': 1400, 'buy_quantity': 12800, 'sell_quantity': 280, 'ohlc': {'open': 108.0, 'high': 109.8, 'low': 74.0,
'close': 150.0}, 'change': -50.666666666666664, 'last_trade_time': datetime.datetime(2018, 1, 30, 15, 23, 51), 'oi': 1800, 'oi_da
y_high': 1800, 'oi_day_low': 1400, 'timestamp': datetime.datetime(2018, 1, 30, 15, 29, 59), 'depth': {'buy': [{'quantity': 80, 'price': 68.3, 'orders': 65536}, {'quantity': 40, 'price': 68.25, 'orders': 65536}, {'quantity': 40, 'price': 65.0, 'orders': 65536}, {'quantity': 40, 'price': 58.0, 'orders': 65536}, {'quantity': 1800, 'price': 51.05, 'orders': 65536}], 'sell': [{'quantity': 40,
'price': 71.35, 'orders': 65536}, {'quantity': 40, 'price': 78.0, 'orders': 65536}, {'quantity': 40, 'price': 100.0, 'orders': 65
536}, {'quantity': 40, 'price': 113.2, 'orders': 65536}, {'quantity': 40, 'price': 150.0, 'orders': 65536}]}}]
INFO:root:[on_message]Binary message received. INFO:root:### Set mode to LTP for all tokens INFO:root:[on_message]Binary message received. INFO:root:Ticks: [{'tradable': True, 'mode': 'ltp', 'instrument_token': 11038466, 'last_price': 74.0}] INFO:root:[on_message]Binary message received. INFO:root:[on_message]Binary message received. INFO:root:### Set mode to quote for all tokens INFO:root:[on_message]Binary message received.
INFO:root:Ticks: [{'tradable': True, 'mode': 'quote', 'instrument_token': 11038466, 'last_price': 74.0, 'last_quantity': 40, 'aver
age_price': 95.34, 'volume': 1400, 'buy_quantity': 12800, 'sell_quantity': 280, 'ohlc': {'open': 108.0, 'high': 109.8, 'low': 74.0
, 'close': 150.0}, 'change': -50.666666666666664}]
The pykiteconnect library already does all of this. You don't have to actually do it.
For your reference, you can check out parse_binary method