mvberg / ib-gateway-docker

Interactive Brokers Trading Gateway running in Docker
MIT License
229 stars 105 forks source link

Connection refused after it has been working after many reboots #23

Open kootenpv opened 4 years ago

kootenpv commented 4 years ago

After having worked for some time, now it seems I cannot shake this off:

socat[537] E connect(5, AF=2 127.0.0.1:4001, 16): Connection refused                                                                    

I think that I have logged in to TWS once and then afterwards it started working again, but at other times it did not have an effect. It actually seems quite random? Did anyone experience something like this?

christian-oudard commented 4 years ago

I have the same thing, with the following error log:

$ docker-compose up
Starting ib-gateway-docker_tws_1 ... done
Attaching to ib-gateway-docker_tws_1
tws_1  | Starting virtual X frame buffer: Xvfb.
tws_1  | 19:52:18:662 IBController: detected frame entitled: Starting application...; event=Closed
tws_1  | 19:52:18:942 IBController: detected dialog entitled: Trader Workstation Configuration;
event=Activated
tws_1  | 19:52:18:943 IBController: detected dialog entitled: Trader Workstation Configuration; event=Opened
tws_1  | 19:52:19:006 IBController: Performing Api setting configuration
tws_1  | 19:52:19:118 IBController: TWS API socket port is already set to 4001
tws_1  | 19:52:19:118 IBController: Unselect and disable Read-Only API
tws_1  | 19:52:19:133 IBController: Select and enable Bypass Order Precautions for API Orders
tws_1  | 19:52:19:133 IBController: Click button: OK
tws_1  | 19:52:19:250 IBController: detected dialog entitled: Trader Workstation Configuration; event=Closed
tws_1  | remove Client 1
tws_1  | stored passwd in file: /.vnc/passwd
tws_1  | Starting x11vnc.
tws_1  |
tws_1  | +==============================================================================
tws_1  | +
tws_1  | + IBController version 3.2.0.5
tws_1  | +
tws_1  | + Running GATEWAY 974
tws_1  | +
tws_1  | + Diagnostic information is logged in:
tws_1  | +
tws_1  | + /opt/IBController/Logs/ibc-3.2.0.5_GATEWAY-974_Thursday.txt
tws_1  | +
tws_1  | +
tws_1  |
tws_1  | ================================================================================
tws_1  |
tws_1  | Starting IBController version 3.2.0.5 on 2020-08-13 at 19:53:37
tws_1  |
tws_1  | Operating system: Linux b13015dfd45f 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020
x86_64 x86_64 x86_64 GNU/Linux
tws_1  |
tws_1  | Arguments:
tws_1  |
tws_1  | TWS version = 974
tws_1  | Entry point = ibcontroller.IBGatewayController
tws_1  | --tws-path = /root/Jts
tws_1  | --tws-settings-path = /root/Jts
tws_1  | --ibc-path = /opt/IBController
tws_1  | --ibc-ini = /root/IBController/IBController.ini
tws_1  | --mode = live
tws_1  | --java-path = /opt/i4j_jres/1.8.0_152/bin
tws_1  | --user = ***
tws_1  | --pw = ***
tws_1  | --fix-user =
tws_1  | --fix-pw =
tws_1  |
tws_1  | =================================
tws_1  | Generating the classpath
tws_1  | Classpath=/root/Jts/ibgateway/974/jars/jts4launch-974.jar:/root/Jts/ibgateway/974/jars/locales.jar:/root/Jts/ibgateway/974/jars/log4j-api-2.5.jar:/root/Jts/ibgateway/974/jars/log4j-core-2.5.jar:/root/Jts/ibgateway/974/jars/total-2018.jar:/root/Jts/ibgateway/974/jars/twslaunch-974.jar:/root/Jts/ibgateway/974/jars/twslaunch-install4j-1.9.jar:/opt/IBController/IBController.jar
tws_1  |
tws_1  | Generating the JAVA VM options
tws_1  | Java VM Options=-Xmx768m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:ParallelGCThreads=20
-XX:ConcGCThreads=5 -XX:InitiatingHeapOccupancyPercent=70
tws_1  |
tws_1  | Determining the location of java executable
tws_1  | Location of java executable=/opt/i4j_jres/1.8.0_152/bin
tws_1  |
tws_1  | Starting IBGateway with this command:
tws_1  | /opt/i4j_jres/1.8.0_152/bin/java -cp
/root/Jts/ibgateway/974/jars/jts4launch-974.jar:/root/Jts/ibgateway/974/jars/locales.jar:/root/Jts/ibgateway/974/jars/log4j-api-2.5.jar:/root/Jts/ibgateway/974/jars/log4j-core-2.5.jar:/root/Jts/ibgateway/974/jars/total-2018.jar:/root/Jts/ibgateway/974/jars/twslaunch-974.jar:/root/Jts/ibgateway/974/jars/twslaunch-install4j-1.9.jar:/opt/IBController/IBController.jar
-Xmx768m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:ParallelGCThreads=20 -XX:ConcGCThreads=5
-XX:InitiatingHeapOccupancyPercent=70 ibcontroller.IBGatewayController /root/IBController/IBController.ini ***
*** live
tws_1  |
tws_1  | System Properties
tws_1  | ------------------------------------------------------------
tws_1  | java.runtime.name = Java(TM) SE Runtime Environment
tws_1  | sun.boot.library.path = /opt/i4j_jres/1.8.0_152/lib/amd64
tws_1  | java.vm.version = 25.152-b16
tws_1  | java.vm.vendor = Oracle Corporation
tws_1  | java.vendor.url = http://java.oracle.com/
tws_1  | path.separator = :
tws_1  | java.vm.name = Java HotSpot(TM) 64-Bit Server VM
tws_1  | file.encoding.pkg = sun.io
tws_1  | user.country = US
tws_1  | sun.java.launcher = SUN_STANDARD
tws_1  | sun.os.patch.level = unknown
tws_1  | java.vm.specification.name = Java Virtual Machine Specification
tws_1  | user.dir = /root/Jts
tws_1  | java.runtime.version = 1.8.0_152-b16
tws_1  | java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
tws_1  | java.endorsed.dirs = /opt/i4j_jres/1.8.0_152/lib/endorsed
tws_1  | os.arch = amd64
tws_1  | java.io.tmpdir = /tmp
tws_1  | line.separator =
tws_1  |
tws_1  | java.vm.specification.vendor = Oracle Corporation
tws_1  | os.name = Linux
tws_1  | sun.jnu.encoding = ANSI_X3.4-1968
tws_1  | java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
tws_1  | java.specification.name = Java Platform API Specification
tws_1  | java.class.version = 52.0
tws_1  | sun.management.compiler = HotSpot 64-Bit Tiered Compilers
tws_1  | os.version = 5.4.0-42-generic
tws_1  | user.home = /root
tws_1  | user.timezone = America/Chicago
tws_1  | java.awt.printerjob = sun.print.PSPrinterJob
tws_1  | file.encoding = ANSI_X3.4-1968
tws_1  | java.specification.version = 1.8
tws_1  | java.class.path = /root/Jts/ibgateway/974/jars/jts4launch-974.jar:/root/Jts/ibgateway/974/jars/locales.jar:/root/Jts/ibgateway/974/jars/log4j-api-2.5.jar:/root/Jts/ibgateway/974/jars/log4j-core-2.5.jar:/root/Jts/ibgateway/974/jars/total-2018.jar:/root/Jts/ibgateway/974/jars/twslaunch-974.jar:/root/Jts/ibgateway/974/jars/twslaunch-install4j-1.9.jar:/opt/IBController/IBController.jar
tws_1  | user.name = root
tws_1  | java.vm.specification.version = 1.8
tws_1  | sun.java.command = ibcontroller.IBGatewayController /root/IBController/IBController.ini USERNAME PASSWORD live
tws_1  | java.home = /opt/i4j_jres/1.8.0_152
tws_1  | sun.arch.data.model = 64
tws_1  | user.language = en
tws_1  | java.specification.vendor = Oracle Corporation
tws_1  | awt.toolkit = sun.awt.X11.XToolkit
tws_1  | java.vm.info = mixed mode
tws_1  | java.version = 1.8.0_152
tws_1  | java.ext.dirs = /opt/i4j_jres/1.8.0_152/lib/ext:/usr/java/packages/lib/ext
tws_1  | sun.boot.class.path = /opt/i4j_jres/1.8.0_152/lib/resources.jar:/opt/i4j_jres/1.8.0_152/lib/rt.jar:/opt/i4j_jres/1.8.0_152/lib/sunrsasign.jar:/opt/i4j_jres/1.8.0_152/lib/jsse.jar:/opt/i4j_jres/1.8.0_152/lib/jce.jar:/opt/i4j_jres/1.8.0_152/lib/charsets.jar:/opt/i4j_jres/1.8.0_152/lib/jfr.jar:/opt/i4j_jres/1.8.0_152/classes
tws_1  | java.vendor = Oracle Corporation
tws_1  | file.separator = /
tws_1  | java.vendor.url.bug = http://bugreport.sun.com/bugreport/
tws_1  | sun.io.unicode.encoding = UnicodeLittle
tws_1  | sun.cpu.endian = little
tws_1  | sun.cpu.isalist =
tws_1  | ------------------------------------------------------------
tws_1  | 19:53:37:653 IBController: using default settings provider: ini file is
/root/IBController/IBController.ini
tws_1  | 19:53:37:654 IBController: using default login manager: getting username and password from args
tws_1  | 19:53:37:654 IBController: using default config dialog manager: constructor parameter isGateway=true
tws_1  | 19:53:37:654 IBController: using default trading mode manager: constructor parameter args:
tradingMode=live
tws_1  | 19:53:37:655 IBController: using default config dialog manager
tws_1  | 19:53:37:658 IBController: IBControllerServer is started.
tws_1  | 19:53:37:702 IBController: IBControllerServer listening on address: b13015dfd45f/172.18.0.2 port:
7462
tws_1  | Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':0' as the
value of the DISPLAY variable.
tws_1  |        at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
tws_1  |        at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
tws_1  |        at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115)
tws_1  |        at java.security.AccessController.doPrivileged(Native Method)
tws_1  |        at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
tws_1  |        at java.lang.Class.forName0(Native Method)
tws_1  |        at java.lang.Class.forName(Class.java:264)
tws_1  |        at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103)
tws_1  |        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
tws_1  |        at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:126)
tws_1  |        at java.lang.Class.forName0(Native Method)
tws_1  |        at java.lang.Class.forName(Class.java:264)
tws_1  |        at java.awt.Toolkit$2.run(Toolkit.java:860)
tws_1  |        at java.awt.Toolkit$2.run(Toolkit.java:855)
tws_1  |        at java.security.AccessController.doPrivileged(Native Method)
tws_1  |        at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:854)
tws_1  |        at ibcontroller.IBController.createToolkitListener(Unknown Source)
tws_1  |        at ibcontroller.IBController.load(Unknown Source)
tws_1  |        at ibcontroller.IBGatewayController.main(Unknown Source)
tws_1  | Forking :::4001 onto 0.0.0.0:4003\n
tws_1  | 2020/08/13 19:54:10 socat[103] E connect(5, AF=2 127.0.0.1:4001, 16): Connection refused
kootenpv commented 4 years ago

In my case it helped to have more RAM

azenakhi commented 1 year ago

Hello,

I tried to do call API to IBKR using IB Gateway in Docker. Maybe I have the same error : ib-gateway_1 | 2023/09/17 16:48:24 socat[189] E connect(5, AF=2 127.0.0.1:4000, 16): Connection refused.

App.py

from ib_insync import *

util.startLoop() # uncomment this line when in a notebook

ib = IB() ib.connect('127.0.0.1', 4006, clientId=1)

contract = Forex('EURUSD') bars = ib.reqHistoricalData( contract, endDateTime='', durationStr='30 D', barSizeSetting='1 hour', whatToShow='MIDPOINT', useRTH=True)

convert to pandas dataframe (pandas needs to be installed):

df = util.df(bars) print(df)


Thanks for your help.

josephchenhk commented 1 year ago

got the same connection refused error. Have no idea what the reason is. Anyone can help?

Mikkel84 commented 10 months ago

Me too. I solved this at least locally: https://github.com/gnzsnz/ib-gateway-docker/issues/34#issuecomment-1873454406. Unfortunately, it does still not work when deploying the container to the cloud.