AlgoTrader (AT) can be configured to run on Docker containers. The Algotrader-launch project contains a pre-configured docker-compose.yml file that will run 6 containers:
- Algotrader
- IB Gateway
- MySQL
- InfluxDB
- Keycloak
- Grafana
You may not need all 6 containers, for example, IB Gateway is needed when trading via Interactive Brokers and thus its entry can be removed from the docker-compose.yml file if not required for your use case.
When running AlgoTrader on Docker, all necessary AT configurations like license key, starter class, security settings, etc. can be populated through the algotrader container environment variables provided in the docker-compose.yml file. Thus, this way it is not possible to override those in Configuration UI, it's especially important in case of security settings.
For further details regarding AlgoTrader container environment variables please visit AlgoTrader container section in our Reference Guide: Docker containers
Requirements:
- Docker version 20.10+
- Docker-compose version 1.27+
Steps to run AlgoTrader on Docker containers:
1. Login to Nexus
Open console window in algotrader-launch project folder and login to the Docker Repository with the username and password provided when licensing AlgoTrader:
docker login docker.algotrader.com
2. Adjust your docker-compose.yml file
Below is a good example:
version: "3.9"
networks:
net:
driver: bridge
ipam:
driver: default
config:
- subnet: 10.0.251.0/24
services:
algotrader:
image: docker.algotrader.com/algotrader/algotrader:6.4.0
environment:
VM_ARGUMENTS: -Dkeygen.id=
-Dspring.profiles.active=live,pooledDataSource,simulation,embeddedBroker,html5,influxDB
-DdataSource.loadSampleData=true
-Dmetrics.enabled=false
-DoverridesPath=/usr/local/algotrader/config-overrides.json
-Dflyway.url=jdbc:mysql://mysql:3306?useSSL=false&allowPublicKeyRetrieval=true
-DdataSource.url=jdbc:mysql://mysql:3306/algotrader?useSSL=false&allowPublicKeyRetrieval=true
-Dhz.discovery.method=TCP
-Dhz.network.interfaces=10.0.251.*
-Dssl.enabled=true
-Dssl.keystore=file:///usr/local/algotrader/keystore/identity.jks
-Dssl.keystorePassword=<password_for_identity.jks>
-Dsecurity.enabled=true
STARTER_CLASS: ch.algotrader.starter.ServerStarter
ALGOTRADER_HOST: "algotrader"
DATABASE_HOST: "mysql"
DATABASE_PORT: "3306"
DATABASE_NAME: "algotrader"
DATABASE_USER: "root"
DATABASE_PASSWORD: "password"
INFLUXDB_HOST: "influxdb"
depends_on:
mysql:
condition: service_healthy
influxdb:
condition: service_healthy
keycloak:
condition: service_healthy
ports:
- 443:443
- 9090:9090
- 61614:61614
- 61617:61617
- 25333:25333
- 25334:25334
- 25332:25332
volumes:
- C:\Users\admin\docker\algotrader_conf\config-overrides.json:/usr/local/algotrader/config-overrides.json
- <local_path_to_html5-keycloak.json>:/usr/local/algotrader/conf/html5/keycloak.json
- <local_path_to_keycloak.json>:/usr/local/algotrader/conf/keycloak.json
- <local_path_to_identity.jks>:/usr/local/algotrader/keystore/identity.jks
- grafanaconfig:/usr/local/algotrader/conf/grafana
networks:
- net
mysql:
image: mysql/mysql-server:8.0.23
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: algotrader
MYSQL_ROOT_HOST: "%"
ports:
- 3306:3306
volumes:
- mysqldb:/var/lib/mysql
networks:
- net
influxdb:
image: influxdb:1.8.10
volumes:
- /var/lib/influxdb
environment:
INFLUXDB_HTTP_FLUX_ENABLED: "true"
INFLUXDB_HTTP_ENABLED: "true"
ports:
- 8086:8086
networks:
- net
healthcheck:
test: "curl -f http://localhost:8086/ping"
interval: 15s
timeout: 15s
retries: 10
start_period: 180s
keycloak:
image: docker.algotrader.com/keycloak:10.0.2-AT1-5
environment:
DB_VENDOR: h2
KEYCLOAK_FRONTEND_URL: "https://<client.url.com>:8444/auth"
CLIENT_KEYCLOAK_USER: <your_keycloack_user>
CLIENT_KEYCLOAK_PASSWORD: <yuor_keycloack_password>
ALGOTRADER_URL: "https://<client.url.com>"
volumes:
- keycloakdb:/opt/jboss/keycloak/standalone/data/
- <local_path_to_realm-algotrader.json>:/opt/jboss/realm-algotrader.json
- <local_path_to_client.url.com.key>:/etc/x509/https/tls.key
- <local_path_to_client.url.com.crt>:/etc/x509/https/tls.crt
networks:
- net
ports:
- 8444:8444
grafana:
image: grafana/grafana:8.3.3
environment:
GF_AUTH_ANONYMOUS_ENABLED: "true"
GF_SERVER_PROTOCOL: "https"
GF_SERVER_CERT_FILE: "/var/lib/grafana/ssl/grafana.crt"
GF_SERVER_CERT_KEY: "/var/lib/grafana/ssl/grafana.key"
GF_SECURITY_ALLOW_EMBEDDING: "true"
GF_PATHS_CONFIG: "/etc/grafana/custom.ini"
ports:
- 3000:3000
networks:
- net
volumes:
- <local_path_to_client.url.com.crt>:/var/lib/grafana/ssl/grafana.crt
- <local_path_to_client.url.com.key>:/var/lib/grafana/ssl/grafana.key
- grafanaconfig:/etc/grafana:ro
volumes:
mysqldb:
influxdb:
keycloakdb:
grafanaconfig:
where
local_path_to_client.url.com.crt, local_path_to_client.url.com.key - path to SSL certificate and key to use in Algotrader and Keycloak. Required to issue them if need that dashboard will be accessible from outside(client.url.com).
local_path_to_identity.jks - path to identity key created from SSL certificate and key
local_path_to_html5-keycloak.json - Required for Keycloak configuration. It contains the next information:
{
"auth-server-url": "https://client.url.com:8444/auth",
"realm": "algotrader",
"resource": "algotrader-dashboard"
}
local_path_to_keycloak.json - Required for Keyckloak configuration. It contains the next information:
{
"realm": "algotrader",
"auth-server-url": "https://client.url.com:8444/auth/",
"ssl-required": "external",
"resource": "algotrader-server",
"verify-token-audience": true,
"credentials": {
"secret": "7dc3cf93-f2a4-48e9-b6a4-873fadc83391"
},
"confidential-port": 0
}
When running a back-test via Docker, please use
STARTER_CLASS=ch.algotrader.starter.SimulationStarter
3. Run Server Starter
Now when everything is configured, executing the following command in the folder containing docker-compose.yml will create and run the containers:
docker-compose up -d
After few seconds AlgoTrader will start:
To look at logs:
docker logs -f launch_algotrader_1
More detailed information about server starter configuration can be found in our documentation: Server Starter
4. Open AlgoTrader Web UI
After that AlgoTrader Web UI can be accessed by the following address:
https://client.url.com
The more detailed information regarding Docker-based installation can be found in our documentation: Docker based installation
Common issues:
- to mount a volume with config overrides it's needed to provide its full path, otherwise Docker will mount it as a file and AlgoTrader will not start.
- empty config-overrides.json file needs to have the following structure:
{
"key" : null,
"properties" : {
}
}
Comments
0 comments
Please sign in to leave a comment.