diff --git a/QuantConnect.IBAutomater/IBAutomater.cs b/QuantConnect.IBAutomater/IBAutomater.cs index 21a90f3..8bfa2f6 100644 --- a/QuantConnect.IBAutomater/IBAutomater.cs +++ b/QuantConnect.IBAutomater/IBAutomater.cs @@ -893,6 +893,38 @@ public bool IsRunning() { if (_process == null) { + // Check if there's an existing IB Gateway process running + // This handles the case where IB Gateway was started manually + if (IsWindows) + { + var ibGatewayProcesses = Process.GetProcessesByName(_ibGatewayExecutableName.Replace(".exe", "")); + if (ibGatewayProcesses.Length > 0) + { + OutputDataReceived?.Invoke(this, new OutputDataReceivedEventArgs( + $"Found existing IB Gateway process (PID: {ibGatewayProcesses[0].Id}). Will reuse it.")); + return true; + } + } + else + { + var javaProcesses = Process.GetProcessesByName("java"); + foreach (var proc in javaProcesses) + { + try + { + if (proc.MainModule?.FileName?.Contains("ibgateway") == true) + { + OutputDataReceived?.Invoke(this, new OutputDataReceivedEventArgs( + $"Found existing IB Gateway java process (PID: {proc.Id}). Will reuse it.")); + return true; + } + } + catch + { + // Ignore access denied exceptions + } + } + } return false; }