开云体育

ctrl + shift + ? for shortcuts
© 2025 Groups.io

TWS vs Gateway at reconnections


 

Last week I was running the TWS and the gateway simultaneously when my internet connection suddenly disappeared. While the gateway attempted to reconnected many times until finally the connection was reestablished exited the TWS directly
and made no attempts to reconnect.
I'd prefer the TWS to behave like the gateway did (reconnect when the internet is available again). How can I change the behaviour of the TWS?


Amine
 

Hi Despair

My answer is not the smartest and could help. I use TWS and its data disconnected due to internet disconnection, then it it was restored once internet was restablish,
I run TWS API (python) in a loop:

app = IBapi()
app.connect('127.0.0.1', port=port, clientId=clientId)
print("serverVersion:%s connectionTime:%s" % (app.serverVersion(),
app.twsConnectionTime()))

def run_loop():
app.run()

api_thread = threading.Thread(target=run_loop, daemon=True)
api_thread.start()


 

The problem is not the reconnection to the API. The problem is the TWS shuts down completely. So I have to restart the TWS manually before the client can connect to it again.


 

Hi all,?

I have also had this problem and am currently switching to run this on a server. I am going to be paying around $20-40/month.?

I am in-between using "VULTR" or spinning up an EC2 instance then creating a UI for Linux on the server.?

Best,
Rob

On Wed, Jun 2, 2021 at 12:32 AM Despair <boris@...> wrote:
The problem is not the reconnection to the API. The problem is the TWS shuts down completely. So I have to restart the TWS manually before the client can connect to it again.


Stuart Cracraft
 

开云体育

I run Ubuntu on AWS and twsapi on it plus check it daily as I think their client side automation is weak.?

Clumsy, and in the case of IB, necessary.?

Unfortunate!

Anyone used alpaca?

On Jun 2, 2021, at 12:46 PM, RobDawg35 <rob.sandberg26@...> wrote:

?
Hi all,?

I have also had this problem and am currently switching to run this on a server. I am going to be paying around $20-40/month.?

I am in-between using "VULTR" or spinning up an EC2 instance then creating a UI for Linux on the server.?

Best,
Rob

On Wed, Jun 2, 2021 at 12:32 AM Despair <boris@...> wrote:
The problem is not the reconnection to the API. The problem is the TWS shuts down completely. So I have to restart the TWS manually before the client can connect to it again.


 

I have not used Alpaca....would using Gateway over TWS be more beneficial on an AWS instance?


On Wed, Jun 2, 2021 at 2:28 PM Stuart Cracraft via <smcracraft=[email protected]> wrote:
I run Ubuntu on AWS and twsapi on it plus check it daily as I think their client side automation is weak.?

Clumsy, and in the case of IB, necessary.?

Unfortunate!

Anyone used alpaca?

On Jun 2, 2021, at 12:46 PM, RobDawg35 <rob.sandberg26@...> wrote:

?
Hi all,?

I have also had this problem and am currently switching to run this on a server. I am going to be paying around $20-40/month.?

I am in-between using "VULTR" or spinning up an EC2 instance then creating a UI for Linux on the server.?

Best,
Rob

On Wed, Jun 2, 2021 at 12:32 AM Despair <boris@...> wrote:
The problem is not the reconnection to the API. The problem is the TWS shuts down completely. So I have to restart the TWS manually before the client can connect to it again.


Stuart Cracraft
 

开云体育

What is needed is a thin auto-restarting Linux client using systemctl with auto-login after outages, maintenances and whenever it disconnects.?

Otherwise, this requires too much hand-holding.?

My two cents.?

On Jun 2, 2021, at 1:47 PM, RobDawg35 <rob.sandberg26@...> wrote:

?
I have not used Alpaca....would using Gateway over TWS be more beneficial on an AWS instance?

On Wed, Jun 2, 2021 at 2:28 PM Stuart Cracraft via <smcracraft=[email protected]> wrote:
I run Ubuntu on AWS and twsapi on it plus check it daily as I think their client side automation is weak.?

Clumsy, and in the case of IB, necessary.?

Unfortunate!

Anyone used alpaca?

On Jun 2, 2021, at 12:46 PM, RobDawg35 <rob.sandberg26@...> wrote:

?
Hi all,?

I have also had this problem and am currently switching to run this on a server. I am going to be paying around $20-40/month.?

I am in-between using "VULTR" or spinning up an EC2 instance then creating a UI for Linux on the server.?

Best,
Rob

On Wed, Jun 2, 2021 at 12:32 AM Despair <boris@...> wrote:
The problem is not the reconnection to the API. The problem is the TWS shuts down completely. So I have to restart the TWS manually before the client can connect to it again.


Stuart Cracraft
 

开云体育

Conversely a full on API without the intermediary step….?

On Jun 2, 2021, at 2:02 PM, Stuart Cracraft via groups.io <smcracraft@...> wrote:

?
What is needed is a thin auto-restarting Linux client using systemctl with auto-login after outages, maintenances and whenever it disconnects.?

Otherwise, this requires too much hand-holding.?

My two cents.?

On Jun 2, 2021, at 1:47 PM, RobDawg35 <rob.sandberg26@...> wrote:

?
I have not used Alpaca....would using Gateway over TWS be more beneficial on an AWS instance?

On Wed, Jun 2, 2021 at 2:28 PM Stuart Cracraft via <smcracraft=[email protected]> wrote:
I run Ubuntu on AWS and twsapi on it plus check it daily as I think their client side automation is weak.?

Clumsy, and in the case of IB, necessary.?

Unfortunate!

Anyone used alpaca?

On Jun 2, 2021, at 12:46 PM, RobDawg35 <rob.sandberg26@...> wrote:

?
Hi all,?

