brndnmtthws / thetagang

ThetaGang is an IBKR bot for collecting money
GNU Affero General Public License v3.0
1.94k stars 255 forks source link

java.awt.AWTError: Can't connect to X11 window server using ':1' as the value of the DISPLAY variable. #238

Closed a1exus closed 1 year ago

a1exus commented 1 year ago

Hello World!

I'm trying to follow Up and running with Docker, yet running into issue that can't pass(

the actual error:

No protocol specified
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2023-01-31 05:27:45:029 IBC: An exception has occurred:
java.awt.AWTError: Can't connect to X11 window server using ':1' as the value of the DISPLAY variable.
        at java.desktop/sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
        at java.desktop/sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:101)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
        at java.desktop/sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:60)
        at java.desktop/sun.awt.PlatformGraphicsInfo.createGE(PlatformGraphicsInfo.java:36)
        at java.desktop/java.awt.GraphicsEnvironment$LocalGE.createGE(GraphicsEnvironment.java:93)
        at java.desktop/java.awt.GraphicsEnvironment$LocalGE.<clinit>(GraphicsEnvironment.java:84)
        at java.desktop/java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:106)
        at java.desktop/sun.awt.X11.XToolkit.<clinit>(XToolkit.java:224)
        at java.desktop/sun.awt.PlatformGraphicsInfo.createToolkit(PlatformGraphicsInfo.java:40)
        at java.desktop/java.awt.Toolkit.getDefaultToolkit(Toolkit.java:599)
        at ibcalpha.ibc.IbcTws.createToolkitListener(Unknown Source)
        at ibcalpha.ibc.IbcTws.load(Unknown Source)
        at ibcalpha.ibc.IbcGateway.main(Unknown Source)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

step I took:

$ mkdir ~/thetagang
$ cd ~/thetagang
$ curl -Lq https://raw.githubusercontent.com/brndnmtthws/thetagang/main/thetagang.toml -o ~/thetagang/thetagang.toml
$ curl -Lq https://raw.githubusercontent.com/brndnmtthws/thetagang/main/ibc-config.ini -o ~/thetagang/config.ini
$ docker run --rm -i --net host \
    -v ~/thetagang:/etc/thetagang \
    brndnmtthws/thetagang:main \
    --config /etc/thetagang/thetagang.toml
+ export DISPLAY=:1
+ DISPLAY=:1
+ Xvfb :1 -ac -screen 0 1024x768x24
++ arch
+ export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/jni
+ LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/jni
+ exec /usr/local/bin/thetagang --config /etc/thetagang/thetagang.toml
_XSERVTransSocketUNIXCreateListener: ...SocketCreateListener() failed
_XSERVTransMakeAllCOTSServerListeners: server already running
(EE) 
Fatal server error:
(EE) Cannot establish any listening sockets - Make sure an X server isn't already running(EE) 
Config:
...
No protocol specified
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2023-01-31 05:27:45:029 IBC: An exception has occurred:
java.awt.AWTError: Can't connect to X11 window server using ':1' as the value of the DISPLAY variable.
        at java.desktop/sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
        at java.desktop/sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:101)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
        at java.desktop/sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:60)
        at java.desktop/sun.awt.PlatformGraphicsInfo.createGE(PlatformGraphicsInfo.java:36)
        at java.desktop/java.awt.GraphicsEnvironment$LocalGE.createGE(GraphicsEnvironment.java:93)
        at java.desktop/java.awt.GraphicsEnvironment$LocalGE.<clinit>(GraphicsEnvironment.java:84)
        at java.desktop/java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:106)
        at java.desktop/sun.awt.X11.XToolkit.<clinit>(XToolkit.java:224)
        at java.desktop/sun.awt.PlatformGraphicsInfo.createToolkit(PlatformGraphicsInfo.java:40)
        at java.desktop/java.awt.Toolkit.getDefaultToolkit(Toolkit.java:599)
        at ibcalpha.ibc.IbcTws.createToolkitListener(Unknown Source)
        at ibcalpha.ibc.IbcTws.load(Unknown Source)
        at ibcalpha.ibc.IbcGateway.main(Unknown Source)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Please advise.

brndnmtthws commented 1 year ago

Do you already have an X11 server running somewhere? Are there multiple instances of the same docker container running (check with docker ps)?

a1exus commented 1 year ago

@brndnmtthws thank you for trying to help me, i really appreciate your time)

I've got the error while trying to run Docker' container on my Chromebook and just in case software is not compatible, I also tried to run same container on my Mac as well:

