### Configuration: Paper Trading Setup Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/MANIFEST.txt Example configuration for setting up IBC in paper trading mode. This is useful for testing strategies without real money. ```properties ib.trading.mode=paper # Other relevant settings for paper trading... ``` -------------------------------- ### Time Format Configuration Examples Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/types.md INI-style examples for setting time-based configurations like shutdown and restart times. Ensure formats match specified patterns. ```ini # Shutdown every Friday at 5 PM ClosedownAt=Friday 17:00 ``` ```ini # Shutdown daily at 10 PM ClosedownAt=22:00 ``` ```ini # Auto-restart every morning at 8 AM AutoRestartTime=08:00 ``` ```ini # Cold restart every Sunday at 6 AM ColdRestartTime=06:00 ``` -------------------------------- ### MenuPath Initialization Examples Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/types.md Demonstrates how to initialize a MenuPath as a String array, representing hierarchical menu structures. ```java new String[]{"File", "Exit"} ``` ```java new String[]{"Edit", "Global Configuration..."} ``` ```java new String[]{"Tools", "API Settings", "Precautions"} ``` -------------------------------- ### Start IBC with config file and trading mode Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Starts the IBC application with a specified configuration file and trading mode. This is a common way to launch IBC for live trading. ```java IbcTws.main(new String[]{"/path/to/config.ini", "LIVETRADING"}); ``` -------------------------------- ### Start IBC Application Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/INDEX.md Launches the IBC application with a specified configuration file. Ensure IBC.jar is in your classpath. ```bash java -cp IBC.jar ibcalpha.ibc.IbcTws /path/to/config.ini ``` -------------------------------- ### Start IBC via Script Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/README.md Provides commands to launch IBC using platform-specific start scripts. ```bash # Linux/macOS ./twsstart.sh # Windows StartTWS.bat ``` -------------------------------- ### DefaultTradingModeManager Example Usage Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/managers.md Example of how to instantiate and initialize the DefaultTradingModeManager with command-line arguments. ```java String[] args = {"config.ini", "user", "pass", "paper"}; TradingModeManager manager = new DefaultTradingModeManager(args); TradingModeManager.initialise(manager); ``` -------------------------------- ### Start IBC with API Credentials Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/README.md Starts the IBC application with API credentials, including optional FIX credentials, for authentication. ```bash # API credentials only java -cp IBC.jar ibcalpha.ibc.IbcTws config.ini user pass paper # FIX and API credentials java -cp IBC.jar ibcalpha.ibc.IbcTws config.ini fixuser fixpass apiuser apipass live ``` -------------------------------- ### CommandPrompt Example Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/types.md Shows how a CommandPrompt is appended after a response, indicating the server is ready for the next command. ```text OK IBC> ENABLEAPI INFO ... OK IBC> ``` -------------------------------- ### Example TWS Build Information Source: https://github.com/ibcalpha/ibc/blob/master/userguide.md This is an example of the build information displayed in TWS, used to determine the major version number for configuration. ```text Build 10.19.1f, Oct 28, 2022 3:03:08 PM ``` -------------------------------- ### Verifying TWS Installation and Version Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/errors.md Shell commands to verify the TWS installation directory and check the TWS major version. This helps diagnose CANT_FIND_ENTRYPOINT errors by ensuring TWS is installed correctly and the version matches the start script configuration. ```bash # Verify TWS installation exists ls -la ~/Jts/ # Linux/macOS ls -la "C:\Jts" # Windows # Check TWS major version # Start TWS manually via IBKR launcher # Check Help > About Trader Workstation # Update start script with correct major version ``` -------------------------------- ### Start IBC Application Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/quick-start.md Launch the IBC application using the provided start scripts or by running the JAR file directly with Java. ```bash # Linux/macOS ./twsstart.sh ``` ```bash # Windows StartTWS.bat ``` ```bash java -cp IBC.jar ibcalpha.ibc.IbcTws ~/ibc/config.ini paper ``` -------------------------------- ### IbcTws.main(String[] args) Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Starts the IBC application with optional configuration arguments. This is the main entry point for users to launch the IBC application. ```APIDOC ## IbcTws.main(String[] args) ### Description Starts the IBC application with optional configuration arguments. This is the main entry point for users to launch the IBC application. ### Method public static void main(final String[] args) throws Exception ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java // Start IBC with config file and trading mode IbcTws.main(new String[]{"/path/to/config.ini", "LIVETRADING"}); // Start IBC with default config location IbcTws.main(new String[]{}); ``` ### Response #### Success Response (void) This method does not return a value. #### Response Example N/A ERROR HANDLING: - Throws: Exception if an unhandled exception occurs ``` -------------------------------- ### IbcTws.load() Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Initializes the application environment after configuration is loaded. This method sets up managers and starts monitoring for TWS/Gateway events. ```APIDOC ## IbcTws.load() ### Description Initializes the application environment after configuration is loaded. This method sets up managers and starts monitoring for TWS/Gateway events. It is typically called internally by `main()`. ### Method public static void load() ### Parameters None ### Request Example ```java // Called internally by main() // Generally not used directly IbcTws.load(); ``` ### Response #### Success Response (void) This method does not return a value. #### Response Example N/A ERROR HANDLING: - Throws: IllegalStateException if shutdown is already in progress ``` -------------------------------- ### IBC Configuration File Format Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/README.md Example of an INI-formatted configuration file for IBC. Comments start with '#', and key-value pairs are separated by '='. ```ini # Comments start with # # Keys and values separated by = IbLoginId=myusername IbPassword=mypassword # Boolean values: yes/no, true/false, 1/0 MinimizeMainWindow=no # Numeric values CommandServerPort=7462 LoginDialogDisplayTimeout=60 # Empty string = default value # IbDir= # Multi-word values ClosedownAt=Friday 22:00 ``` -------------------------------- ### IBC Configuration File Example Source: https://github.com/ibcalpha/ibc/blob/master/userguide.md Configure IBC instances by creating separate `.ini` files. Set `IbDir` to the desired settings folder and provide `IbLoginId` and `IbPassword` for account authentication. ```ini IbDir=C:\JtsLive IbLoginId=your_live_username IbPassword=your_live_password ``` ```ini IbDir=C:\JtsPaper IbLoginId=your_paper_username IbPassword=your_paper_password ``` -------------------------------- ### Docker: Docker Compose Integration Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/MANIFEST.txt Example of integrating IBC into a Docker Compose setup. This allows managing multiple services together. ```yaml version: '3.8' services: ibc: build: . ports: - "7497:7497" volumes: - ./config:/app/config environment: - IB_HOST=localhost - IB_PORT=7497 ``` -------------------------------- ### Invoke Nested Menu Example Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/types.md Provides an example of how to invoke a nested menu item using the Utils.invokeMenuItem method with a MenuPath. ```java // Invoke a nested menu Utils.invokeMenuItem(mainWindow, new String[]{ "Edit", "Global Configuration...", "API", "Settings" }); ``` -------------------------------- ### CommandResponse Examples Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/types.md Illustrates the string-based response format for CommandServer, including OK, ERROR, and INFO types with optional messages. ```text OK OK Goodbye ERROR Command invalid ERROR RESTART is not valid for the FIX Gateway INFO IBC Command Server INFO Session restarting ``` -------------------------------- ### TradingModeManager getTradingMode Example Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/managers.md Example demonstrating how to check if the trading mode is set to paper, ignoring case. ```java if ("paper".equalsIgnoreCase( TradingModeManager.tradingModeManager().getTradingMode())) { // Paper trading } ``` -------------------------------- ### Start IBC with default config location Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Starts the IBC application using the default configuration file location. This is useful for quick startup when default settings are sufficient. ```java IbcTws.main(new String[]{}); ``` -------------------------------- ### Configuration: Live Trading with API Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/MANIFEST.txt Configuration example for live trading using the IBC API. Ensure all security and connection details are correctly set. ```properties ib.trading.mode=live ib.login.id=your_username ib.password=your_password # API specific settings... ``` -------------------------------- ### ConfigPath String Array Example Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/types.md Represents a path within the configuration dialog tree. Use this to navigate or specify sections. ```java new String[]{"API", "Settings"} ``` ```java new String[]{"Lock and Exit"} ``` ```java new String[]{"Defaults", "Orders"} ``` -------------------------------- ### Run gatewaystart.sh every 15 minutes (Linux) Source: https://github.com/ibcalpha/ibc/blob/master/userguide.md Crontab entry to periodically attempt starting the gateway, which will only succeed if IBC is not already running. This is useful for automatic restarts. ```bash 0,15,30,45 * * * 1-5 export DISPLAY=:10 && /bin/bash /opt/ibc/gatewaystart.sh ``` -------------------------------- ### Creating Separate Start Scripts Source: https://github.com/ibcalpha/ibc/blob/master/userguide.md Create distinct start scripts for each TWS instance by copying a base script and modifying configuration and log paths. This ensures each instance uses its own settings and logs. ```batch @echo off set CONFIG=configLive.ini set LOG_PATH=%IBC_PATH%\LiveLogs call StartTWS.bat ``` ```batch @echo off set CONFIG=configPaper.ini set LOG_PATH=%IBC_PATH%\PaperLogs call StartTWS.bat ``` -------------------------------- ### IBC Command Server Prompt Example Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/endpoints.md Shows how the command prompt appears after a response when the CommandPrompt setting is configured. This indicates the server is ready for the next command. ```text OK IBC> ``` -------------------------------- ### startSession() Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Marks the session as started and initiates the monitoring process for the login dialog display. This is typically called internally during initialization. ```APIDOC ## startSession() ### Description Marks the session as started and initiates the monitoring process for the login dialog display. This is typically called internally during initialization. ### Method static void startSession() ### Request Example ```java // Called internally during IBC initialization SessionManager.startSession(); ``` ``` -------------------------------- ### Bash Script: Startup and Shutdown Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/MANIFEST.txt Provides bash scripts for starting and shutting down the IBC service. These are useful for automation. ```bash # Example startup script /path/to/ibc/start.sh # Example shutdown script /path/to/ibc/stop.sh ``` -------------------------------- ### OK Messages Examples Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/endpoints.md Examples of 'OK' messages indicating successful command completion. This includes a simple success message and a message for the EXIT command. ```text OK # Simple success OK Goodbye # EXIT command ``` -------------------------------- ### IBC Command Protocol Example Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/README.md Demonstrates connecting to the IBC command server via telnet, sending commands like ENABLEAPI and EXIT, and observing server responses. ```text # Connect telnet localhost 7462 # Server sends greeting INFO IBC Command Server # Send command (case-insensitive) ENABLEAPI # Server responds OK IBC> # Send more commands or exit EXIT OK Goodbye ``` -------------------------------- ### ERROR Messages Examples Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/endpoints.md Examples of 'ERROR' messages indicating command failure or invalid input. These messages help diagnose issues with command execution. ```text ERROR Command invalid # Unknown command ERROR RESTART not valid... # Invalid for this session ``` -------------------------------- ### Systemd: Process Management Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/MANIFEST.txt Illustrates systemd commands for managing the IBC service, such as starting, stopping, and checking its status. Assumes a systemd unit file is configured. ```bash # Start the IBC service systemctl start ibc.service # Stop the IBC service systemctl stop ibc.service # Check the status of the IBC service systemctl status ibc.service ``` -------------------------------- ### Configure IBC as a Systemd Service Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/quick-start.md This systemd service file configures IBC to run as a background service. It specifies the user, working directory, and restart behavior. Start the service with `sudo systemctl start ibc`. ```ini [Unit] Description=IBC Automated Trading After=network.target StartLimitIntervalSec=0 [Service] Type=simple User=trader WorkingDirectory=/opt/ibc ExecStart=/opt/ibc/twsstart.sh Restart=always RestartSec=10 [Install] WantedBy=multi-user.target ``` -------------------------------- ### Singleton Manager Access Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/managers.md Provides static facade methods to access initialized managers after their setup is complete. ```plaintext Settings.settings() SessionManager.isGateway() LoginManager.loginManager() MainWindowManager.mainWindowManager() ConfigDialogManager.configDialogManager() TradingModeManager.tradingModeManager() ``` -------------------------------- ### Run gatewaystart.sh at 08:00 on Mondays (Linux) Source: https://github.com/ibcalpha/ibc/blob/master/userguide.md Example crontab entry to run the gatewaystart.sh script at a specific time on a particular day. Ensure the DISPLAY variable is set correctly for your system. ```bash * 8 * * 1 export DISPLAY=:10 && /bin/bash /opt/ibc/gatewaystart.sh ``` -------------------------------- ### Telnet: Interactive Command Session Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/MANIFEST.txt An example of initiating an interactive command session with IBC using telnet. Useful for manual testing and exploration. ```bash telnet localhost 7497 # Once connected, you can type commands like EXIT, STOP, etc. ``` -------------------------------- ### IBC Configuration Settings Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/INDEX.md Example INI file format for IBC configuration. Specifies login credentials and the command server port. ```ini IbLoginId=username IbPassword=password CommandServerPort=7462 ``` -------------------------------- ### Configuration: FIX Gateway Configuration Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/MANIFEST.txt Example configuration for setting up IBC to work with a FIX Gateway. This involves specific connection and authentication parameters. ```properties ib.fix.mode=true ib.fix.host=fix.gateway.com ib.fix.port=10000 # Other FIX specific settings... ``` -------------------------------- ### Error Code: 1107 - Can't find TWS entry point Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/MANIFEST.txt The entry point for the TWS/Gateway application could not be found. Verify the installation path. ```text 1107 ``` -------------------------------- ### Build Docker Image for IBC Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/quick-start.md Use this Dockerfile to build a container image for IBC. It installs TWS and IBC, copies the configuration, and sets the command to run IBC. ```docker FROM openjdk:17-slim # Install TWS (offline version) COPY Jts.zip /tmp/ RUN unzip /tmp/Jts.zip -d /root/ # Install IBC COPY IBC.zip /tmp/ RUN unzip /tmp/IBC.zip -d /opt/ibc/ # Config file COPY config.ini /root/.ibc/config.ini RUN chmod 600 /root/.ibc/config.ini # Run IBC WORKDIR /opt/ibc CMD ["java", "-cp", "IBC.jar", "ibcalpha.ibc.IbcTws", "/root/.ibc/config.ini"] ``` -------------------------------- ### Initialize IBC Settings and Login Manager in Java Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/INDEX.md Initializes the IBC application's settings and login manager using provided arguments. This is a common setup step for Java integration. ```java Settings.initialise(new DefaultSettings(args)); LoginManager.initialise(new DefaultLoginManager(args)); ``` -------------------------------- ### Bash Script: Daily Restart Automation Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/MANIFEST.txt A bash script example for automating the daily restart of the IBC service. This ensures continuous operation. ```bash # Script to automate daily IBC restart /path/to/ibc/stop.sh sleep 10 /path/to/ibc/start.sh ``` -------------------------------- ### Initialize Settings with Command-Line Args Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/managers.md Creates a settings provider using a path specified in command-line arguments or a default location. Throws IllegalStateException if the file doesn't exist. ```java public DefaultSettings(String[] args) ``` ```java String[] args = {"/etc/ibc/config.ini"}; Settings settings = new DefaultSettings(args); Settings.initialise(settings); ``` -------------------------------- ### Initialize IBC application environment Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Initializes the IBC application environment, including setting up managers and starting the command server. This method is typically called internally by main() and not used directly. ```java IbcTws.load(); ``` -------------------------------- ### Initialize IBC for Gateway mode Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Initializes all application managers with their default implementations for running in Gateway mode. This method is part of the internal setup process. ```java IbcTws.setupDefaultEnvironment(args, true); ``` -------------------------------- ### Automated Login and API Enablement Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/quick-start.md Starts IBC with automatic login using credentials from a config file and then enables the API via a remote command. Ensure the config.ini file is present and accessible. ```bash # config.ini has credentials # Start IBC - logs in automatically java -cp IBC.jar ibcalpha.ibc.IbcTws config.ini # Wait for login (2-5 seconds typically) sleep 5 # Enable API via remote command echo "ENABLEAPI" | nc localhost 7462 ``` -------------------------------- ### Configuring Multiple TWS Versions Source: https://github.com/ibcalpha/ibc/blob/master/userguide.md When running different TWS versions simultaneously, ensure each start script correctly specifies the `TWS_MAJOR_VRSN` variable corresponding to the installed version. ```batch set TWS_MAJOR_VRSN=952 ``` -------------------------------- ### Create and Secure IBC Configuration File Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/quick-start.md Use these commands to create a directory and copy the sample config.ini file, then set appropriate permissions for security. ```bash # Linux/macOS mkdir -p ~/ibc cp /path/to/ibc/config.ini ~/ibc/config.ini chmod 600 ~/ibc/config.ini ``` ```bash # Windows mkdir "%USERPROFILE%\Documents\IBC" copy C:\IBC\config.ini "%USERPROFILE%\Documents\IBC\config.ini" ``` -------------------------------- ### INFO Messages Examples Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/endpoints.md Examples of informational messages providing progress feedback. These messages are suppressed if 'SuppressInfoMessages' is set to 'yes'. ```text INFO IBC Command Server # Sent on connection INFO Session restarting # During restart ``` -------------------------------- ### initialise Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Sets the global main window manager instance. This method should be called once to establish the manager. ```APIDOC ## initialise(MainWindowManager mainWindowManager) ### Description Sets the global main window manager instance. ### Method public static void initialise(MainWindowManager mainWindowManager) ### Parameters #### Path Parameters - **mainWindowManager** (MainWindowManager) - Required - MainWindowManager implementation ### Throws - IllegalArgumentException if mainWindowManager is null ### Request Example ```java MainWindowManager manager = new DefaultMainWindowManager(); MainWindowManager.initialise(manager); ``` ``` -------------------------------- ### IbcTws.setupDefaultEnvironment(String[] args, boolean isGateway) Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Initializes all application managers with their default implementations. This method is used to set up the environment for either TWS or Gateway. ```APIDOC ## IbcTws.setupDefaultEnvironment(String[] args, boolean isGateway) ### Description Initializes all application managers with their default implementations. This method is used to set up the environment for either TWS or Gateway. ### Method static void setupDefaultEnvironment(final String[] args, final boolean isGateway) throws Exception ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### args (String[]) - Required - Command-line arguments passed from main #### isGateway (boolean) - Required - true if running Gateway, false if running TWS ### Request Example ```java // Initialize for TWS mode IbcTws.setupDefaultEnvironment(args, false); // Initialize for Gateway mode IbcTws.setupDefaultEnvironment(args, true); ``` ### Response #### Success Response (void) This method does not return a value. #### Response Example N/A ERROR HANDLING: - Throws: Exception if initialization fails ``` -------------------------------- ### IBC Command Server Configuration Example Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/endpoints.md This INI configuration sets the command server port, bind address, and allowed control IP addresses. Ensure these settings align with your network security policies. ```ini CommandServerPort=7462 BindAddress=0.0.0.0 ControlFrom=192.168.1.100,192.168.1.101,office.example.com ``` -------------------------------- ### Initialize Settings with Explicit File Path Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/managers.md Creates a settings provider with an explicitly provided file path. Throws IllegalStateException if the path is not a file. ```java public DefaultSettings(String path) ``` ```java Settings settings = new DefaultSettings("/home/trader/ibc/config.ini"); Settings.initialise(settings); ``` -------------------------------- ### Start the SessionManager session Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Marks the session as started and initiates monitoring for the login dialog display. This is typically called internally during IBC initialization. ```java static void startSession() ``` ```java // Called internally during IBC initialization SessionManager.startSession(); ``` -------------------------------- ### Custom Settings Implementation Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/managers.md Demonstrates how to replace the default Settings manager with a custom implementation, such as one loading settings from a database. ```java // Custom settings from database class DatabaseSettings extends Settings { // Implementation } Settings.initialise(new DatabaseSettings()); ``` -------------------------------- ### Error Code: 1106 - Can't create settings directory Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/MANIFEST.txt IBC was unable to create the directory for storing settings. Check file system permissions. ```text 1106 ``` -------------------------------- ### Python Client: Basic Command Sending Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/MANIFEST.txt Demonstrates how to send a basic command using the Python client. Ensure the client is properly initialized. ```python from ibc.client import IbcClient client = IbcClient(host='localhost', port=7497) client.connect() # Example: Send a command (replace with actual command) response = client.send_command('SOME_COMMAND') print(response) client.disconnect() ``` -------------------------------- ### Initialize Settings with Default INI Path Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/managers.md Creates a settings provider using the default INI file location. Default paths vary by OS. ```java public DefaultSettings() ``` ```java Settings settings = new DefaultSettings(); Settings.initialise(settings); ``` -------------------------------- ### Get ConfigDialogManager Instance Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Returns the global config dialog manager instance. ```java public static ConfigDialogManager configDialogManager() ``` ```java JDialog dialog = ConfigDialogManager.configDialogManager() .getConfigDialog(); ``` -------------------------------- ### commandServer() Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Returns the singleton command server instance. ```APIDOC ## commandServer() ### Description Returns the singleton command server instance. ### Returns - CommandServer: the global command server. ### Example ```java CommandServer server = CommandServer.commandServer(); server.shutdown(); ``` ``` -------------------------------- ### Get Singleton CommandServer Instance Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Returns the singleton CommandServer instance. This is used to access the global command server. ```java CommandServer server = CommandServer.commandServer(); server.shutdown(); ``` -------------------------------- ### Get MainWindowManager Instance Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Retrieves the current global main window manager instance. This is used to access the main window. ```java JFrame window = MainWindowManager.mainWindowManager().getMainWindow(); ``` -------------------------------- ### Accessing Configuration Settings Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/configuration.md Demonstrates how to retrieve string, integer, and boolean settings from the IBC configuration using the Settings singleton. Invalid values or missing settings will gracefully fall back to their default values. ```java Settings.settings().getString("IbLoginId", "") Settings.settings().getInt("CommandServerPort", 0) Settings.settings().getBoolean("MinimizeMainWindow", false) ``` -------------------------------- ### DefaultSettings(String[] args) Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/managers.md Creates a settings provider using a path from command-line arguments or the default location. It handles different argument values for path resolution. ```APIDOC ## DefaultSettings(String[] args) ### Description Creates settings provider using path from command-line args or default. **Path Resolution:** - If args[0] is "NULL": use `config..ini` in working directory - If args[0] is empty: use default location - Otherwise: use args[0] as file path **Throws:** IllegalStateException if file doesn't exist ### Method Constructor ### Endpoint N/A ### Parameters #### Path Parameters - **args** (String[]) - Required - Command-line arguments; first element is INI file path ### Request Example ```java String[] args = {"/etc/ibc/config.ini"}; Settings settings = new DefaultSettings(args); Settings.initialise(settings); ``` ### Response #### Success Response Creates a `DefaultSettings` object. #### Response Example ```java String[] args = {"/etc/ibc/config.ini"}; Settings settings = new DefaultSettings(args); ``` ``` -------------------------------- ### Get LoginManager Instance Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Returns the global login manager instance. This is useful for accessing login-related functionalities throughout the application. ```java public static LoginManager loginManager() ``` ```java LoginManager mgr = LoginManager.loginManager(); LoginManager.LoginState state = mgr.getLoginState(); ``` -------------------------------- ### Run TWS with FIX and API Credentials via Command Line Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/configuration.md This command demonstrates launching the IBC TWS application with both FIX and API credentials, along with the live trading mode, specified via the command line. ```bash java -cp IBC.jar ibcalpha.ibc.IbcTws config.ini fixuser fixpass apiuser apipass live ``` -------------------------------- ### Get String Configuration Value Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Retrieves a string configuration value by its key. Returns a default value if the key is not found. ```java public abstract String getString(String key, String defaultValue) ``` ```java String username = Settings.settings().getString("IbLoginId", ""); String closedownTime = Settings.settings().getString("ClosedownAt", ""); ``` -------------------------------- ### Settings.initialise Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Sets the global settings instance. This method is used to configure the application with a specific settings provider. ```APIDOC ## initialise(Settings settings) ### Description Sets the global settings instance. ### Method `initialise` ### Parameters #### Path Parameters - **settings** (Settings) - Required - Settings implementation to use globally ### Request Example ```java Settings settings = new DefaultSettings("/path/to/config.ini"); Settings.initialise(settings); ``` ### Throws IllegalArgumentException if settings is null ``` -------------------------------- ### Get Global Settings Instance Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Retrieves the currently active global settings instance. This instance can then be used to access configuration values. ```java public static Settings settings() ``` ```java Settings settings = Settings.settings(); String username = settings.getString("IbLoginId", ""); int port = settings.getInt("CommandServerPort", 0); ``` -------------------------------- ### Error Code: 1103 - Config file not found Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/MANIFEST.txt The specified configuration file could not be located. Ensure the file path is correct and the file exists. ```text 1103 ``` -------------------------------- ### Get String Setting Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/managers.md Retrieves a string setting value. Handles empty strings and trims whitespace. Key matching is case-insensitive. ```java public String getString(String key, String defaultValue) ``` ```java String username = Settings.settings().getString("IbLoginId", ""); ``` ```java String dir = Settings.settings().getString("IbDir", System.getProperty("user.dir")); ``` -------------------------------- ### IBC Startup Flow Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/architecture.md Illustrates the sequence of operations during the IBC application's startup, from argument validation to launching the TWS or Gateway. ```text IbcTws.main(args) ↓ IbcTws.checkArguments() - Validate arg count ↓ IbcTws.setupDefaultEnvironment() ├→ SessionManager.initialise(isGateway) ├→ Settings.initialise(new DefaultSettings(args)) ├→ LoginManager.initialise(new DefaultLoginManager(args)) ├→ MainWindowManager.initialise(new DefaultMainWindowManager()) └→ TradingModeManager.initialise(new DefaultTradingModeManager(args)) ↓ IbcTws.load() ├→ Print version info ├→ Log system properties and settings ├→ Start CommandServer (in thread pool) ├→ Schedule shutdown/restart timers ├→ Create toolkit listener with handlers ├→ Start TWS/Gateway settings auto-saver └→ Launch TWS or Gateway (blocks until exit) ``` -------------------------------- ### General Command-Line Argument Format for IbcTws Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/configuration.md This illustrates the general syntax for passing configuration parameters to the IbcTws application via the command line, showing different argument combinations. ```bash IbcTws [iniFile] [tradingMode] ``` ```bash IbcTws [iniFile] [apiUserName] [apiPassword] [tradingMode] ``` ```bash IbcTws [iniFile] [fixUserName] [fixPassword] [apiUserName] [apiPassword] [tradingMode] ``` -------------------------------- ### Python Client: Session Management Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/MANIFEST.txt Illustrates how to manage sessions using the Python client. This includes connecting, disconnecting, and potentially handling session state. ```python from ibc.client import IbcClient client = IbcClient(host='localhost', port=7497) # Establish connection client.connect() print("Connected to IBC.") # Perform session operations... # Close connection client.disconnect() print("Disconnected from IBC.") ``` -------------------------------- ### Get Main Window (Blocking) Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Retrieves the main window, blocking until it becomes available. Avoid calling this from the Swing event dispatch thread. ```java JFrame window = MainWindowManager.mainWindowManager().getMainWindow(); if (window != null) { window.setVisible(false); // Minimize } ``` -------------------------------- ### Select Config Section Usage Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/types.md Demonstrates how to use the Utils.selectConfigSection method with a ConfigPath. ```java // Select section in config dialog Utils.selectConfigSection(configDialog, new String[]{"API", "Settings"}); ``` -------------------------------- ### CommandServer() Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Creates a new command server instance. Only one instance is permitted. Throws IllegalArgumentException if an instance already exists. ```APIDOC ## CommandServer() ### Description Creates a new command server instance. Only one instance is permitted. ### Throws - IllegalArgumentException: if an instance already exists. ### Example ```java CommandServer server = new CommandServer(); MyCachedThreadPool.getInstance().execute(server); ``` ``` -------------------------------- ### Get Login State Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Retrieves the current login state of the user. Check this state to determine if the user is logged in, logging in, or in another state. ```java public LoginState getLoginState() ``` ```java LoginManager.LoginState state = LoginManager.loginManager().getLoginState(); if (state == LoginManager.LoginState.LOGGED_IN) { // User is logged in } ``` -------------------------------- ### Get Double Configuration Value Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Retrieves a double configuration value by its key. Returns a default value if the key is not found or the value is invalid. ```java public abstract double getDouble(String key, double defaultValue) ``` ```java double pi = Settings.settings().getDouble("PiValue", 3.14); double price = Settings.settings().getDouble("DefaultPrice", 100.0); ``` -------------------------------- ### Get Integer Configuration Value Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Retrieves an integer configuration value by its key. Returns a default value if the key is not found or the value is invalid. ```java public abstract int getInt(String key, int defaultValue) ``` ```java int port = Settings.settings().getInt("CommandServerPort", 0); int timeout = Settings.settings().getInt("LoginDialogDisplayTimeout", 60); ``` -------------------------------- ### Get Boolean Configuration Value Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Retrieves a boolean configuration value by its key. Returns a default value if the key is not found or the value is invalid. ```java public abstract boolean getBoolean(String key, boolean defaultValue) ``` ```java boolean readOnly = Settings.settings().getBoolean("ReadOnlyLogin", false); boolean showTrades = Settings.settings().getBoolean("ShowAllTrades", false); ``` -------------------------------- ### Get Double Setting Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/managers.md Retrieves a double setting value. Returns the default value for non-numeric or missing settings without throwing exceptions. ```java public double getDouble(String key, double defaultValue) ``` ```java double value = Settings.settings().getDouble("SomeNumericSetting", 0.0); ``` -------------------------------- ### Get Integer Setting Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/managers.md Retrieves an integer setting value. Returns the default value for non-numeric or missing settings without throwing exceptions. ```java public int getInt(String key, int defaultValue) ``` ```java int port = Settings.settings().getInt("CommandServerPort", 0); ``` ```java int timeout = Settings.settings().getInt("LoginDialogDisplayTimeout", 60); ``` -------------------------------- ### DefaultSettings() Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/managers.md Creates a settings provider using the default INI file location. The default paths vary based on the operating system. ```APIDOC ## DefaultSettings() ### Description Creates settings provider using the default INI file location. **Default Path Resolution:** - Windows: `%USERPROFILE%\Documents\IBC\config.ini` - Linux/macOS: `~/ibc/config.ini` ### Method Constructor ### Endpoint N/A ### Parameters None ### Request Example ```java Settings settings = new DefaultSettings(); Settings.initialise(settings); ``` ### Response #### Success Response Creates a `DefaultSettings` object. #### Response Example ```java Settings settings = new DefaultSettings(); ``` ``` -------------------------------- ### Initialize Global Settings Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Sets the global settings instance for the application. Requires an instance of a Settings implementation. ```java public static void initialise(Settings settings) ``` ```java Settings settings = new DefaultSettings("/path/to/config.ini"); Settings.initialise(settings); ``` -------------------------------- ### Get Global Configuration Dialog Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Returns the Global Configuration dialog, blocking until available. Throws IllegalStateException if called from Swing event dispatch thread. ```java public abstract JDialog getConfigDialog() throws IllegalStateException ``` ```java JDialog dialog = ConfigDialogManager.configDialogManager() .getConfigDialog(); if (dialog != null) { // Configure settings } ``` -------------------------------- ### Get Char Setting Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/managers.md Retrieves a single character setting value. Uses the first character of the value or default. Logs warnings for multi-character values. ```java public char getChar(String key, String defaultValue) ``` ```java char separator = Settings.settings().getChar("FieldSeparator", ","); ``` -------------------------------- ### Get Boolean Setting Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/managers.md Retrieves a boolean setting value. Recognizes various string representations for true and false. Returns the default for invalid values. ```java public boolean getBoolean(String key, boolean defaultValue) ``` ```java boolean minimize = Settings.settings().getBoolean("MinimizeMainWindow", false); ``` ```java boolean showTrades = Settings.settings().getBoolean("ShowAllTrades", false); ``` ```java boolean fixMode = Settings.settings().getBoolean("FIX", false); ``` -------------------------------- ### IBC TWS Command-Line Argument Patterns Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/errors.md Illustrates various valid command-line argument patterns for launching the IbcTws application, ranging from zero to six arguments. ```bash # 0 args: use default config location java -cp IBC.jar ibcalpha.ibc.IbcTws # 1 arg: config file path or "NULL" java -cp IBC.jar ibcalpha.ibc.IbcTws /path/to/config.ini # 2 args: config + trading mode java -cp IBC.jar ibcalpha.ibc.IbcTws config.ini paper # 3 args: config + API user + API pass java -cp IBC.jar ibcalpha.ibc.IbcTws config.ini user pass # 4 args: config + API user + API pass + trading mode java -cp IBC.jar ibcalpha.ibc.IbcTws config.ini user pass paper # 5 args: config + FIX user + FIX pass + API user + API pass java -cp IBC.jar ibcalpha.ibc.IbcTws config.ini fixuser fixpass apiuser apipass # 6 args: config + FIX user + FIX pass + API user + API pass + trading mode java -cp IBC.jar ibcalpha.ibc.IbcTws config.ini fixuser fixpass apiuser apipass paper ``` -------------------------------- ### Initialize IBC for TWS mode Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Initializes all application managers with their default implementations for running in TWS mode. This method is part of the internal setup process. ```java IbcTws.setupDefaultEnvironment(args, false); ``` -------------------------------- ### Settings.settings Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Returns the global settings instance. This allows access to the currently configured settings provider throughout the application. ```APIDOC ## settings() ### Description Returns the global settings instance. ### Method `settings` ### Returns Settings — the current settings provider ### Request Example ```java Settings settings = Settings.settings(); String username = settings.getString("IbLoginId", ""); int port = settings.getInt("CommandServerPort", 0); ``` ``` -------------------------------- ### Check if SessionManager is using FIX protocol Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/api-reference.md Returns `true` if the FIX protocol is being used for the session, `false` otherwise. Throws `IllegalStateException` if called before the session starts. ```java public static boolean isFIX() ``` ```java if (!SessionManager.isFIX()) { // API-specific code } ``` -------------------------------- ### Run TWS with Explicit API Credentials via Command Line Source: https://github.com/ibcalpha/ibc/blob/master/_autodocs/configuration.md This command shows how to launch the IBC TWS application with explicit API credentials and paper trading mode specified on the command line. ```bash java -cp IBC.jar ibcalpha.ibc.IbcTws config.ini apiuser apipass paper ```