AlgoTraderAlgoTrader Documentation

Chapter 12. Database

12.1. Entity Relationship Model
12.2. Data Source
12.3. Transaction Handling

By default the database MySql is used by the system. 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

The directory algotrader/core/ contains all relevant database files:

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

The Entity Relationship Model of the system is displayed below. For a description of tables please see Chapter 10, Code Generation








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

-Dspring.profiles.active=<dataSource>

dataSource can be one of the following

  • pooledDataSource: A Data Souce 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.

Using Spring Transaction Boundaries are declared on Services using the annotation @Transactional. Transaction Boundaries are handled by the org.springframework.transaction.interceptor.TransactionInterceptor. A typical declaration looks like this:

@Transactional(propagation = Propagation.REQUIRED)
public void saveTransaction(final Transaction transaction) { 
   
}