Defining user interface

User interface is defined using field annotations. Annotating fields in strategy body with @Property results in generating strategy input form with controls which type corresponds with type of annotated field. Following example lists supported field types. Boolean (or boolean) field generates check-box control, Integer (or int) field generates spinner with step of 1, BigDecimal field generates spinner with default step of 0.01, enum field generates drop-down list that contain all values defined in given enum type, String field generates text-field and date field generates date/time input control. Fields can be also set with default values, that are displayed in generated form with exception of fields of Date type. Values selected in generated form are automatically assigned to proper fields at strategy start.

@Description(lines = {
                "Example demonstrates basic use of annotations for input form generation.",
                "Values selected in generated form are automatically set at strategy start.",
                "Change values in generated form, start strategy and see selected values printed in logger tab."
})
public class FormProperty extends StrategyExt {

        @Property
        private Boolean property_Boolean;

        @Property
        private Integer property_Integer;

        @Property
        private BigDecimal property_BigDecimal;

        @Property
        private Side property_Side;

        @Property
        private String property_String;

        @Property
        private Date property_Date;

        @Override
        protected void initialize(StrategyIntializer builder) throws PropertyValidationException {
                getPlatform().sendInfo("property_Boolean:" + property_Boolean);
                getPlatform().sendInfo("property_Integer:" + property_Boolean);
                getPlatform().sendInfo("property_BigDecimal:" + property_BigDecimal);
                getPlatform().sendInfo("property_Side:" + property_Side);
                getPlatform().sendInfo("property_String:" + property_String);
                getPlatform().sendInfo("property_Date:" + property_Date);
        }
}
Form Property strategy visualization

MarketSymbol property

Annotation @Symbol can be only added to fields of MarketSymbol type. Adding this annotation does not generate new form controls - it is used to assign symbols from existing strategy symbol selection control. In case of this annotation, name of field is not interpreted - important is sequence in which annotated fields are defined in strategy body. When multiple symbols are selected, consecutive fields are filled with consecutive chosen symbols. When starting strategy, number of selected symbols is validated against number of annotated fields. If those number do not match, strategy will fail to start.

@Description(lines = {
                "Example demonstrates setting symbols chosen in symbols control in strategy panel.",
                "In this strategy, exactly two symbols has to be chosen. Any other value results in strategy failing to start."
})
public class FormSymbol extends StrategyExt {

        @Symbol
        private MarketSymbol symbol_1;

        @Symbol
        private MarketSymbol symbol_2;

        @Override
        protected void initialize(StrategyIntializer builder) throws PropertyValidationException {
                getPlatform().sendInfo("symbol_1: " + symbol_1);
                getPlatform().sendInfo("symbol_2: " + symbol_2);
        }
}
Form Symbol strategy visualization

Field of type Integer can be configured with additional annotations that limit its value to range of values, or to specific set of legal values.

Integer property

@Description(lines = {
                "Example demonstrates additional annotations that can be used for Integer type fields.",
                "Property value can be limited by minimal and maximal allowed value.",
                "Property value can be limited by set of legal values.",
                "Field can be initialized with default value that is displayed in generated form."
})
public class FormPropertyInteger extends StrategyExt {

        @Property
        @ValidInteger(minValue = 1, maxValue = 10)
        private Integer integer_1 = 5;

        @Property
        @EnumValues(values = {"2", "3", "5"})
        private Integer integer_2 = 3;

        @Override
        protected void initialize(StrategyIntializer builder) throws PropertyValidationException {
                getPlatform().sendInfo("integer_1:" + integer_1);
                getPlatform().sendInfo("integer_2:" + integer_2);
        }
}
Form Property Integer strategy visualization

BigDecimal property

Field of type BigDecimal can be configured analogically to field of type Integer. Additionally, default precision of passed value can be changed to values other than 2 (for instance 0,1 or 3) which results in changing step value of generated spinner.

