Hi,
Is it possible to run LEAN with TWS instead of the Gateway on my local machine? I went through the setup and managed to run it with the Gateway but wasn't able to connect to TWS directly...
Thanks
QUANTCONNECT COMMUNITY
Hi,
Is it possible to run LEAN with TWS instead of the Gateway on my local machine? I went through the setup and managed to run it with the Gateway but wasn't able to connect to TWS directly...
Thanks
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Aaron Janeiro Stone
Yes, although the particular version of TWS must be specified in the Launcher config file (it is rather picky about this). What error messages are you receiving upon launching?
Georgea Trading
Thank you, this is what happens when I already have a TWS session open:
20201204 16:23:03.249 Trace:: InteractiveBrokersBrokerage.OnIbAutomaterOutputDataReceived(): IBAutomater error - Code: ExistingSessionDetected Message: An existing session was detected and will not be automatically disconnected. Please close the existing session manually.
20201204 16:23:03.248 Trace:: InteractiveBrokersBrokerage.OnIbAutomaterOutputDataReceived(): Window event: [WINDOW_OPENED] - Window title: [Existing session detected]
20201204 16:23:03.250 Trace:: InteractiveBrokersBrokerage.OnIbAutomaterOutputDataReceived(): Click button: [Exit Application]
20201204 16:23:03.252 ERROR:: Brokerage.OnMessage(): Error - Code: ExistingSessionDetected - An existing session was detected and will not be automatically disconnected. Please close the existing session manually.
20201204 16:23:03.278 ERROR:: LiveTradingResultHandler.Update(): Algorithm not yet initialized.
20201204 16:23:03.325 ERROR:: Engine.Run(): System.Exception: InteractiveBrokersBrokerage.CheckIbAutomaterError(): ExistingSessionDetected - An existing session was detected and will not be automatically disconnected. Please close the existing session manually.
at QuantConnect.Brokerages.InteractiveBrokers.InteractiveBrokersBrokerage.CheckIbAutomaterError(StartResult result, Boolean throwException) in C:\Users\laure\source\repos\Lean\Brokerages\InteractiveBrokers\InteractiveBrokersBrokerage.cs:line 30820201204 16:23:03.328 Trace:: InteractiveBrokersBrokerage.OnIbAutomaterOutputDataReceived(): Window event: [WINDOW_CLOSED] - Window title: [Existing session detected]
1
at QuantConnect.Brokerages.InteractiveBrokers.InteractiveBrokersBrokerage..ctor(IAlgorithm algorithm, IOrderProvider orderProvider, ISecurityProvider securityProvider, IDataAggregator aggregator, String account, String host, Int32 port, String ibDire20201204 16:23:03.330 Trace:: InteractiveBrokersBrokerage.OnIbAutomaterOutputDataReceived(): Window event: [WINDOW_DEACTIVATED] - Window title: [Existing session detected]
ctory, String ibVersion, String userName, String password, String tradingMode, String agentDescription) in C:\Users\laure\source\repos\Lean\Brokerages\InteractiveBrokers\InteractiveBrokersBrokerage.cs:line 260
at QuantConnect.Brokerages.InteractiveBrok20201204 16:23:03.331 Trace:: InteractiveBrokersBrokerage.OnIbAutomaterOutputDataReceived(): Window event: [WINDOW_ACTIVATED] - Window title: [Authenticating...]
ers.InteractiveBrokersBrokerageFactory.CreateBrokerage(LiveNodePacket job, IAlgorithm algorithm) in C:\Users\laure\source\repos\Lean\Brokerages\InteractiveBrokers\InteractiveBrokersBrokerageFactory.cs:line 95
at QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler.CreateBrokerage(AlgorithmNodePacket algorithmNodePacket, IAlgorithm uninitializedAlgorithm, IBrokerageFactory& factory) in C:\Users\laure\source\repos\Lean\Engine\Setup\BrokerageSetupHandler.cs:line 128
at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath, WorkerThread workerThread) in C:\Users\laure\source\repos\Lean\Engine\Engine.cs:line 136
Is there just a way t stop the IB Automater to try to initialize a Gateway session?
Â
Derek Melchin
Hi Georgea,
There can only be one active TWS session. Refer to the IB docs. To resolve this, ensure all other sessions are closed before trying to connect.
Best,
Derek Melchin
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Georgea Trading
Hi, but is it possible to get the TWS started instead of the Gateway? I would like to be able to interact with my account while autotrading without having to have 2 sessions opened.
Derek Melchin
Hi Georgea Trading,
It's not possible. To interact with the account, use the IB website. Alternatively, the QC IDE can be used to add securities and place orders manually in the Holdings Tab.
Best,
Derek Melchin
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Ilshat Garipov
Georgea Trading Hi , I think it's possible to run with TWS, though you would have to change the code a little - because Lean's IB implementation runs IB Gateway automatically, here:
https://github.com/QuantConnect/Lean/blob/master/Brokerages/InteractiveBrokers/InteractiveBrokersBrokerage.cs#L266I believe if you can tweak it the way it does not start the gateway, it is likely that everything will work fine through the TWS too..
Georgea Trading
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!