Bot stops working after Reconnect

Created at 03 Nov 2022, 22:19
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!
GR

GridSurfer

Joined 08.06.2019

Bot stops working after Reconnect
03 Nov 2022, 22:19


Hi,

my dsl internet provider cuts my connection every night for about 1 minute. In most cases the reconnect doesn't affect the running bot but I have had several times now, that the bot disappears in nirvana. What I mean is that the bot stopps working - doesn't trade anymore etc., but appears still running in cTrader.

I even tried it with debugging: after the reconnect in the night cTrader doesn't send OnTick() or does anything with the bot. I can hit the "Stop Bot" button and the bot stops, but even the OnStop() does not seem to be called.

My questions are: How can I circumvent the state of "nirvana"? cTrader keeps working, so it is the reconnect I need to handle - is this done programmatically? I want the bot keep working when the connection is lost while the bot is running.

Cheers
GridSurfer


@GridSurfer
Replies

Spotware
04 Nov 2022, 10:08

Dear GridSurfer,

Can you please share your cBot so that we can investigate further?

Best regards,

cTrader Team


@Spotware

GridSurfer
04 Nov 2022, 12:11

RE:

Spotware said:

Dear GridSurfer,

Can you please share your cBot so that we can investigate further?

Best regards,

cTrader Team

Thank you. Unfortunately the code is huge with lots of necessary setups (files, paths etc.). I will wite a simple bot and test it with it.

For my understanding:

1. When cTrader loses connection (no matter how long) and reconnects, the running bot should continue working as if there were no disruption?
2. The ticks that occured during this time are not re-send. I could get them from the server via MarketData.GetTicks()
3. But basically I wouldn't know that there was a disconnect without data feed during a certain time, right? Or is there a way to verify that all ticks have arrived?

For the time being I am only concerned with 1. I know of this approx. 1 minute disruption of the connection which sends the system sometimes into nirvana.


@GridSurfer

Spotware
04 Nov 2022, 14:09

Dear GridSurfer,

  1. It depends on your cBot's implementation
  2. No they are not
  3. If the disconnection has not been initiated by the server, then you won't be able to know.

Best regards,

cTrader Team


@Spotware

GridSurfer
04 Nov 2022, 15:33

Hi Support,

thanks for your quick reply. If "it depends on your cBot's implementation", what do I need to do to keep my bot alive.

Given the simplest of all bots (e.g. your sample of a basic bot), what is supposed to happen, when cTrader loses connection and reconnects with the last account?

If it is anything but the bot keeps running, keeps all previous conditions, session, trades, variables, etc. - what can I do to make sure my bot keeps running, unless I close cTrader completely or stop the bot? Is there a way to ensure the disconnect, reconnect doesn't affect the bot running?

Cheers

 


@GridSurfer

Spotware
07 Nov 2022, 11:32

Dear GridSurfer,

It's a very vague discussion. We will be able to advise if you share your source code and explain in detail the issue you are experiencing.

Best regards,

cTrader Team


@Spotware

GridSurfer
07 Nov 2022, 14:45

Spotware said:

It's a very vague discussion. We will be able to advise if you share your source code and explain in detail the issue you are experiencing.

I will prepare and share, of course, but first I need to know what the desired outcome is supposed to be.

I have a bot running, it has positions, it is waiting for events OnTick() etc. --> If the connection is lost, cTrader logs out and when the connection comes back cTrader reconnects.

It is not a "vague discussion" - actually it is a simple question:Does the bot continue running as if there were no disconnect or is there some reset, re-initialize, break, etc.?


@GridSurfer

Spotware
07 Nov 2022, 16:43

Dear GridSurfer,

The cBot does not reinitialize after disconnection.

Best regards,

cTrader Team


@Spotware

ncel01
15 Dec 2022, 00:09

RE:

Hello,

How to ensure that cBots will keep working as soon as the connection is reestablished? Could you please provide a sample for this?

It is not very evident/intuitive that cBots stop working in such cases since, apparently, the start buttons remain active. I guess this means that OnStop() is not reached. 

Is this correct?

Thanks.

 

Spotware said:

