Working with Quote Depths

razcads
Hi,

I need to retrieve the top bid price and ask price from the depth received from kite.quote()
Is the data provided in quote ordered with the best matched pair first in the list?
Can you explain how the depth data is organized?

Thanks
Ravi
  • sauravkedia
    @razcards, the bid and ask data come in form for a list which is sorted with top item being the best. I also extract this two row to get best bid and offer and use it for trading

    The real issues comes later.

    Right now, we receive data in json format which is not a native python data type. So, we need to convert into a native datatype. Further, the json data comes in a format which is really not usable right away without additional processing like extracting best bid and offer.

    I have experiment and found that dictionaries work best here. So, when I receive list of jsons (one row per ticker) as quote from websocket, I loop through the list, and convert each line into dictionary and update it into the quotes dictionary. While doing so, I
    also extract the best bid and best ask from depth data. While this is working well (within 10milliseconds), I want to replace it with a faster algo.

    Looping through a list seems avoidable. I have tried reading the json as pandas dataframe at one go and do vector operations but that is even slower.

    I am aware that one user has forked the Kiteconnect package in order to receive the data as
    dictionary (rather than json) and that may simpify things, but the additional overhead involved in keeping that fork updated with Zeodha's releases is a tall order.

    Team Zerodha and others users, any suggestions?
  • sujith
    Hi,
    It will have the best bid and ask in the top.
    We don't organize data. We just fetch and serve the request.
  • razcads
    razcads edited October 2017
    @sauravkedia @sujith thanks for your response.
    the python api gives the values as dicts and its pretty easy to work with atleast for my use case. Looping through the nest can be a problem.. I just get my data as this -
    based on what @sujith said the first 'sell' dict value is the best bid and similarly for 'buy'
    so best bid price will be
    (((quote['depth'])['sell'])[0])['price']
    best ask price will be
    (((quote['depth'])['buy'])[0])['price']
    where
    quote = kite.quote(exchange,fno)
This discussion has been closed.