AlgoTrader (AT) strategies, as well as AT server can be run on Docker containers in just a few steps (How to run AlgoTrader on Docker). There are 2 ways of starting an AlgoTrader strategy: embedded mode and distributed mode. In this article, we will focus on a distributed deployment because Docker containers are a perfect solution for that.
Firstly, create a docker image of the strategy. AlgoTrader examples project contains already configured Dockerfiles that you can easily adjust for your own strategy:
https://www.algotrader.com/downloads/latest-examples
e.g. in Random strategy:
FROM docker.algotrader.com/algotrader/algotrader:latest
MAINTAINER AlgoTrader AG <info@algotrader.com>
ENV STRATEGY_NAME=RANDOM
ENV SPRING_PROFILES=live,pooledDataSource,iBMarketData,iBNative,embeddedBroker,html5
WORKDIR /usr/local/strategy
ADD target/*-bin.tar.gz .
ENTRYPOINT ["/usr/local/algotrader/bin/docker-strategy-run.sh"]
CMD ["-e"]
To build the image, execute the following command:
docker build <path to dockerfile>\. -t <image name>
e.g.:
docker build . -t random
After you successfully build the image, it will be available for docker:
AlgoTrader examples contain also docker-compose.yml files that can be used to run AT on Docker containers. In this example we will run 2 strategies:
- cryptos
- cryptos2
For the cryptos strategy, we will use the image created above, although for the cryptos2 strategy we will use an image from our Algotrader docker repository.
Before starting the strategies it's needed to fill DB with strategies names and configure connection to the exchange in Configuration UI, in this example Binance Global account was activated. After that AT downloaded reference data and based on that securityIDs were updated for each strategy.
Adjusted docker-compose.yml file:
After executing docker-compose up in the folder containing docker-compose.yml Algotrader will start in distributed mode together with both strategies, MySQL and InfluxDB container. The AlgoTrader web UI is exposed on localhost:9090.
The random strategy project contains 2 docker-compose.yml files, one is set up to work in distributed mode, by running the second one, AT with the strategy will start in embedded mode. If you are interested in running AT in embedded mode, you can check those docker-compose files, in reference to the base examples directory you have extracted: examples/random.
Common issues:
- Notice that: -Dhz.discovery.tcp.members= should point to the member address picked by the server:
- If you build a strategy without the examples project as a parent, then it is imperative to update your strategy's pom.xml using the below guide so that the related jar files will be deployed correctly in the docker image.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<dependencies>
<dependency>
<groupId>algotrader</groupId>
<artifactId>algotrader-core</artifactId>
<version>6.3.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>strategy-bin</descriptorRef>
</descriptorRefs>
<tarLongFileMode>gnu</tarLongFileMode>
</configuration>
</execution>
</executions>
</plugin>
Comments
0 comments
Please sign in to leave a comment.