You are using AgenaTrader in combination with brokerage software Trading Workstation (TWS) from Interactive Broker (IB) or the german based broker Captrader and you want to trade with financial products 24 hours, 7 days a week (24/7)?
Then you certainly know one of the following problems:
- Connection between AgenaTrader and TWS is broken due an unknown problem and you do not want to wait to connect to the broker with TWS the next day.
- Your goal is the use of AgenaTrader and TWS in 24/7 operation on a server, but you do not want the manual reconnection.
- You use RDP (Windows Remote Desktop), but in this case AgenaTrader does not automatically reconnect to TWS after midnight maintenance.
TWS is programmed to complete and close once per day, in most cases at midnight. For this purpose, a pretty good function was programmed into the AgenaTrader which makes an automatic login and restores the connection to the broker. This only works if the server has an user session active. The main problem with remote sessions using RDP on “headless systems” is that the user session is handled differently. This is actually a classic problem on any “real” server, any computer without a monitor, any Virtual Private Server (VPS), or a Microsoft Azure cloud server.
If no user is logged on, nothing happens with the forms which require user input like the login form of the TWS and in this case AgenaTrader is not able to log in automatically to the broker (Interactive Broker or Captrader). If you open an RDP connection, then AgenaTrader automatically connects, because now an user session is active on the server.
This is not a TWS-specific problem, it is a problem of all software programs that require a login step via an user forms. Of course, the software manufacturer could positively influence this situation in which automatic logoff / logon procedures are implemented or the API is opened to a size that this could be done via external program (at your own risk, of course). There is certainly a lot of discussion about the structure and usability of the graphical user interface of the TWS, but the API access is simply unbeatable!
On GitHub an open source project was created which, among other advantages, solves all of the above problems in one fell swoop.
The project is called IBController and allows a much deeper configuration of the TWS as well as an automatic logout / logon.
IBController offers among other things the following advantages (according to the GitHub project from 15.10.2016):
Automates Trader Workstation (TWS) and IB Gateway (including the FIX mode)
Completes login dialog with credentials from an .ini file or command line
Handles dialog boxes which TWS presents during programmatic trading activities
Keeps TWS running indefinitely by handling TWS time-based exits
Allows TWS to be terminated at a specified time on a specified day of the week
Dismisses various dialog messages (eg version updates, daily tips, IB API connections etc)
Exposes a telnet control protocol to STOP the GUI or ENABLEAPI for IB API client access
The IBController project works with the TWS of the Interactive Broker (IB) as well as with the TWS for the broker Captrader.
IBController is open source and has been made available on GitHub.
We have created an quick start to make it easier for you to install IBController:
- Installation IBController for automatic 24h stock trading (part 1)
- Installation IBController for automatic 24h stock trading (part 2)