Kite v3:- Not getting the data in the new quote packet structure

ansumanm
Hi,

I am not getting the ticks in the packet structure specified at:-
https://kite.trade/docs/connect/v3/websocket/


packet format received:-

>python3 ws.py
Subscribing to:
[11038466] << BANKNIFTY18FEB28600CE


DEBUG:root:Ticks: [{'tradable': True, 'mode': 'quote', 'instrument_token': 11038466, 'last_price': 74.0, 'last_quantity': 40, 'average_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}]

I had copied the code from pykiteconnect api documentation give here:-

https://kite.trade/docs/pykiteconnect/v3/#kiteconnect.KiteTicker

I havent set the mode explicitly for BANKNIFTY18FEB28600CE.
My on_connect() function.

def on_connect(ws, response):
global ws_ctx

inst_list = ws_ctx['inst_list']

print('Subscribing to:')
print(inst_list)
print('\n')
# Callback on successful connect.
ws.subscribe(inst_list)

# Subscribe to instrument list
# ws.set_mode(ws.MODE_FULL, [738561])

What do i need to do.
Tagged:
  • sujith
    @ansumanm,
    You need to connect first then only you will get ticks.
  • ansumanm
    Hi Sujith, I am connecting ..And getting ticks also..Only that its not in the query packet structure as mentioned in kite documentation..
  • ansumanm
    Pasting logs:-

    >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''

  • ansumanm
    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.
  • ansumanm
    Figured it out.. Looks like we get timestamps in ticks only in Full mode. Is there any example code to process binary payload in python?

    >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}]
  • sujith
    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
Sign In or Register to comment.