Skip to content

Can it be deployed to Kubernetes (EKS)? #127

@soujiro0725

Description

@soujiro0725

Is there anyone who has succeeded in deploying it to AWS kubernetes?

I tried and the deployment of the gateway was successful. VNC was visible through a loadbalancer on browsers.
However, API connection was not successful, although it showed like the following.

kubectl get svc ibkr-gateway-us -n trading-infrastructure NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ibkr-gateway-us LoadBalancer 10.xxx.28.xxx acxxxxxxxxxxxxx7feaa38ac-227xxxxxxxxxxxx4a94.elb.ap-northeast-1.amazonaws.com 6080:32047/TCP,8888:30783/TCP 18m

I tried to make a connection like

#!/usr/bin/env python3
"""
Fixed IB Gateway connection test script.
"""

import sys
import time
import logging
from ib_async import *

# Configure logging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)

# Fixed connection parameters
IB_GATEWAY_HOST = "acxxxxxxxxxxxxx7feaa38ac-227xxxxxxxxxxxx4a94.elb.ap-northeast-1.amazonaws.com"
IB_GATEWAY_PORT = 8888 
IB_CLIENT_ID = 8

def test_connection():
    """Test IB Gateway connection"""
    logger.info(f"Testing connection to {IB_GATEWAY_HOST}:{IB_GATEWAY_PORT}")
    
    # Create IB client instance
    ib = IB()
    
    try:
        # Test basic connection first
        logger.info(f"Connecting with clientId {IB_CLIENT_ID}...")
        
        ib.connect(
            IB_GATEWAY_HOST, 
            IB_GATEWAY_PORT, 
            clientId=IB_CLIENT_ID,
            #timeout=30
        )

        # Check if connected
        if ib.isConnected():
            logger.info("✅ Successfully connected to IB Gateway!")
            
            # Test basic API functionality
            logger.info("Testing API functionality...")
            
            # Try to get managed accounts
            try:
                accounts = ib.managedAccounts()
                logger.info(f"Managed accounts: {accounts}")
            except Exception as e:
                logger.warning(f"Could not get managed accounts: {e}")
            
            # Try to get account summary
            try:
                account_values = ib.accountSummary()
                logger.info(f"Received {len(account_values)} account values")
                
                # Print first few values
                for i, value in enumerate(account_values[:3]):
                    logger.info(f"  {value.tag}: {value.value} {value.currency}")
            except Exception as e:
                logger.warning(f"Could not get account summary: {e}")
                
            logger.info("✅ Connection test successful!")
            return True
            
        else:
            logger.error("❌ Failed to connect to IB Gateway")
            return False
            
    except ConnectionRefusedError:
        logger.error(f"❌ Connection refused - Check if IB Gateway is running and API is enabled")
        return False
    except TimeoutError:
        logger.error("❌ Connection timed out - Check firewall and network connectivity")
        return False
    except Exception as e:
        logger.error(f"❌ Connection failed: {str(e)}")
        logger.error(f"Error type: {type(e).__name__}")
        return False
    finally:
        # Always disconnect
        if ib.isConnected():
            ib.disconnect()
            logger.info("Disconnected from IB Gateway")

def test_port_connectivity():
    """Test basic port connectivity"""
    import socket
    
    logger.info("Testing basic port connectivity...")
    
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(10)
        result = sock.connect_ex((IB_GATEWAY_HOST, IB_GATEWAY_PORT))
        
        if result == 0:
            logger.info("✅ Port is reachable")
            sock.close()
            return True
        else:
            logger.error(f"❌ Port not reachable (error code: {result})")
            return False
            
    except Exception as e:
        logger.error(f"❌ Port test failed: {e}")
        return False

def main():
    """Main function"""
    logger.info("=== IB Gateway Connection Test ===")
    
    # Test 1: Basic port connectivity
    # if not test_port_connectivity():
    #     logger.error("Basic connectivity failed. Check network and firewall settings.")
    #     return
    
    # Test 2: IB API connection
    test_connection()

if __name__ == "__main__":
    main()

the output log was

2025-06-26 17:45:40,140 - main - INFO - === IB Gateway Connection Test ===
2025-06-26 17:45:40,140 - main - INFO - Testing connection to acxxxxxxxxxxxxx7feaa38ac-227xxxxxxxxxxxx4a94.elb.ap-northeast-1.amazonaws.com:8888
2025-06-26 17:45:40,141 - main - INFO - Connecting with clientId 8...
2025-06-26 17:45:40,141 - ib_async.client - INFO - Connecting to acxxxxxxxxxxxxx7feaa38ac-227xxxxxxxxxxxx4a94.elb.ap-northeast-1.amazonaws.com:8888 with clientId 8...
2025-06-26 17:45:40,159 - ib_async.client - INFO - Connected
2025-06-26 17:45:44,160 - ib_async.client - INFO - Disconnecting
2025-06-26 17:45:44,161 - ib_async.client - ERROR - API connection failed: TimeoutError()
2025-06-26 17:45:44,161 - ib_async.client - INFO - Disconnected.
2025-06-26 17:45:44,161 - main - ERROR - ❌ Connection timed out - Check firewall and network connectivity

Can anyone help me out?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions