Skip to content

Commit

Permalink
set timezone
Browse files Browse the repository at this point in the history
kill xfce session ssh-agent and gpg-agent
include chromiun dependencies libnspr4 libnss3
avoid duplicate ssh tunnel and agent on tws restart

Changes to be committed:
	modified:   docker-compose.yml
	modified:   image-files/config/ibc/config.ini.tmpl
	modified:   latest/Dockerfile.tws
	modified:   latest/config/ibc/config.ini.tmpl
	modified:   latest/scripts/common.sh
	modified:   latest/scripts/port_forwarding.sh
	modified:   latest/tws-scripts/run_tws.sh
	modified:   latest/tws-scripts/start_session.sh
	modified:   tws-docker-compose.yml
  • Loading branch information
gnzsnz committed Nov 26, 2023
1 parent 936371e commit 547053d
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "3.4"
name: algo-trader
services:
ib-gateway:
restart: unless-stopped
restart: always
build:
context: ./latest
tags:
Expand Down
5 changes: 2 additions & 3 deletions latest/Dockerfile.tws
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
ARG IB_VERSION=10.26.1g
FROM ghcr.io/gnzsnz/ib-gateway:${IB_VERSION} as setup

WORKDIR /

##############################################################################
# Build Stage: build production image
##############################################################################
Expand All @@ -33,7 +31,8 @@ ARG DEBIAN_FRONTEND=noninteractive

RUN \
apt-get update -y && \
apt-get install --no-install-recommends --yes socat sshpass gettext-base && \
apt-get install --no-install-recommends --yes socat sshpass gettext-base \
libnspr4 libnss3 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* # end

Expand Down
22 changes: 11 additions & 11 deletions latest/config/ibc/config.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -411,23 +411,23 @@ ReadOnlyApi=${READ_ONLY_API}
# should use the Global Configuration to set the relevant checkboxes and not
# provide values for these settings.

BypassOrderPrecautions=
BypassOrderPrecautions=${BYPASS_WARNING}

BypassBondWarning=
BypassBondWarning=${BYPASS_WARNING}

BypassNegativeYieldToWorstConfirmation=
BypassNegativeYieldToWorstConfirmation=${BYPASS_WARNING}

BypassCalledBondWarning=
BypassCalledBondWarning=${BYPASS_WARNING}

BypassSameActionPairTradeWarning=
BypassSameActionPairTradeWarning=${BYPASS_WARNING}

BypassPriceBasedVolatilityRiskWarning=
BypassPriceBasedVolatilityRiskWarning=${BYPASS_WARNING}

BypassUSStocksMarketDataInSharesWarning=
BypassUSStocksMarketDataInSharesWarning=${BYPASS_WARNING}

BypassRedirectOrderWarning=
BypassRedirectOrderWarning=${BYPASS_WARNING}

BypassNoOverfillProtectionPrecaution=
BypassNoOverfillProtectionPrecaution=${BYPASS_WARNING}


# Market data size for US stocks - lots or shares
Expand Down Expand Up @@ -605,7 +605,7 @@ ConfirmOrderIdReset=
# AutoRestartTime to your desired value before running IBC. NB: this does not
# apply to TWS from version 1018 onwards.

AutoLogoffTime=
AutoLogoffTime=${AUTO_LOGOFF_TIME}

AutoRestartTime=${AUTO_RESTART_TIME}

Expand Down Expand Up @@ -719,7 +719,7 @@ AllowBlindTrading=no
# To save every 90 minutes starting at 08:00 up to and including 17:43
#SaveTwsSettingsAt=Every 90 08:00 17:43

SaveTwsSettingsAt=
SaveTwsSettingsAt=${SAVE_TWS_SETTINGS}


# Confirm Crypto Currency Orders Automatically
Expand Down
11 changes: 9 additions & 2 deletions latest/scripts/common.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC1091