Dear GridSurfer,

The cBot does not reinitialize after disconnection.

Best regards,

cTrader Team

 


@ncel01

ncel01
16 Dec 2022, 11:37

RE: RE:

Dear cTrader team,

Could plase inform on the above?

Thank you.

 

ncel01 said:

Hello,

How to ensure that cBots will keep working as soon as the connection is reestablished? Could you please provide a sample for this?

It is not very evident/intuitive that cBots stop working in such cases since, apparently, the start buttons remain active. I guess this means that OnStop() is not reached. 

Is this correct?

Thanks.

 

Spotware said:

Dear GridSurfer,

The cBot does not reinitialize after disconnection.

Best regards,

cTrader Team

 

 


@ncel01

PanagiotisChar
16 Dec 2022, 17:04

Hi there,

How to ensure that cBots will keep working as soon as the connection is reestablished? Could you please provide a sample for this?

This is a very vague question to be answered with a sample. What do you mean when you say "keep working"? It all depends on the implementation logic. When the cBot is disconnected, what happens is that OnBar and OnTick events stop getting triggered. If your cBot is simple e.g. checking for MA crosses, then there is nothing you need to do. The cBot will continue checking when reconnected and bars start getting streamed again. If you are doing something more complicated, like counting bars, then you will need to write logic to account for the lost bars on reconnection.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

ncel01
16 Dec 2022, 18:04

RE:

Hi Panagiotis,

Thanks for your feedback.

That was exactly my point. I was thinking that, once disconnected, events wouldn't continue to trigger even after the connection is reestablished.

Since this is, by default, not the case, there's no issue at all.

 

PanagiotisChar said:

Hi there,

How to ensure that cBots will keep working as soon as the connection is reestablished? Could you please provide a sample for this?

This is a very vague question to be answered with a sample. What do you mean when you say "keep working"? It all depends on the implementation logic. When the cBot is disconnected, what happens is that OnBar and OnTick events stop getting triggered. If your cBot is simple e.g. checking for MA crosses, then there is nothing you need to do. The cBot will continue checking when reconnected and bars start getting streamed again. If you are doing something more complicated, like counting bars, then you will need to write logic to account for the lost bars on reconnection.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

 


@ncel01

scherli
18 Apr 2024, 13:22 ( Updated at: 19 Apr 2024, 05:27 )

Hello everyone

I have the same problem, my bots (running on ctrader-cli) stop once a week without visible reason, with or without lost connection. I help myself with writing timestamps to a logfile and having a watchdog process, that restarts the cbot when the log entries don't occure anymore.

Greetings
scherli

 


@scherli

dreampunchboy
14 May 2024, 04:46

RE: Bot stops working after Reconnect

scherli said: 

Hello everyone

I have the same problem, my bots (running on ctrader-cli) stop once a week without visible reason, with or without lost connection. I help myself with writing timestamps to a logfile and having a watchdog process, that restarts the cbot when the log entries don't occure anymore.

Greetings
scherli

 

I've been experiencing this almost every morning when I check the CLI processes.
“Attempting to reconnect” while everything else is still open and running. CTrader open and connected, MT5 connected and running.

@Spotware can you please have a look at this?


@dreampunchboy

PanagiotisCharalampous
14 May 2024, 05:57

RE: RE: Bot stops working after Reconnect

dreampunchboy said: 

scherli said: 

Hello everyone

I have the same problem, my bots (running on ctrader-cli) stop once a week without visible reason, with or without lost connection. I help myself with writing timestamps to a logfile and having a watchdog process, that restarts the cbot when the log entries don't occure anymore.

Greetings
scherli

 

I've been experiencing this almost every morning when I check the CLI processes.
“Attempting to reconnect” while everything else is still open and running. CTrader open and connected, MT5 connected and running.

@Spotware can you please have a look at this?

Hi there,

We would need more information regarding this matter. Also this seems to be a separate issue so please do the following

  1. Create a new thread with a clear explanation of your issue
  2. Provide your cBot code.
  3. Provide us with exact steps on how to reproduce this problem.

Best regards,

Panagiotis


@PanagiotisCharalampous