HeartBeats Failed

  • Hi @rajanprabu , Hope your issue is resolved. If not, please share your contact details on api@angelbroking.com

  • @Ashok Im also wondering if that is the root cause of the problem. But in my code I have a streamer class which emits the ticks. This I run in one thread and other things that I do in parallel using threads. This functionality is crucial.

    I hope @admin and team had a look at it.

  • @rajanprabu my websocket worked just fine today no failures. I was seeing tick data till 15.30.
    But I forgot to log the heartbeat message to see if there are any failures.
    PS: I am not using threaded ticker

  • @Ashok was it running ok for you today ?? No HeartBeats Failed message ?

  • @admin

    I have tested today and I had the same error. Please find the test script below. Im using threaded=True

    from smartapi import WebSocket 
    import json
    import datetime
    import time
    with open('AB/ab_user.json') as f:
        data = json.load(f)
    client_code = data['client_code']
    with open('AB/ab_tokens.json') as f:
        data = json.load(f)
    feed_token = str(data['feedToken'])
    token = "nse_cm|3456&nse_cm|7229&nse_cm|1594&nse_cm|3787&nse_cm|1330&nse_cm|10999&nse_cm|4717&nse_cm|13538&nse_cm|694&nse_cm|2031&nse_cm|2475&nse_cm|1394&nse_cm|11536&nse_cm|20374&nse_cm|1333&nse_cm|881&nse_cm|467&nse_cm|1348&nse_cm|10604&nse_cm|547&nse_cm|3506&nse_cm|4963&nse_cm|1660&nse_cm|17963&nse_cm|910&nse_cm|11532&nse_cm|526&nse_cm|3351&nse_cm|236&nse_cm|14977&nse_cm|21808&nse_cm|1232&nse_cm|1624&nse_cm|11723&nse_cm|5900&nse_cm|10940&nse_cm|3045&nse_cm|11287&nse_cm|11630&nse_cm|5258&nse_cm|11483&nse_cm|1922&nse_cm|3103&nse_cm|1363&nse_cm|2885&nse_cm|16675&nse_cm|317&nse_cm|15083&nse_cm|3499"
    ss = WebSocket(feed_token, client_code)
    def on_tick(ws, tick):
        print("Ticks: {}".format(tick))
    def on_connect(ws, response):
    def on_close(ws, code, reason):
    # Assign the callbacks.
    ss.on_ticks = on_tick
    ss.on_connect = on_connect
    ss.on_close = on_close
    while True:

  • @rajanprabu @Ashok We have connected the websocket today morning and till now it's working fine. If we get a disconnection before 3.30, will identify and resolve the issue.

  • Hi @Ashok @rajanprabu , we are reviewing this.

  • @rajanprabu Very similar to what happened to me today.

    -> Login (Generate session) @ 7AM - OK
    -> When the cron started Websocket at 9.15 AM, the token got expired
    -> Then I generated new token at 11:12 and started websocket streaming again - OK
    -> But the streaming ended at 14:09 got stopped - I did not check the heartbeat, but probably that is the reason

    Looks like the token i getting expired after sometime. say 2.5 hrs by estimate.

    I raised this with @Bhaveshsjain @admin today morning . lets wait for the analysis.

    PS: All my jobs are scheduled in a scheduler

  • @dheepi

    I run a cron job to start my algo because I live in a different time zone. Program started at 9:15 and ran fine till 10:33 then it gave heartbeats failed message.

    Then I tried manually to run and its started appearing randomly after some time.

  • @rajanprabu , At what time the heartbeat failed for you?

  • Bugs

    Found a bug? Use this category to report us.

  • Java SDK

    Ask Java SDK related queries here.

  • R SDK

    Ask R SDK related queries here.

  • Go SDK

    Ask Go SDK related queries here.

How SmartAPI works