@Description(lines = {
                "Example demonstrates additional annotations that can be used for BigDecimal type fields.",
                "Property value can be limited by minimal and maximal allowed value.",
                "Property can have non-default precision, other than 2 (for instance: 0,1,3)",
                "Property value can be limited by set of legal values.",
                "Field can be initialized with default value that is displayed in generated form."
})
public class FormPropertyBigDecimal extends StrategyExt {

        @Property
        @ValidBigDecimal(minValue = 1.5, maxValue = 10.5)
        private BigDecimal bigDecimal_1 = new BigDecimal("5.5");

        @Property
        @ValidBigDecimal(minValue = 1.521, maxValue = 1.555, precision = 3)
        private BigDecimal bigDecimal_2 = new BigDecimal("1.535");

        @Property
        @EnumValues(values = {"2.5", "3.5", "5.5"})
        private BigDecimal bigDecimal_3 = new BigDecimal("3.5");

        @Override
        protected void initialize(StrategyIntializer builder) throws PropertyValidationException {
                getPlatform().sendInfo("bigDecimal_1:" + bigDecimal_1);
                getPlatform().sendInfo("bigDecimal_2:" + bigDecimal_2);
                getPlatform().sendInfo("bigDecimal_3:" + bigDecimal_3);
        }
}
Form Property BigDecimal strategy visualization

Enum property

Field of enum type can be configured to allow only subset of defined values.

@Description(lines = {
                "Example demonstrates additional annotations that can be used for Enum type fields.",
                "Property value can be limited by set of legal values.",
                "Field can be initialized with default value that is displayed in generated form."
})
public class FormPropertyEnum extends StrategyExt {

        @Property
        private Side side_1 = Side.Sell;

        @Property
        @EnumValues(values = {"Buy", "Sell"})
        private Side side_2 = Side.Sell;

        @Override
        protected void initialize(StrategyIntializer builder) throws PropertyValidationException {
                getPlatform().sendInfo("side_1:" + side_1);
                getPlatform().sendInfo("side_2:" + side_2);
        }
}
Form Property Enum strategy visualization

String property

Field of String type can be configured to all ow strings of limited length, it can also limit its value to specific set of legal values.

@Description(lines = {
                "Example demonstrates additional annotations that can be used for String type fields.",
                "Property value can be limited by maximal value length.",
                "Property value can be limited by set of legal values.",
                "Field can be initialized with default value that is displayed in generated form."
})
public class FormPropertyString extends StrategyExt {

        @Property
        @ValidString(maxLength = 25)
        private String string_1 = "initial value";

        @Property
        @EnumValues(values = {"one", "two", "three"})
        private String string_2 = "two";

        @Override
        protected void initialize(StrategyIntializer builder) throws PropertyValidationException {
                getPlatform().sendInfo("");
        }
}
Form Property String strategy visualization

Panels

By default labels at controls contain name of annotated field. Those labels can be easily customized with more descriptive text. Not configured controls are appended vertically in single default panel. Controls can be grouped in multiple, labelled and horizontally aligned panels. Controls are grouped by panel label, occurrence of new panel label name results in creation of new panel.

@Description(lines = {
                "Example demonstrates additional features that can be used to organize controls in generated form."
})
public class FormPanel extends StrategyExt {

        private final String panel_a = "Integer properties";
        private final String panel_b = "Boolean properties";

        @Property(panel = panel_a, label = "first input parameter")
        private Integer value_1;

        @Property(panel = panel_a, label = "second input parameter")
        private Integer value_2;

        @Property(panel = panel_b, label = "third input parameter")
        private Boolean value_3;

        @Override
        protected void initialize(StrategyIntializer builder) throws PropertyValidationException {
                getPlatform().sendInfo("first:" + value_1);
                getPlatform().sendInfo("second:" + value_2);
                getPlatform().sendInfo("third:" + value_3);
        }
}
Form Panel strategy visualization