Skip to content

Commit 6f34a6a

Browse files
committed
Added scripts to start and kill the gateway manualy
1 parent 20247f1 commit 6f34a6a

File tree

5 files changed

+51
-22
lines changed

5 files changed

+51
-22
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
Provides a Container including a running TWS/Gateway in an isolated environment.
44

55
* The TWS/Gateway is restarted once a day
6+
* Framebuffer device to redirect Gateway-Output
7+
* X11 integration to run GUI-applications inside the container
68
* A reverse SSH-Tunnel is implemented for an extra layer of security
79
* [Simple-Monitor](https://github.com/ib-ruby/simple-monitor) is started upon setup
810
* Anything is prepared to run an reliable Trading-Bot in a secure environment
9-
* a suitable ruby installation to develope and run ib-ruby-trading solutions
11+
* A suitable ruby installation to develop and run ib-ruby-trading solutions
1012

1113
## Background
1214

@@ -29,7 +31,7 @@ provides the proprietary `IB-API` and the `FIX-Protocol`, the industry standard
2931
Edit `config.sh`
3032

3133
The script `setup.sh`
32-
* downloads and installs a minimized Ubuntu Linux Image (Unbuntu 20.4 LTS)
34+
* downloads and installs a minimized Ubuntu Linux Image (Ubuntu 20.4 LTS)
3335
* downloads the official binaries from the interactive brokers server into the container
3436
* downloads the [IBC](https://github.com/IbcAlpha/IBC) automation software providing tws/gateway-autostart
3537
* prepares the container to run ruby programs
@@ -57,6 +59,13 @@ The script is called with up to six arguments
5759
```
5860
All arguments are requested interactively if absent
5961

62+
After successfully initializing the container, the gateway is started (output goes into the framebuffer) and a TMUX-Session
63+
is opened. [Simple-Monitor](https://github.com/ib-ruby/simple-monitor) is autostarted.
64+
65+
The Control-Key is **CRTL A**; _CRTL A d_ detaches from the session.
66+
67+
The container is accessible (with X11 support) through: `lxc open {container name}`
68+
6069
## Finishing
6170

6271
On your Middleman Server, edit `~.ssh/config` and add the reverse tunnel specification
@@ -81,7 +90,7 @@ This software is tested on Ubuntu systems.
8190

8291
## ToDo
8392

84-
* Implement adressing the ibgateway application and enable the fix protocol
93+
* Implement addressing the ibgateway application and enable the fix protocol
8594

8695
## CONTRIBUTING
8796

kill-gateway.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
kill -9 `ps -ef | grep export | grep -v grep|awk '{print $2}'`
3+
kill -9 `ps -ef | grep java | grep -v grep|awk '{print $2}'`
4+
echo "Gateway instance killed"
5+

setup.sh

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,19 @@ else
101101
fi
102102
fi
103103
fi
104+
read -p "[?] Gateway Ausgabe in Framebuffer umleiten? [Y/n]:" cont
105+
if [[ -n $cont || $cont == 'n' ]] ; then
106+
TWS_DISPLAY=:0
107+
else
108+
TWS_DISPLAY=:99
109+
fi
104110

105111

106-
print_status "-------------------------"
112+
print_status "......................................"
107113
print_status "Containter: $CONTAINER"
108114
print_status "Login: $LOGIN"
109115
print_status "Password: **** " # $PASS"
110-
print_tatus "Demoaccount: `if [ $DEMOACCOUNT -eq 1 ] ; then echo "ja" ; else echo "nein"; fi ` "
116+
print_status "Demoaccount: `if [ $DEMOACCOUNT -eq 1 ] ; then echo "ja" ; else echo "nein"; fi ` "
111117
print_status "Gateway/TWS: `if [ "$PRODUCT" = tws ] ; then echo "$INSTANCE" ; else echo "Gateway" ; fi `"
112118
if [ $SETUP_AUTOSSH -eq 1 ] ; then
113119
print_status "PORT: $SSH_PORT_NUMBER"
@@ -116,15 +122,9 @@ if [ $SETUP_AUTOSSH -eq 1 ] ; then
116122
print_status "Middleman User: $SSH_MIDDLEMAN_USER"
117123
else
118124
print_status "SSH-Tunnel wird nicht installiert "
119-
print_status "......................................"
120-
fi
121-
read -p "[?] Gateway Ausgabe in Framebuffer umleiten? [Y/n]:" cont
122-
if [[ -n $cont || $cont == 'n' ]] ; then
123-
TWS_DISPLAY=:99
124-
else
125-
TWS_DISPLAY=:0
126125
fi
127126
print_status "Ausgabe für Gateway: $TWS_DISPLAY "
127+
print_status "......................................"
128128
read -p "[?] Installieren? [Y/n]:" cont
129129
if [[ -n $cont || $cont == 'n' ]] ; then
130130
exit 255
@@ -192,7 +192,7 @@ prepare_lxd(){
192192
lxc profile create gui
193193
lxc profile edit gui < lxdguiprofile.txt
194194
# alias anlegen
195-
lxc alias add ubuntu 'exec @ARGS@ -- sudo --login --user ubuntu'
195+
lxc alias add open 'exec @ARGS@ -- sudo --login --user ubuntu'
196196
fi
197197

198198
}
@@ -212,7 +212,7 @@ launch_image(){
212212

213213

214214
download_ib_software(){
215-
istf [ -f $IB_PROGRAM ] ; then
215+
if [ -f $IB_PROGRAM ] ; then
216216
:
217217
else
218218
print_status "Hole $PRODUCT vom offiziellen Server"
@@ -332,21 +332,31 @@ apply_ibc(){
332332
local lxd_display=`$access_container echo $DISPLAY`
333333
# set display , if no DISPLAY setting is found, use :99 (xvfb)
334334
if [ $lxd_display ] ; then
335-
:
335+
if [ "$TWS_DISPLAY" == ":0" ] ; then
336+
TWS_DISPLAY=$lxd_display
337+
fi
336338
else
337-
$access_container export DISPLAY=:99
338-
local lxd_display=`$access_container echo $DISPLAY`
339+
# $access_container export DISPLAY=:99
340+
TWS_DISPLAY=:99
339341
fi
340342

341343
echo 'START_TIME * * 1-5 export DISPLAY=ibc-display && /bin/bash /home/ubuntu/ibc/gatewaystart.sh -inline' > ibc_cronfile
342-
sed -e " 1 s/ibc-display/$lxd_display/ " -e " 1 s/START_TIME/$START_TIME/ " ibc_cronfile > t_c
343344
if [ $INSTANCE = "tws" ] ; then
344-
sed -in ' s/gateway/tws/ ' t_c
345+
sed -in ' s/gateway/tws/ ' ibc_cronfile
346+
sed -in ' s/ibc-display/$lxd_display/ ' ibc_cronfile
347+
else
348+
sed -in " s/ibc-display/$TWS_DISPLAY/ " ibc_cronfile
345349
fi
350+
sed -in " s/START_TIME/$START_TIME/ " ibc_cronfile
346351

347-
lxc file push t_c $CONTAINER/home/ubuntu/ibc_cronfile
348-
rm t_c
352+
lxc file push ibc_cronfile $CONTAINER/home/ubuntu/
349353
rm ibc_cronfile
354+
lxc file push start_framebuffer_gateway.sh $CONTAINER/home/ubuntu/
355+
lxc file push start_gateway.sh $CONTAINER/home/ubuntu/
356+
lxc file push kill_gateway.sh $CONTAINER/home/ubuntu/
357+
$access_container chmod a+x start_framebuffer_gateway.sh
358+
$access_container chmod a+x start_gateway.sh
359+
$access_container chmod a+x kill_gateway.sh
350360
$access_container crontab -u ubuntu /home/ubuntu/ibc_cronfile
351361
$access_container rm /home/ubuntu/ibc_cronfile
352362
fi
@@ -481,6 +491,7 @@ run_ats(){
481491
# starte die IB-Software
482492
local access_container="lxc exec $CONTAINER -- sudo --login --user ubuntu --"
483493
$access_container /home/ubuntu/ibc/${INSTANCE}start.sh -inline &
494+
$access_container /home/ubuntu/ibc/${INSTANCE}start.sh -inline &
484495
sleep 5
485496
$access_container /home/ubuntu/simple-monitor/start-simple-monitor
486497
return 0
@@ -497,7 +508,7 @@ launch_image
497508
download_ib_software
498509

499510
init_container
500-
print_status " +++++++++++++++++++++++++++++++++++++++ "
511+
print_status "......................................"
501512
print_status " Container ${CONTAINER} ist angelegt "
502513

503514
setup_xvfb

start_framebuffer_gateway.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
export DISPLAY=:99 && /bin/bash /home/ubuntu/ibc/gatewaystart.sh -inline &

start_gateway.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
/home/ubuntu/ibc/gatewaystart.sh -inline &

0 commit comments

Comments
 (0)