I have also had this problem and am currently switching to run this on a server. I am going to be paying around $20-40/month.?

I am in-between using "VULTR" or spinning up an EC2 instance then creating a UI for Linux on the server.?

Best,
Rob

On Wed, Jun 2, 2021 at 12:32 AM Despair <boris@...> wrote:
The problem is not the reconnection to the API. The problem is the TWS shuts down completely. So I have to restart the TWS manually before the client can connect to it again.


 

I do not think it would be too difficult to spin up that linux command, no?


On Wed, Jun 2, 2021 at 3:07 PM Stuart Cracraft via <smcracraft=[email protected]> wrote:
Conversely a full on API without the intermediary step….?

On Jun 2, 2021, at 2:02 PM, Stuart Cracraft via <smcracraft=[email protected]> wrote:

?
What is needed is a thin auto-restarting Linux client using systemctl with auto-login after outages, maintenances and whenever it disconnects.?

Otherwise, this requires too much hand-holding.?

My two cents.?

On Jun 2, 2021, at 1:47 PM, RobDawg35 <rob.sandberg26@...> wrote:

?
I have not used Alpaca....would using Gateway over TWS be more beneficial on an AWS instance?

On Wed, Jun 2, 2021 at 2:28 PM Stuart Cracraft via <smcracraft=[email protected]> wrote:
I run Ubuntu on AWS and twsapi on it plus check it daily as I think their client side automation is weak.?

Clumsy, and in the case of IB, necessary.?

Unfortunate!

Anyone used alpaca?

On Jun 2, 2021, at 12:46 PM, RobDawg35 <rob.sandberg26@...> wrote:

?
Hi all,?

I have also had this problem and am currently switching to run this on a server. I am going to be paying around $20-40/month.?

I am in-between using "VULTR" or spinning up an EC2 instance then creating a UI for Linux on the server.?

Best,
Rob

On Wed, Jun 2, 2021 at 12:32 AM Despair <boris@...> wrote:
The problem is not the reconnection to the API. The problem is the TWS shuts down completely. So I have to restart the TWS manually before the client can connect to it again.


Stuart Cracraft
 

开云体育

The IB Gateway seems insufficient and you certainly wouldn’t try it with the TWS app…

On Jun 2, 2021, at 2:48 PM, RobDawg35 <rob.sandberg26@...> wrote:

?
I do not think it would be too difficult to spin up that linux command, no?

On Wed, Jun 2, 2021 at 3:07 PM Stuart Cracraft via <smcracraft=[email protected]> wrote:
Conversely a full on API without the intermediary step….?

On Jun 2, 2021, at 2:02 PM, Stuart Cracraft via <smcracraft=[email protected]> wrote:

?
What is needed is a thin auto-restarting Linux client using systemctl with auto-login after outages, maintenances and whenever it disconnects.?

Otherwise, this requires too much hand-holding.?

My two cents.?

On Jun 2, 2021, at 1:47 PM, RobDawg35 <rob.sandberg26@...> wrote:

?
I have not used Alpaca....would using Gateway over TWS be more beneficial on an AWS instance?

On Wed, Jun 2, 2021 at 2:28 PM Stuart Cracraft via <smcracraft=[email protected]> wrote:
I run Ubuntu on AWS and twsapi on it plus check it daily as I think their client side automation is weak.?

Clumsy, and in the case of IB, necessary.?

Unfortunate!

Anyone used alpaca?

On Jun 2, 2021, at 12:46 PM, RobDawg35 <rob.sandberg26@...> wrote:

?
Hi all,?

I have also had this problem and am currently switching to run this on a server. I am going to be paying around $20-40/month.?

I am in-between using "VULTR" or spinning up an EC2 instance then creating a UI for Linux on the server.?

Best,
Rob

On Wed, Jun 2, 2021 at 12:32 AM Despair <boris@...> wrote:
The problem is not the reconnection to the API. The problem is the TWS shuts down completely. So I have to restart the TWS manually before the client can connect to it again.


 

Why do you think the gateway is insufficient? In my experience it is considerably faster than the TWS and works great. The only thing is that you don't see things like you do with the TWS.

And to return to my original question. Isn't there a setting that controls the TWS behaviour at the loss of connection. I don't see why it shouldn't reconnect like the gateway does.


GUY
 

Hello everyone

I have been French and computer scientist for over 30 years. I am 72 years old and I have been using python for 6 months. I have developed an API to process the eurusd. When you are French, you absolutely have to preserve your euro capital? This is what my API does. I also ran into the shutdown of TWS. To remedy this, check the automatic restart box in the general configuration from "modification", "lock and exit" and specify the time for the automatic restart.

You should know that IB reboots its servers at 0am US time, ie 6am French time. It is therefore necessary to program the automatic restart after 0 hours to allow the reboots to take place. But this is not enough if you have an API that works 24 hours a day, you have to restart your API also automatically AFTER the TWS reboot. For that I use a DOS .bat to restart

. I hope I answered the question

Good weekend to all

cordially

Guy

?

?

?

?

> Message du 02/06/21 21:46
> De : "RobDawg35" <rob.sandberg26@...>
> A : "[email protected] Group Moderators" <[email protected]>
> Copie à :
> Objet : Re: [TWS API] TWS vs Gateway at reconnections
>
>
Hi all,?

>
I have also had this problem and am currently switching to run this on a server. I am going to be paying around $20-40/month.?

>
I am in-between using "VULTR" or spinning up an EC2 instance then creating a UI for Linux on the server.?

>
Best,
Rob

>
On Wed, Jun 2, 2021 at 12:32 AM Despair <boris@...> wrote:
>
The problem is not the reconnection to the API. The problem is the TWS shuts down completely. So I have to restart the TWS manually before the client can connect to it again.

>

>