Understanding WebSocket tick data


  • Hello team,

    When I am running the WebSocket usage example provided in the GitHub repo, the data received is not in a consistent format.

    Ticks: [{'name': 'tm', 'tvalue': '29/12/2020 14:21:42'}, {'ap': '161.59', 'bp': '159.85', 'bq': '6283', 'bs': '3162', 'c': '163.45', 'cng': '-03.55', 'e': 'nse_cm', 'lo': '159.40', 'ltp': '159.90', 'ltq': '500', 'ltt': '29/12/2020 14:21:42', 'name': 'sf', 'nc': '-02.17', 'sp': '159.95', 'tbq': '1335926', 'tk': '3063', 'to': '2922824084.18', 'tsq': '3460661', 'v': '18087902'}]
    Ticks: [{'name': 'tm', 'tvalue': '29/12/2020 14:21:43'}, {'e': 'nse_cm', 'ltp': '159.90', 'ltq': '500', 'ltt': 'NA', 'name': 'sf', 'tk': '3063'}]
    Ticks: [{'name': 'tm', 'tvalue': '29/12/2020 14:21:44'}, {'ap': '161.59', 'bp': '159.90', 'bq': '10', 'bs': '1942', 'c': '163.45', 'cng': '-03.55', 'e': 'nse_cm', 'lo': '159.40', 'ltp': '159.90', 'ltq': '500', 'ltt': '29/12/2020 14:21:42', 'name': 'sf', 'nc': '-02.17', 'sp': '159.95', 'tbq': '1343158', 'tk': '3063', 'to': '2922824084.18', 'tsq': '3459855', 'v': '18087902'}]
    Ticks: [{'ap': '161.59', 'bp': '159.90', 'bq': '10', 'bs': '1942', 'c': '163.45', 'cng': '-03.55', 'e': 'nse_cm', 'lo': '159.40', 'ltp': '159.90', 'ltq': '500', 'ltt': '29/12/2020 14:21:42', 'name': 'sf', 'nc': '-02.17', 'sp': '159.95', 'tbq': '1348279', 'tk': '3063', 'to': '2922824084.18', 'tsq': '3459855', 'v': '18087902'}]
    Ticks: [{'name': 'tm', 'tvalue': '29/12/2020 14:21:45'}, {'ap': '161.59', 'bp': '159.90', 'bq': '10', 'bs': '6223', 'c': '163.45', 'cng': '-03.55', 'e': 'nse_cm', 'lo': '159.40', 'ltp': '159.90', 'ltq': '500', 'ltt': '29/12/2020 14:21:42', 'name': 'sf', 'nc': '-02.17', 'sp': '159.95', 'tbq': '1348208', 'tk': '3063', 'to': '2922824084.18', 'tsq': '3464157', 'v': '18087902'}]
    Ticks: [{'name': 'tm', 'tvalue': '29/12/2020 14:21:46'}, {'e': 'nse_cm', 'ltp': '159.95', 'ltq': '57', 'ltt': 'NA', 'name': 'sf', 'tk': '3063'}]
    Ticks: [{'ap': '161.59', 'bp': '159.90', 'bq': '10', 'bs': '5223', 'c': '163.45', 'cng': '-03.50', 'e': 'nse_cm', 'lo': '159.40', 'ltp': '159.95', 'ltq': '57', 'ltt': '29/12/2020 14:21:46', 'name': 'sf', 'nc': '-02.14', 'sp': '159.95', 'tbq': '1344216', 'tk': '3063', 'to': '2922985674.18', 'tsq': '3463155', 'v': '18088902'}]
    

    Sometimes the response has two dictionaries with 2 and 6 key/value pairs respectively. Whereas, sometimes it has 2 and 19 key value/pairs. And other times I receive only a single dictionary.

    Now, which response do I consider as the live data? Or am I missing something here. Could you please help me with this?

    Thanks,
    Krishna


  • @MNAGESH

    ltp in websocket stream is last traded price..


  • @krishna
    you have to check the length of every tick, iterate through each part of tick,then use try/except to extract ltp if any portion of tick is having that


  • @rajanprabu Thanks. I figured out the problem. It was an error that I introduced while refactoring the code. After fixing it, its working fine now.


  • @softice You are using Java which I have no idea.. maybe a fellow Java trader can help.


  • @rajanprabu I am back with my query. My WebSocket API call stopped working today while it was working earlier.

    Today whole day, I just got below messages:

    [{"msg":"connected","task":"cn","ak":"ok"}]
    [{"msg":"mw","task":"mw","ak":"ok"}]
    [{"msg":"mw","task":"mw","ak":"ok"}]
    []
    [{"msg":"heartbeat","task":"hb","ak":"ok"}]

    Even though I got ack for task "mw", didn't get any data at all. Any pointers would be helpful.

    Thanks in advance.


  • @rajanprabu thanks for the reply on volume. Regarding using Pandas, well call me old school but I am on Java.


  • @softice

    pandas has resample function which can do this automatically for you.. I wrote it just for theoretical explanation.

    for volume you can use delta volumes ( tick V now - tick V previous )


  • @rajanprabu one more question. How to build the volume for a 1 min candle from this tick data?


  • @rajanprabu Thanks a ton man. You made my day. This turned out to be very simple than all the hacks I was trying.

    Thanks once again.


  • @softice

    you get LTP from the websokcets. one need to aggregate it for the time desired to get high and low. first entry in that time period is open and last entry is close.

    for example :

    time       ltp
    10:01:01 100
    10.01:02 110
    .
    .
    .
    
    10:01:30 120
    10:01:31  90
    .
    .
    .
    10:01:59 101
    

    open 100
    high 120
    low. 90
    close 101

    I hope its clear now.. this is how candles are made..
    https://smartapi.angelbroking.com/docs/WebSocket


  • @rajanprabu Thanks I didn't find what I was looking for. But then I realized that I never asked for it explicitly. So here it is.

    I am just looking for OHLC + Volume data. The following section of response seems to have a few of this:

    {"tbq":"67425","lo":"442.00","c":"484.50","e":"nse_fo","ltq":"25","ltp":"622.75","ltt":"30/03/2021 15:04:04","bp":"621.80","bq":"25","ap":"606.55","bs":"50","tsq":"54600","nc":"28.53","v":"5737850","tk":"58737","name":"sf","to":"3480292917.50","sp":"624.80","cng":"138.25"}

    but the high and open price seems to be missing here.

    So suppose if I want to build OHLC + Volume data from a tick,

    Open - missing
    High - missing
    Low - "lo":"<number of double type from this tick data>"
    Close - "c":"<number of double type from PREVIOUS tick data>"
    Volume - "v":"<long number from this tick data>"

    How do I get Open and High?

    The API documentation shows "h" and "op" for High and Open Price respectively but I am not seeing both these in the response.


  • @softice @krishna

    One need to search the keys of the dictionary. there is a sample code for old SDK here. modify it for new SDK.

    https://smartapi.angelbroking.com/topic/329/working-websocket-sample-code-to-retrieve-ltp-python?_=1617430271269

    HTH


  • Any updates on this? I am also having same confusion.


  • Hi @krishna , it's still under review. We will update you once we start the development activity on this.


  • @admin

    Did you get a chance to look into this? Any updates?

    Thanks!


  • Hi @krishna , we are reviewing the response structure.