% tail -7 ib_insync.log
2023-01-31 19:27:08,640 ib_insync.IBC INFO Starting
2023-01-31 19:27:38,656 ib_insync.client INFO Connecting to 127.0.0.1:7497 with clientId 1...
2023-01-31 19:27:38,658 ib_insync.client INFO Disconnecting
2023-01-31 19:27:38,659 ib_insync.client ERROR API connection failed: ConnectionRefusedError(111, "Connect call failed ('127.0.0.1', 7497)")
2023-01-31 19:27:38,660 ib_insync.client ERROR Make sure API port on TWS/IBG is open
2023-01-31 19:27:38,661 ib_insync.IBC INFO Terminating
2023-01-31 19:27:41,024 ib_insync.IBC INFO Starting
% 

I didn't get the same error, however I got the one I pasted above..

Please advise. Thanks again!

brndnmtthws commented 1 year ago

You're going to need to debug it a little more. Check the logs thoroughly for error messages to see what's going on.

a1exus commented 1 year ago

@brndnmtthws -

Check the logs thoroughly for error messages to see what's going on.

the following is entire log (starting from the beginning)

alexus@mbp thetagang % tail -f ib_insync.log
2023-02-01 02:05:20,607 ib_insync.Watchdog INFO Starting
2023-02-01 02:05:20,608 ib_insync.IBC INFO Starting
2023-02-01 02:05:50,638 ib_insync.client INFO Connecting to 127.0.0.1:7497 with clientId 1...
2023-02-01 02:05:50,642 ib_insync.client INFO Disconnecting
2023-02-01 02:05:50,643 ib_insync.client ERROR API connection failed: ConnectionRefusedError(111, "Connect call failed ('127.0.0.1', 7497)")
2023-02-01 02:05:50,644 ib_insync.client ERROR Make sure API port on TWS/IBG is open
2023-02-01 02:05:50,646 ib_insync.IBC INFO Terminating
2023-02-01 02:05:53,017 ib_insync.IBC INFO Starting
2023-02-01 02:06:23,027 ib_insync.client INFO Connecting to 127.0.0.1:7497 with clientId 1...
2023-02-01 02:06:23,030 ib_insync.client INFO Disconnecting
2023-02-01 02:06:23,032 ib_insync.client ERROR API connection failed: ConnectionRefusedError(111, "Connect call failed ('127.0.0.1', 7497)")
2023-02-01 02:06:23,034 ib_insync.client ERROR Make sure API port on TWS/IBG is open
2023-02-01 02:06:23,035 ib_insync.IBC INFO Terminating

the output keeps on repeating due to ConnectionRefusedError(111, "Connect call failed ('127.0.0.1', 7497)")

alexus@mbp ~ % docker exec -it clever_bhaskara bash
root@docker-desktop:/src# apt-get update -qq && apt-get -qq install -qq telnet
root@docker-desktop:/src# telnet 127.0.0.1 7497
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
root@docker-desktop:/src#

confirmed port 7497 isn't listening on 127.0.0.1.


I'm going by following consideration:

If you don't want to mess around too much, consider running ThetaGang with Docker.

root@docker-desktop:/src# ps auxwww
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.2  0.2 449604 40648 ?        Ssl  02:05   0:01 /usr/bin/python3 /usr/local/bin/thetagang --config /etc/thetagang/thetagang.toml
root         7  0.2  0.4 194748 67556 ?        S    02:05   0:01 Xvfb :1 -ac -screen 0 1024x768x24
root      2337  0.0  0.0   7632  4044 pts/0    Ss   02:11   0:00 bash
root      2903  0.0  0.0   7500  3880 ?        S    02:14   0:00 /bin/bash /opt/ibc/scripts/ibcstart.sh 1019 --gateway --mode=paper --ibc-path=/opt/ibc --ibc-ini=/etc/thetagang/config.ini --java-path=/opt/java/openjdk/bin --user=demo --pw=demo
root      2915  128  1.7 6931356 282728 ?      Sl   02:14   0:08 /opt/java/openjdk/bin/java -cp /root/Jts/1019/jars/jackson-core-2.12.3.jar:/root/Jts/1019/jars/jts4launch-1019.jar:/root/Jts/1019/jars/locales.jar:/root/Jts/1019/jars/log4j-api-2.17.1.jar:/root/Jts/1019/jars/log4j-core-2.17.1.jar:/root/Jts/1019/jars/total-2020.jar:/root/Jts/1019/jars/twslaunch-1019.jar:/root/Jts/1019/jars/twslaunch-install4j-1.12.jar:/root/Jts/1019/.install4j/i4jruntime.jar:/opt/ibc/IBC.jar -Xmx768m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:ParallelGCThreads=20 -XX:ConcGCThreads=5 -XX:InitiatingHeapOccupancyPercent=70 --module-path /usr/share/openjfx/lib --add-modules java.base,java.naming,java.management,javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web --add-opens java.desktop/javax.swing=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens javafx.graphics/com.sun.javafx.application=ALL-UNNAMED -Dtwslaunch.autoupdate.serviceImpl=com.ib.tws.twslaunch.install4j.Install4jAutoUpdateService -Dchannel=latest -Dexe4j.isInstall4j=true -Dinstall4jType=standalone ibcalpha.ibc.IbcGateway /etc/thetagang/config.ini demo demo paper
root      3004  0.0  0.0  10068  1556 pts/0    R+   02:14   0:00 ps auxwww
root@docker-desktop:/src#

