### Installing QuantConnect.IBAutomater NuGet Package (PowerShell) Source: https://github.com/quantconnect/ibautomater/blob/master/README.md Provides the command-line instruction for installing the `QuantConnect.IBAutomater` library using the Package Manager Console in Visual Studio. This command downloads the latest version of the NuGet package and adds it as a dependency to the currently selected project in the console's context. ```PowerShell Install-Package QuantConnect.IBAutomater ``` -------------------------------- ### Initializing and Controlling IB Gateway with IBAutomater (C#) Source: https://github.com/quantconnect/ibautomater/blob/master/README.md Demonstrates the basic steps to initialize the `IBAutomater` class, subscribe to its key events for monitoring the IB Gateway process and handling status updates, and programmatically start and stop the gateway instance. It shows the essential methods and events for integrating IBAutomater into a C# application. ```C# using QuantConnect.IBAutomater; // Create a new instance of IBAutomater _ibAutomater = new IBAutomater.IBAutomater(ibDirectory, ibVersion, userName, password, tradingMode, port, exportIbGatewayLogs); // You can bind to event handlers to receive the output data. _ibAutomater.OutputDataReceived += OnIbAutomaterOutputDataReceived; // Gracefully handle errors _ibAutomater.ErrorDataReceived += OnIbAutomaterErrorDataReceived; // Get events once the IB Gateway has exited. _ibAutomater.Exited += OnIbAutomaterExited; // Get events once the IB Gateway has auto-restarted. _ibAutomater.Restarted += OnIbAutomaterRestarted; // Trigger the IB Gateway to start and login with your configured parameters. _ibAutomater.Start(false); // Stop IB Gateway with a simple command. _ibAutomater.Stop(); ``` -------------------------------- ### Creating NuGet Package using dotnet pack (Shell) Source: https://github.com/quantconnect/ibautomater/blob/master/nuget/README.md This command builds the .NET project and creates a NuGet package (.nupkg file) based on the project configuration (.csproj). It requires the .NET SDK to be installed and should be executed from the project directory after updating the version in the .csproj file. ```Shell dotnet pack ``` -------------------------------- ### Setting NuGet API Key for Publishing (Shell) Source: https://github.com/quantconnect/ibautomater/blob/master/nuget/README.md This command configures the NuGet API key locally, which is used for authenticating when publishing packages to a NuGet feed (like nuget.org). It requires the NuGet CLI tool to be installed. The placeholder must be replaced with the actual API key obtained from your NuGet profile. ```Shell nuget setApiKey ``` -------------------------------- ### Handling IB Gateway Exited and Restarted Events with IBAutomater (C#) Source: https://github.com/quantconnect/ibautomater/blob/master/README.md Provides C# example methods for handling the `Exited` and `Restarted` events from the `IBAutomater`. These handlers are essential for responding to IB Gateway lifecycle events, such as auto-restarts or unexpected shutdowns, allowing the client application to reconnect its API or restart the gateway as needed. Includes a helper function to check and report errors from startup results. ```C# private void OnIbAutomaterExited(object sender, ExitedEventArgs e) { // check if IB Gateway was closed because of an IBAutomater error var result = _ibAutomater.GetLastStartResult(); CheckIbAutomaterError(result); if (!result.HasError) { // IB Gateway was closed by IBAutomater because the auto-restart token expired or it was closed manually (less likely) Console.WriteLine("OnIbAutomaterExited(): IB Gateway close detected, restarting IBAutomater in 10 seconds..."); // Wait a few seconds for IB Gateway to shutdown Thread.Sleep(TimeSpan.FromSeconds(10)); try { // Close the client API connection Disconnect(); // Restart IB Gateway CheckIbAutomaterError(_ibAutomater.Start(false)); // Open the client API connection Connect(); } catch (Exception exception) { Console.WriteLine($"OnIbAutomaterExited(): IBAutomaterRestartError - {exception}"); } } } private void OnIbAutomaterRestarted(object sender, EventArgs e) { // check if IB Gateway was closed because of an IBAutomater error var result = _ibAutomater.GetLastStartResult(); CheckIbAutomaterError(result); if (!result.HasError) { // IB Gateway was restarted automatically Console.WriteLine("OnIbAutomaterRestarted(): IB Gateway restart detected, reconnecting..."); try { // Close the client API connection Disconnect(); // Open the client API connection Connect(); } catch (Exception exception) { Console.WriteLine($"OnIbAutomaterRestarted(): IBAutomaterAutoRestartError - {exception}"); } } } private void CheckIbAutomaterError(StartResult result) { if (result.HasError) { // notify the user that an IBAutomater error has occurred Console.WriteLine($"CheckIbAutomaterError(): {result.ErrorCode} - {result.ErrorMessage}"); } } ``` -------------------------------- ### Packaging QuantConnect IBAutomater Project - Shell Source: https://github.com/quantconnect/ibautomater/blob/master/README.md This command packages the QuantConnect.IBAutomater C# project into a NuGet package (.nupkg) using the .NET CLI. It specifies the output directory (./packages), sets the package version using a property, uses the Release configuration, and includes debugging symbols in the package. This is a prerequisite step before publishing the package. ```Shell dotnet pack QuantConnect.IBAutomater/QuantConnect.IBAutomater.csproj --output ./packages -p:PackageVersion=2.0.XXXX --configuration Release --include-symbols ``` -------------------------------- ### Publishing QuantConnect IBAutomater NuGet Package - Shell Source: https://github.com/quantconnect/ibautomater/blob/master/README.md This command pushes the previously generated QuantConnect.IBAutomater.2.0.XXXX.nupkg file to the official NuGet feed (https://api.nuget.org/v3/index.json). It requires a valid API key provided via the --api-key parameter for authentication purposes. This completes the process of making the package available for public or private consumption. ```Shell dotnet nuget push ./packages/QuantConnect.IBAutomater.2.0.XXXX.nupkg --api-key --source https://api.nuget.org/v3/index.json ``` -------------------------------- ### Publishing NuGet Package to nuget.org (Shell) Source: https://github.com/quantconnect/ibautomater/blob/master/nuget/README.md This command uploads the specified NuGet package file (.nupkg) to the target NuGet feed specified by the -Source URL. It requires the NuGet CLI tool and that the API key has been set using 'nuget setApiKey' previously. Ensure the package filename matches the generated .nupkg file. ```Shell nuget push QuantConnect.IBAutomater.1.0.1.nupkg -Source https://api.nuget.org/v3/index.json ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.