Websocket data type


  • Hi @admin , I have subscribed to three scripts and I am getting response like this.

    2021-10-11 15:19:21.267343 : Start task in the background
    {'task': 'hb', 'channel': '', 'token': '0944454213', 'user': 'A282484', 'acctid': 'A282484'}
    HeartBeat Sending Failed
    [{'ap': '2684.05', 'bp': '2647.65', 'bq': '250', 'bs': '45', 'c': '2671.25', 'cng': '-23.25', 'e': 'nse_cm', 'lo': '2647.00', 'ltp': '2648.00', 'ltq': '5', 'ltt': '11/10/2021 15:19:20', 'name': 'sf', 'nc': '-00.8704', 'sp': '2647.80', 'tbq': '130785', 'tk': '2885', 'to': '17308410458.85', 'tsq': '511929', 'v': '6448617'}, {'e': 'nse_cm', 'ltp': '1691.50', 'ltq': '1', 'ltt': 'NA', 'name': 'sf', 'tk': '1594'}, {'e': 'nse_cm', 'ltp': '2649.00', 'ltq': '146', 'ltt': 'NA', 'name': 'sf', 'tk': '2885'}, {'e': 'nse_cm', 'ltp': '3683.40', 'ltq': '1', 'ltt': 'NA', 'name': 'sf', 'tk': '11536'}, {'e': 'nse_cm', 'ltp': '469.55', 'ltq': '25', 'ltt': 'NA', 'name': 'sf', 'tk': '3045'}]
    [{'ap': '3703.91', 'bp': '3683.00', 'bq': '5', 'bs': '181', 'c': '3935.65', 'cng': '-252.25', 'e': 'nse_cm', 'lo': '3660.00', 'ltp': '3683.40', 'ltq': '5', 'ltt': '11/10/2021 15:19:20', 'name': 'sf', 'nc': '-06.4094', 'sp': '3683.40', 'tbq': '511510', 'tk': '11536', 'to': '41437978337.21', 'tsq': '2612296', 'v': '11187631'}, {'name': 'tm', 'tvalue': '11/10/2021 15:19:21'}]
    [{'ap': '1699.28', 'bp': '1691.45', 'bq': '5554', 'bs': '7', 'c': '1723.85', 'cng': '-32.35', 'e': 'nse_cm', 'lo': '1663.70', 'ltp': '1691.50', 'ltq': '1', 'ltt': '11/10/2021 15:19:20', 'name': 'sf', 'nc': '-01.8766', 'sp': '1691.50', 'tbq': '474429', 'tk': '1594', 'to': '13932678800.48', 'tsq': '2169821', 'v': '8199166'}]
    [{'ap': '1699.28', 'bp': '1691.45', 'bq': '5463', 'bs': '8', 'c': '1723.85', 'cng': '-32.40', 'e': 'nse_cm', 'lo': '1663.70', 'ltp': '1691.45', 'ltq': '91', 'ltt': '11/10/2021 15:19:21', 'name': 'sf', 'nc': '-01.8795', 'sp': '1691.50', 'tbq': '474341', 'tk': '1594', 'to': '13932833434.96', 'tsq': '2169822', 'v': '8199257'}]
    [{'ap': '467.43', 'bp': '469.50', 'bq': '3987', 'bs': '1219', 'c': '458.00', 'cng': '11.55', 'e': 'nse_cm', 'lo': '458.65', 'ltp': '469.55', 'ltq': '1', 'ltt': '11/10/2021 15:19:20', 'name': 'sf', 'nc': '02.5218', 'sp': '469.60', 'tbq': '4966163', 'tk': '3045', 'to': '8825363064.87', 'tsq': '2126423', 'v': '18880609'}]
    

    also in the middle I am getting time data and heartbeat data, how can I read my script data like this??


  • @Asif_Khan I agree this is not an ideal implementation.
    The trick is not to look for the data as positional in the array, rather use the actual key.
    Next, you need to ignore the array's like below. May be like checking if the array have a key 'ltp' or even better have the K-V pair of 'name': 'sf'
    {'name': 'tm', 'tvalue': '13/10/2021 11:36:40'}

    BR
    Ashok


  • HI @Asif_Khan As discussed on the call kindly find the working web socket code:
    from smartapi import SmartWebSocket

    feed_token= ""

    FEED_TOKEN= ""
    CLIENT_CODE=""

    token="mcx_fo|224395"

    token="nse_cm|2885&nse_cm|1594&nse_cm|11536&nse_cm|3045"

    token="mcx_fo|226745&mcx_fo|220822&mcx_fo|227182&mcx_fo|221599"

    task="mw" # mw|sfi|dp

    ss = SmartWebSocket(FEED_TOKEN, CLIENT_CODE)

    def on_message(ws, message):
    print("Ticks: {}".format(message))

    def on_open(ws):
    print("on open")
    ss.subscribe(task,token)

    def on_error(ws, error):
    print(error)

    def on_close(ws):
    print("Close")

    Assign the callbacks.

    ss._on_open = on_open
    ss._on_message = on_message
    ss._on_error = on_error
    ss._on_close = on_close

    ss.connect()


  • @admin I have not heard from you people its been two days now,

    [[{'e': 'nse_cm', 'ltp': '2678.50', 'ltq': '1', 'ltt': 'NA', 'name': 'sf', 'tk': '2885'}]
    ********************************************************************
    [{'ap': '3661.25', 'bp': '3660.00', 'bq': '306', 'bs': '215', 'c': '3652.85', 'cng': '07.20', 'e': 'nse_cm', 'lo': '3645.00', 'ltp': '3660.05', 'ltq': '3', 'ltt': '13/10/2021 11:36:39', 'name': 'sf', 'nc': '00.1971', 'sp': '3660.05', 'tbq': '336997', 'tk': '11536', 'to': '4582984332.50', 'tsq': '1302928', 'v': '1251754'}]
    ********************************************************************
    [{'ap': '3661.25', 'bp': '3660.00', 'bq': '306', 'bs': '260', 'c': '3652.85', 'cng': '07.20', 'e': 'nse_cm', 'lo': '3645.00', 'ltp': '3660.05', 'ltq': '3', 'ltt': '13/10/2021 11:36:39', 'name': 'sf', 'nc': '00.1971', 'sp': '3660.05', 'tbq': '336891', 'tk': '11536', 'to': '4582984332.50', 'tsq': '1302973', 'v': '1251754'}]
    ********************************************************************
    [{'name': 'tm', 'tvalue': '13/10/2021 11:36:40'}, {'ap': '2677.79', 'bp': '2678.05', 'bq': '4', 'bs': '47', 'c': '2667.80', 'cng': '10.70', 'e': 'nse_cm', 'lo': '2669.30', 'ltp': '2678.50', 'ltq': '2', 'ltt': '13/10/2021 11:36:39', 'name': 'sf', 'nc': '00.4011', 'sp': '2678.50', 'tbq': '137394', 'tk': '2885', 'to': '4573244906.97', 'tsq': '310675', 'v': '1707843'}]
    ********************************************************************
    [{'e': 'nse_cm', 'ltp': '1699.25', 'ltq': '30', 'ltt': 'NA', 'name': 'sf', 'tk': '1594'}]
    ********************************************************************
    [{'e': 'nse_cm', 'ltp': '481.95', 'ltq': '4', 'ltt': 'NA', 'name': 'sf', 'tk': '3045'}, {'e': 'nse_cm', 'ltp': '3660.00', 'ltq': '13', 'ltt': 'NA', 'name': 'sf', 'tk': '11536'}, {'e': 'nse_cm', 'ltp': '2678.50', 'ltq': '2', 'ltt': 'NA', 'name': 'sf', 'tk': '2885'}, {'ap': '1690.83', 'bp': '1699.20', 'bq': '127', 'bs': '97', 'c': '1685.15', 'cng': '14.10', 'e': 'nse_cm', 'lo': '1680.05', 'ltp': '1699.25', 'ltq': '30', 'ltt': '13/10/2021 11:36:39', 'name': 'sf', 'nc': '00.8367', 'sp': '1699.25', 'tbq': '364823', 'tk': '1594', 'to': '5668680039.66', 'tsq': '1454319', 'v': '3352602'}]]
    

    just look at the response,why m i getting different different responses?? it should be one array containing all the ticket information.


  • @admin my client id is A282484


  • HI @Asif_Khan Post your client id here our team will connect with you.


  • @admin what I am trying to say, just see the response,

    I have gone through the documentation you are referring,

    and I know the meaning of each property in the json but look at the response it is not similar, First array contains 5 objects two of the same ticket, 3 different tickets, second array contains two objects one foe ticket number 11536 and other is time value,
    third array contains only one object..so what is this??how would I know which array to select?


  • Hi @Asif_Khan Kindly go through below doc to understand the various values you are getting in response of websocket:
    https://smartapi.angelbroking.com/docs/WebSocketStreaming


  • @admin I am not talking about heartbeat , I am talking about actual response, look at the first array, it contains 5 objects, but after that all arrays contain different different objects, which one to use and which one to ignore, and how to ignore


  • HI @Asif_Khan Currently our team is working on web socket we will update you on this.