Can you please point me into right direction where to look next?) I'd appreciate that)

Please advise. Thanks again!

a1exus commented 1 year ago
alexus@mbp ~ % docker exec -it vigilant_hypatia tail -0f /root/Jts/launcher.log
2023-02-01 02:48:56.051 [TH] INFO  [JTS-Main] - ------------------------------- IB GATEWAY RESTART --------------------------------
2023-02-01 02:48:56.055 [TH] INFO  [JTS-Main] - installer version: unknown, installer type: standalone, install dir: 'null', Jts dir: '/root/Jts', VM options file: 'null'
2023-02-01 02:48:56.068 [TH] INFO  [JTS-Main] - Verifying environment [entryPoint=IBGATEWAY_STANDALONE]...
2023-02-01 02:48:56.087 [TH] INFO  [JTS-Main] - Install4jAutoUpdateService initialized [props=LauncherProperties[updateDownloadUrl=null,skipUpdateCheck=false,nightlyEnabled=false,channelNameArg=null,channelName=latest,channelChanged=false,jtsConfigDir=null,apiPort=null,sessionId=null,installDir=null,exeName=null]].
2023-02-01 02:48:56.091 [TH] INFO  [JTS-Main] - PROXY Installed custom selector
2023-02-01 02:48:56.097 [TH] INFO  [JTS-Main] - useSsl=true,FIX endPoint=null:4001
2023-02-01 02:48:56.213 [TH] INFO  [JTS-Main] - Setting custom timezone: Africa/Abidjan
2023-02-01 02:48:56.217 [TH] INFO  [JTS-Main] - LOCALE: Property locale_to_use=null
2023-02-01 02:48:56.222 [TH] INFO  [JTS-Main] - LOCALE: JTS Locale=en_US  country=United States  variant=
2023-02-01 02:48:56.223 [TH] INFO  [JTS-Main] - Region: Custom
2023-02-01 02:48:56.224 [TH] WARN  [JTS-Main] - The locales jar directory resolved to '/root/Jts/jars' ('installDir' system property is not set).
2023-02-01 02:48:56.224 [TH] WARN  [JTS-Main] - The locales jar directory resolved to '/root/Jts/jars' ('installDir' system property is not set).
2023-02-01 02:48:56.224 [TH] INFO  [JTS-Main] - Locale from ini: en
2023-02-01 02:48:56.225 [TH] INFO  [JTS-Main] - Locale=en_US  country=United States  variant=
2023-02-01 02:48:56.228 [TH] INFO  [JTS-Main] - prohibiting class lookup [twslaunch.ji18n.LauncherLanguage]
2023-02-01 02:48:56.230 [TH] INFO  [JTS-Main] - prohibiting class lookup [twslaunch.ji18n.LauncherLanguage_en]
2023-02-01 02:48:56.231 [TH] INFO  [JTS-Main] - prohibiting class lookup [twslaunch.ji18n.LauncherLanguage_en_US]
2023-02-01 02:48:56.231 [TH] INFO  [JTS-Main] - LOCALE:  type: launcher intended: en_US actual:  size: 485
2023-02-01 02:48:56.232 [TH] INFO  [JTS-Main] - settings dir: '/root/Jts'
2023-02-01 02:48:56.386 [TH] INFO  [JTS-Main] - LauncherFontUpdater: simulatehighdefscreen=false
2023-02-01 02:48:56.390 [TH] INFO  [JTS-Main] - LauncherFontUpdater: Screen dimensions=1024x768
2023-02-01 02:48:56.390 [TH] INFO  [JTS-Main] - LauncherFontUpdater: highres=false
2023-02-01 02:48:56.390 [TH] INFO  [JTS-Main] - LauncherFontUpdater: FontSize=16
2023-02-01 02:48:56.390 [TH] INFO  [JTS-Main] - initPreUI() - entry
2023-02-01 02:48:56.400 [TH] INFO  [JTS-Main] - Build 10.19.1j, Jan 11, 2023 6:06:40 PM
2023-02-01 02:48:56.430 [TH] INFO  [JTS-Main] - LookAndFeelChangedListener installed
2023-02-01 02:48:56.433 [TH] INFO  [JTS-Main] - JtsLookAndFeel initialized
2023-02-01 02:48:56.848 [TH] INFO  [JTS-Main] - Current LAF: TWS LAF
2023-02-01 02:48:56.848 [TH] INFO  [JTS-Main] - initPreUI() - exit
2023-02-01 02:48:57.305 [TH] INFO  [AWT-EventQueue-0] - Default timezone:Africa/Abidjan
2023-02-01 02:48:57.308 [TH] INFO  [AWT-EventQueue-0] - Starting GstatMessageMgr...
2023-02-01 02:48:57.309 [TH] WARN  [JTS-GstatMessageMgr-6] - Misc URLs have not been received. Resending request...
2023-02-01 02:48:57.357 [TH] INFO  [AWT-EventQueue-0] - Started on 20230201-02:48:57
2023-02-01 02:48:57.358 [TH] INFO  [AWT-EventQueue-0] - Default timezone:Africa/Abidjan name:Greenwich Mean Time dst:0
2023-02-01 02:48:57.358 [TH] INFO  [AWT-EventQueue-0] - java version = 17.0.4
2023-02-01 02:48:57.358 [TH] INFO  [AWT-EventQueue-0] - sun.arch.data.model = 64
2023-02-01 02:48:57.358 [TH] INFO  [AWT-EventQueue-0] - os = Linux
2023-02-01 02:48:57.358 [TH] INFO  [AWT-EventQueue-0] - os version = 5.15.49-linuxkit
2023-02-01 02:48:57.358 [TH] INFO  [AWT-EventQueue-0] - os architecture = 32
2023-02-01 02:48:57.358 [TH] INFO  [AWT-EventQueue-0] - runtime = OpenJDK Runtime Environment
2023-02-01 02:48:57.359 [TH] INFO  [AWT-EventQueue-0] - vendor = Eclipse Adoptium
2023-02-01 02:48:57.359 [TH] INFO  [AWT-EventQueue-0] - vm name = OpenJDK 64-Bit Server VM
2023-02-01 02:48:57.359 [TH] INFO  [AWT-EventQueue-0] - username = 'Unknown'
2023-02-01 02:49:01.091 [TH] INFO  [JTS-DeadlockMonitor-2] - Memory:total=786,432KB free=738,110KB HeapUsage: Max=786,432KB used=46,654KB committed=65,536KB NonHeapUsage: Max=0KB used=56,500KB committed=58,496KB
2023-02-01 02:49:02.096 [TH] INFO  [JTS-DeadlockMonitor-2] - CPU:cur=0.11% avg=0.11% 30 min avg=0.11% 10 min avg=0.11% 5 min avg=0.11% 1 min avg=0.11%
GC:called=6 times CPU used=0.07%
Finalizer:cur=0.00% avg=0.00% 30 min avg=0.00% 10 min avg=0.00% 5 min avg=0.00% 1 min avg=0.00%
Threads Count:curr live=28 curr daemon=17

IB GATEWAY RESTART keeps on restarting...

Please advise.

brndnmtthws commented 1 year ago

Are you trying to use a demo account? I don't think that will work, you need to login to a valid account. A paper account is fine, it just needs to actually exist.

PS: Careful not to leak your account details on here.

a1exus commented 1 year ago

Are you trying to use a demo account? I don't think that will work, you need to login to a valid account. A paper account is fine, it just needs to actually exist.

... when I ran "ps" command I did had a "demo" account in there, however I quickly realized that as well and updated to my actual account and left my last comment where "IB GATEWAY RESTART" (still stuck there)

PS: Careful not to leak your account details on here.

right, thank you)

brndnmtthws commented 1 year ago

Are you using the sample config.ini?

a1exus commented 1 year ago

Are you using the sample config.ini?

yes, with updated IbLoginId, IbPassword and TradingMode (paper)

alexus@mbp thetagang % diff config.ini bak/config.ini | cut -d= -f1
79c79
< IbLoginId
---
> IbLoginId
103c103
< IbPassword
---
> IbPassword
161c161
< TradingMode
---
> TradingMode
alexus@mbp thetagang %
a1exus commented 1 year ago

FYI: at very least, one cannot use "IBKR Lite" and must use "IBKR Pro" instead