AlgoTraderAlgoTrader Documentation

Chapter 9. Database

9.1. Instances
9.2. Flyway
9.3. Files
9.4. Data Source

AlgoTrader uses MySQL to store transaction data. In addition an embedded in-memory H2 database can be used for simulations.

AlgoTrader uses the database migration library flyway to keep databases in-line with the current version of AlgoTrader. Flyway executes database migration scripts to ensure that the database is in the state corresponding to the version of AlgoTrader installed.

Flyway is embedded into the AlgoTrader platform, and can perform a migration of the Database on each startup automatically. In case the configured schema does not exist on MySQL, it will create it. This schemas default-name is algotrader. The feature is activated on all startup-scripts including docker but deactivated in the development environment. misc.flywayMigrateOnStartup is the property to control this behaviour, it can be passed as a VM Argument.


In case you need to reset the Database, the easiest way is to delete the corresponding schema on MySQL and start AlgoTrader. For further migration related issues, a class within AlgoTrader ch.algotrader.starter.FlywayRunner can be used to execute other flyway commands. It is not recommended to use Flyways command-line-tool instead, because of potential problems when using several flyway versions on the same schema.

For additional information on flyway please visit the flyway documentation.

The database migration scripts are located in /bootstrap/conf/flyway.

The directory /bootstrap/conf contains all relevant database files:

With the embedded database H2 all H2 scripts that are available in the class path under the following wild card pathname will be loaded by the system: h2/h2-*.sql and /db/h2/h2-*.sql.

AlgoTrader provides different Data Source for different scenarios. One of the available Data Sources needs to be configured via the following VM argument:<dataSource>

dataSource can be one of the following

  • pooledDataSource: A Data Source that uses connection pooling based on C3P0

  • singleDataSource: A Data Source that uses one single database connection and no connection pooling.

  • embeddedDataSource: An H2 based in-memory / in-process Data Source that is ideal for simulation of strategies. Using the embeddedDataSource reduces the duration of back-test runs by 30%-50% and allows multiple parallel simulations on the same machine without needing to installing a physical database.