ProtoHeartbeatEvent

Created at 19 Sep 2022, 21:00
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
PS

PS_Prop

Joined 20.07.2022

ProtoHeartbeatEvent
19 Sep 2022, 21:00


Point 6 in https://help.ctrader.com/open-api/connection/  "To keep your connections alive, keep sending a ProtoHeartbeatEvent in 10 seconds interval."

In " connected() " I added a twisted.task.LoopingCall

hb = task.LoopingCall(ProtoHeartbeatEvent)
hb.start(10.0)
 

I still only get a ProtoHeartbeatEvent back from the server every 30 seconds though. Is this the correct way to do it?


@PS_Prop
Replies

PanagiotisCharalampous
20 Sep 2022, 09:17

Hi sansand,

Yes server sends heartbeats every 30 seconds.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

PS_Prop
20 Sep 2022, 09:26

RE:

PanagiotisCharalampous said:

Hi sansand,

Yes server sends heartbeats every 30 seconds.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 

So the " task.LoopingCall " I added is correct?


@PS_Prop

PanagiotisCharalampous
20 Sep 2022, 09:29

Hi sansand,

I have no idea what is that about and what it is doing :)

Best Regards,

Panagiotis 

Join us onTelegram andFacebook


@PanagiotisCharalampous

PS_Prop
20 Sep 2022, 09:31 ( Updated at: 20 Sep 2022, 09:40 )

RE:

PanagiotisCharalampous said:

Hi sansand,

I have no idea what is that about and what it is doing :)

Best Regards,

Panagiotis 

Join us onTelegram andFacebook

 

Ok. So what would be the best way to keep the connection alive by sending a ProtoHeartbeatEvent in 10 second intervals?

Forgot to say that I'm using OpenApiPy.


@PS_Prop

PS_Prop
22 Sep 2022, 15:54

Since I can't find anything in the samples, and there's no confirmation back from the server when I send a ProtoHeartbeatEvent, I don't know if I'm doing it right.

I would greatly appreciate an input from the developers or someone that has a working example, how it's supposed to be done.


@PS_Prop

PanagiotisCharalampous
22 Sep 2022, 16:17

Hi sansand,

The server does not send any confirmations for heartbeats. If the connection is not dropped and you keep receiving heartbeats from the server, then it means tou are doing it right.

Best Regards,

Panagiotis 

Join us onTelegram andFacebook


@PanagiotisCharalampous

PS_Prop
22 Sep 2022, 16:21

RE:

PanagiotisCharalampous said:

Hi sansand,

The server does not send any confirmations for heartbeats. If the connection is not dropped and you keep receiving heartbeats from the server, then it means tou are doing it right.

Best Regards,

Panagiotis 

Join us onTelegram andFacebook

 

Since the sample https://github.com/spotware/OpenApiPy/tree/main/samples/ConsoleSample does not send a ProtoHeartbeatEvent, do we really need to do it (server keeps sending a heartbeat every 30 sec)? How long until the server drops the connection, if we don't send a ProtoHeartbeatEvent?


@PS_Prop

PanagiotisCharalampous
26 Sep 2022, 09:49

Hi sansand,

Yes, when there is no other interaction with the server, you need to send heatbeats to keep the connection alive. If you stop sending heartbeats, the connection will be dropped after some seconds.

Best Regards,

Panagiotis 

Join us onTelegram andFacebook


@PanagiotisCharalampous

opalodemo
20 Dec 2023, 00:32 ( Updated at: 21 Dec 2023, 17:21 )

RE: ProtoHeartbeatEvent

I have these methods in my app  in python but it never returns anything and the connection drops after 30 seconds, what I have wrong?

 


    # ----------------------------------------------------------------------------------------    
   def pruebas_loopincall(self):       
       lc = LoopingCall(self.enviar_señal)               
       lc.start(3)

   

   # ----------------------------------------------------------------------------------------    
   def enviar_señal(self):

       request = ProtoHeartbeatEvent()
       deferred  = self.client.send(request, responseTimeoutInSeconds = 60)                        
       deferred.addTimeout(60, reactor)            
       print("deferred", deferred)

 

 


@opalodemo