QuantConnect / IBAutomater

Automates IB Gateway start, stopping and restarting.
https://www.lean.io
Apache License 2.0
103 stars 37 forks source link

IBAutomater IOException trying to delete IBAutomater.log #86

Open omidkrad opened 1 month ago

omidkrad commented 1 month ago

This always happens when running the project locally.

20240725 21:54:22.571 ERROR:: Engine.Run():  System.IO.IOException: The process cannot access the file 'C:\Jts\ibgateway\1019\IBAutomater.log' because it is being used by another process.
   at System.IO.FileSystem.DeleteFile(String fullPath)
   at System.IO.File.Delete(String path)
   at QuantConnect.IBAutomater.IBAutomater.Start(Boolean waitForExit)
   at QuantConnect.Brokerages.InteractiveBrokers.InteractiveBrokersBrokerage.a(IAlgorithm A_0, IOrderProvider A_1, ISecurityProvider A_2, String A_3, String A_4, Int32 A_5, String A_6, String A_7, String A_8, String A_9, String A_10, String A_11, Boolean A_12, Nullable`1 A_13)
   at QuantConnect.Brokerages.InteractiveBrokers.InteractiveBrokersBrokerage..ctor(IAlgorithm algorithm, IOrderProvider orderProvider, ISecurityProvider securityProvider, String account, String host, Int32 port, String ibDirectory, String ibVersion, String userName, String password, String tradingMode, String agentDescription, Boolean loadExistingHoldings, Nullable`1 weeklyRestartUtcTime)
   at QuantConnect.Brokerages.InteractiveBrokers.InteractiveBrokersBrokerageFactory.CreateBrokerage(LiveNodePacket job, IAlgorithm algorithm)
   at QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler.CreateBrokerage(AlgorithmNodePacket algorithmNodePacket, IAlgorithm uninitializedAlgorithm, IBrokerageFactory& factory)
   at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath, WorkerThread workerThread)

---- REPRO STEPS ---- ibgateway version: 1019 In Launcher project reference the following nuget packages:

In config.json set the following settings:

  "environment": "live-interactive",
  "data-provider": "QuantConnect.Lean.Engine.DataFeeds.DownloaderDataProvider",
  "data-downloader": "QuantConnect.ToolBox.IBDownloader.IBDataDownloader",

  // QC access token
  "job-user-id": "...",
  "api-access-token": "...",
  "job-organization-id": "...",

  // interactive brokers configuration
  "ib-account": "...",
  "ib-user-name": "...",
  "ib-password": "...",
  "ib-host": "127.0.0.1",
  "ib-port": "4002",
  "ib-agent-description": "Individual",
  "ib-tws-dir": "C:\\Jts",
  "ib-version": "1019",
  "ib-trading-mode": "live",
  "ib-enable-delayed-streaming-data": false,
  "ib-weekly-restart-utc-time": "22:00:00",

Run the Launcher

omidkrad commented 1 month ago

I tried to link QuantConnect.Brokerages.InteractiveBrokers by project reference instead of package. The project QuantConnect.Brokerages.InteractiveBrokers references QuantConnect.IBAutomater by project. In QuantConnect.IBAutomater project I tried to put the line that tries to delete IBAutomater.log in try/catch, but for some reason after doing this and running the project only once, IB Gateway stops working altogether. Even trying to run IB Gateway manually won't work and ibgateway process won't load at all. When reverting changes and linking QuantConnect.Brokerages.InteractiveBrokers by package instead of by project, and running the Launcher, then IB Gateway starts again, with the exception happening again:

System.IO.IOException: The process cannot access the file 'C:\Jts\ibgateway\1019\IBAutomater.log' because it is being used by another process.