AlgoTraderAlgoTrader Documentation

Chapter 29. Configuration and Preferences API

29.1. Configuration Files
29.2. Esper Variables
29.3. Config Providers
29.4. Config Beans
29.5. Config Locator

The AlgoTrader Server contains the following two main configuration files. the main public configuration file: contains settings that are only used by the core project:

In addition Broker Interfaces may have their own settings file. for IB and for BB.

Configuration parameters can be changed inside the .properties files. As an alternative configuration parameters can be provided as VM arguments in which case they will overwrite existing parameters inside *.properties files.

Most configuration parameters are prefixed with a namespace (e.g. dataSource, simulation, statement, misc, etc.)

The configuration files are also used to define values for Esper variables. Because the Esper Variable system is strong typed, variables with their type have to be configured within the corresponding Esper configuration files. e.g.

<variable name="simulation_eventsPerDay" type="long"/>    

AlgoTrader provides extensive support for configuration and customization of platform functions as well as of strategy specific settings.

The cornerstone of the configuration and preference APIs is the ConfigProvider interface that can be used to obtain arbitrary typed configuration parameters.

public interface ConfigProvider {

    <T> T getParameter(String name, Class<T> clazz);
    Set<String> getNames();

DefaultSystemConfigProvider is the default implementation of ConfigProvider based on Spring ConversionService and is internally backed by a thread safe Map. The default provider makes use of ConversionService conversion framework to convert the content of the internal parameter map to the desired type. One can customize the process of parameter conversion by using a custom ConversionService implementation.

ConfigParams is a utility facade for ConfigProvider exposing a set of getter methods for common data types such Boolean, Integer, Long, Double, BigDecimal, URL and URI. This class can be used by trading strategies that need to dynamically resolve configuration parameters at runtime.

DefaultConfigLoader is used to read configuration parameters from property files.

AlgoTrader also provides commonly used parameters in a form of plain Java beans referred to as Config beans. Common configuration are represented by CommonConfig. Core platform parameters are represented by CoreConfig. Instances of these classes are immutable and can be shared by multiple components and multiple threads of execution.

ConfigBeanFactory class can be used to create instances of Config beans based on configuration parameters using @ConfigName constructor parameter annotations. This factory is used to build standard CommonConfig and CoreConfig but it can also be used to build arbitrary Config beans for a trading strategy using the following convention

public final class StratConfig {

    private final String textParam;
    private final boolean boolParam;
    private final BigDecimal decimalParam;
    public StratConfig(
        @ConfigName(value = "my.text") final String textParam,
        @ConfigName(value = "my.bool") final boolean boolParam,
        @ConfigName(value = "my.decimal", optional = true) final BigDecimal decimalParam) {
        this.textParam = textParam;
        this.boolParam = boolParam;
        this.decimalParam = decimalParam;
    public String getTextParam() {
        return textParam;
    public boolean isBoolParam() {
        return boolParam;
    public BigDecimal getDecimalParam() {
        return decimalParam;

Each constructor parameter of a Config bean must be annotated with @ConfigName containing the parameter name. The config parameter type will be inferred from the constructor argument type. If a parameter is null able and might be undefined in the config property files it can be marked as optional.

Standard platform Config beans such as CommonConfig and CoreConfig are declared in the Spring application context and get automatically injected into all beans that require configuration. One can also add strategy specific Config beans using the following bean definition:

<bean id="stratConfig" class="ch.algotrader.config.spring.ConfigBeanFactoryBean">
    <constructor-arg index="0" ref="configLocator"/>
    <constructor-arg index="1" value="my.strategy.StratConfig"/>

Standard as well as strategy specific Config beans can be conveniently accessed using Spring SPEL expressions to wire other beans in the same Spring application context.

<bean id="MyObject" class="...">
    <constructor-arg value="#{@stratConfig.requestUri}"/>

In addition it is possible to reference individual beans (e.g. config beans) directly within Spring wired classes

private @Value("#{@configParams.accountId}") long accountId;

Even though it is preferable to dependency injection services provided by Spring application context to obtain configuration details required by custom components, in certain cases it may be necessary for unmanaged beans to get hold of Config beans. This can be done through the global ConfigLocator

ConfigParams configParams = ConfigLocator.instance().getConfigParams();
CommonConfig commonConfig = ConfigLocator.instance().getCommonConfig();
StratConfig stratConfig = ConfigLocator.instance().getConfig(StratConfig.class);