AlgoTraderAlgoTrader Documentation

Chapter 12. Configuration and Preferences API

12.1. Config Providers
12.2. Config Beans
12.3. Config Locator

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 API 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);