setup_ssh() {
# setup SSH Tunnel
Expand All @@ -16,13 +17,19 @@ setup_ssh() {
echo ".> SSH options: $SSH_ALL_OPTIONS"

if [ -n "$SSH_PASSPHRASE" ]; then
if [ -z "${SSH_AUTH_SOCK}" ]; then
if ! pgrep ssh-agent >/dev/null; then
# start agent if it's not already running
# https://wiki.archlinux.org/title/SSH_keys#SSH_agents
echo ".> Starting ssh-agent."
eval "$(ssh-agent -s)"
ssh-agent >"/config/.ssh-agent.env"
source "/config/.ssh-agent.env"
echo ".> ssh-agent sock: ${SSH_AUTH_SOCK}"
else
echo ".> ssh-agent already running"
if [ -z "${SSH_AUTH_SOCK}" ]; then
echo ".> Loading agent environment"
source "/config/.ssh-agent.env"
fi
echo ".> ssh-agent sock: ${SSH_AUTH_SOCK}"
fi

Expand Down
8 changes: 7 additions & 1 deletion latest/scripts/port_forwarding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ fi

if [ "$SSH_TUNNEL" = "yes" ]; then

if [ -n "$(pgrep -x ssh)" ]; then
# if this script is already running don't start it
echo ".> SSH tunnel already active. Not starting a new one"
exit 0
fi

if [ -z "$SSH_REMOTE_PORT" ]; then
# by default remote port is same than API_PORT
SSH_REMOTE_PORT="$API_PORT"
Expand All @@ -29,7 +35,7 @@ if [ "$SSH_TUNNEL" = "yes" ]; then
fi

while true; do
echo ".> ssh sock: $SSH_AUTH_SOCK"
echo ".> Starting ssh tunnel with ssh sock: $SSH_AUTH_SOCK"
bash -c "ssh ${SSH_ALL_OPTIONS} -TNR 127.0.0.1:${API_PORT}:localhost:${SSH_REMOTE_PORT} ${SSH_SCREEN:-} ${SSH_USER_TUNNEL}"
sleep "${SSH_RESTART:-5}"
done
Expand Down
11 changes: 7 additions & 4 deletions latest/tws-scripts/run_tws.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash
# shellcheck shell=bash
# shellcheck disable=SC1091,SC2317

echo "*************************************************************************"
echo ".> Starting IBC/TWS"
echo "*************************************************************************"
# shellcheck disable=SC1091
# source common functions
source "${SCRIPT_PATH}/common.sh"

Expand All @@ -13,9 +13,15 @@ disable_agents() {
# https://docs.xfce.org/xfce/xfce4-session/advanced
if [ ! -f /config/.config/disable_agents ]; then
echo ".> Disabling ssh-agent and gpg-agent"
# disable xfce
xfconf-query -c xfce4-session -p /startup/ssh-agent/enabled -n -t bool -s false
xfconf-query -c xfce4-session -p /startup/gpg-agent/enabled -n -t bool -s false
# kill ssh-agent and gpg-agent
pkill -x ssh-agent
pkill -x gpg-agent
touch /config/.config/disable_agents
else
echo ".> Found '/config/.config/disable_agents' agents already disabled"
fi
}

Expand All @@ -38,9 +44,6 @@ apply_settings
# forward ports, socat or ssh
"${SCRIPT_PATH}/port_forwarding.sh" &

# settings
apply_settings

# start IBC
echo ".> Starting IBC with params:"
echo ".> Version: ${TWS_MAJOR_VRSN}"
Expand Down
5 changes: 5 additions & 0 deletions latest/tws-scripts/start_session.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ echo ".> Setting user password"
echo "abc:$_PASS" | chpasswd
id

if [ -n "${TZ}" ]; then
echo ".> Setting timezone to: ${TZ}"
echo "${TZ}" >/etc/timezone
fi

# open xfce session
echo ".> Openning Xrdp session"
echo "${_PASS}" | xrdp-sesrun -s 127.0.0.1 -F 0 abc
Expand Down
7 changes: 5 additions & 2 deletions tws-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
restart: unless-stopped
devices:
- /dev/dri:/dev/dri #optional
shm_size: "2gb" #optional
shm_size: "4gb" #optional
build:
context: ./latest
dockerfile: Dockerfile.tws
Expand All @@ -23,7 +23,10 @@ services:
TWS_SETTINGS_PATH: ${TWS_SETTINGS_PATH:-}
READ_ONLY_API: ${READ_ONLY_API:-}
TWOFA_TIMEOUT_ACTION: ${TWOFA_TIMEOUT_ACTION:-exit}
BYPASS_WARNING: ${BYPASS_WARNING:-}
AUTO_RESTART_TIME: ${AUTO_RESTART_TIME:-}
AUTO_LOGOFF_TIME: ${AUTO_LOGOFF_TIME:-}
SAVE_TWS_SETTINGS: ${SAVE_TWS_SETTINGS:-}
RELOGIN_AFTER_TWOFA_TIMEOUT: ${RELOGIN_AFTER_TWOFA_TIMEOUT:-no}
TWOFA_EXIT_INTERVAL: ${TWOFA_EXIT_INTERVAL:-60}
TIME_ZONE: ${TIME_ZONE:-Etc/UTC}
Expand All @@ -39,7 +42,7 @@ services:
SSH_RESTART: ${SSH_RESTART:-}
SSH_RDP_PORT: ${SSH_RDP_PORT:-}
volumes:
- ./config:/config #optional
- ./config:/config # optional
ports:
#- "127.0.0.1:7496:7498" # live
- "127.0.0.1:7497:7499" # paper
Expand Down

0 comments on commit 547053d

Please sign in to comment.