Skip to main content

6. Connect Xerolite to IB TWS

Once TWS/IB Gateway is configured for API access, you can connect XeroLite to Interactive Brokers. This section guides you through establishing the connection.

Prerequisites

6.1: Ensure TWS Is Running

  1. Launch TWS or IB Gateway:
    • Open Trader Workstation or IB Gateway
    • Log in with your Interactive Brokers credentials
    • Ensure you're connected to IB servers (check connection status)
  2. Verify API Settings:
    • Confirm API access is enabled (port 7497)
    • Ensure TWS/IB Gateway is not in read-only mode
  3. Keep TWS Running:
    • TWS/IB Gateway must remain running while XeroLite is active
    • Do not close TWS/IB Gateway during trading operations

6.2: Open Broker Connection Settings

  1. Log in to XeroLite:
    • Open your web browser
    • Navigate to http://localhost or your server's IP address
    • Log in with your XeroLite credentials
  2. Navigate to Connection Settings:
    • Look for Broker Connection, Connections, or Settings in the menu
    • This is typically found in the main navigation or settings section
  3. Select Broker Configuration:
    • Click on the broker connection settings
    • You should see options for configuring broker connections

6.3: Select Interactive Brokers

  1. Choose Broker:
    • Select Interactive Brokers from the list of available brokers
    • If you see multiple broker options, ensure Interactive Brokers is selected
  2. Verify Broker Selection:
    • Confirm that Interactive Brokers is highlighted or selected
    • The interface should show IB-specific configuration options

6.4: Set Connection Mode

  1. Connection Type:
    • XeroLite typically auto-detects TWS/IB Gateway
    • Ensure the connection mode is set to use the local TWS/IB Gateway instance
  2. Port Configuration:
    • Verify the port matches your TWS API settings (default: 7497)
    • For paper trading: typically port 7497
    • For live trading: typically port 7496 or 7497
  3. Connection Parameters:
    • Host should be set to 127.0.0.1 or localhost
    • Client ID can usually be left at default (0) unless you have multiple connections

6.5: Connect to IB

  1. Initiate Connection:
    • Click Connect, Save, or Apply button
    • XeroLite will attempt to connect to TWS/IB Gateway
  2. Wait for Connection:
    • The connection process may take a few seconds
    • Watch for connection status indicators
  3. Verify Connection Status:
    • Look for a green status indicator or "Connected" message
    • The Broker Health indicator should display as connected
    • Account information should appear if connection is successful

Connection Status Indicators

  • Green/Connected: Successfully connected to IB
  • Red/Disconnected: Connection failed or TWS is not running
  • Yellow/Pending: Connection in progress

Automatic Connection

Once properly configured, XeroLite will automatically connect to TWS/IB Gateway when:

  • Both XeroLite and TWS/IB Gateway are running
  • API settings are correctly configured
  • Connection parameters are saved

Troubleshooting

Connection Failed

  • Verify TWS is Running: Ensure TWS/IB Gateway is launched and logged in
  • Check Port: Confirm the port in XeroLite matches TWS API settings (7497)
  • Firewall: Ensure port 7497 is not blocked by firewall
  • Restart Both: Try restarting both TWS and XeroLite

API Settings Not Saving

  • Restart TWS: Restart TWS/IB Gateway after changing API settings
  • Check Permissions: Ensure you have write permissions for TWS configuration
  • Verify Settings: Go back to API settings and confirm they persisted

Next Steps

After successfully connecting, proceed to:


Need more help? Contact support at [email protected]

See also: