API example: Launching a custom window

Custom indicators, trading strategies, data export and recording and more...
Posts: 106
Joined: Mon Jun 11, 2018 12:40 pm
Has thanked: 15 times
Been thanked: 28 times

API example: Launching a custom window

Post by Serg » Mon Dec 17, 2018 5:15 pm

This is a demonstration of an ability to create entirely custom window (not only the settings panel). A use case for this could be, for instance, creating a footprint chart and rendering / updating it from a custom API module (the addon).

In this example our custom window displays only the last traded price as following:

Code: Select all

        labelSide.setText(isBuy ? "BUY " : "SELL");
        labelSize.setText("" + size);
        labelPrice.setText("" + price);
This and any more advance rendering on the custom window requires standard Java knowledge, unrelated to Bookmap API. The addon also creates a custom settings panel, which in this simple case contains a button that launches the custom window. Also, in this case the addon needs to subscribe only on trades data. Market depth and other available functionality can be found in API documentation.

Here is the entire code of the addon:

Code: Select all

@Layer1StrategyName("Example Custom Window")
public class ExampleCustomWindow implements CustomModule, TradeDataListener, CustomSettingsPanelProvider {

    private JFrame frame;
    private JLabel labelSide;
    private JLabel labelSize;
    private JLabel labelPrice;

    private double pips;

    public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
        pips = info.pips;

        frame = new JFrame("Custom API window for " + alias);
        frame.setMinimumSize(new Dimension(400, 200));

        labelSide = new JLabel("");
        labelPrice = new JLabel("");
        labelSize = new JLabel("");
        updateLabels(true, 0, Double.NaN);

        JPanel panel = new JPanel();
        panel.add(new JLabel("Last trade: "));
        panel.add(new JLabel("  "));
        panel.add(new JLabel(" at "));


    public void stop() {

    public void onTrade(double price, int size, TradeInfo tradeInfo) {
        if (size != 0) {
            if (frame.isVisible()) {
                updateLabels(tradeInfo.isBidAggressor, size, pips * price);

    public StrategyPanel[] getCustomSettingsPanels() {
        StrategyPanel panel = new StrategyPanel("Custom setttings panel");
        JButton button = new JButton("Launch custom window");
        button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
        return new StrategyPanel[] { panel };

    private void updateLabels(boolean isBuy, int size, double price) {
        labelSide.setText(isBuy ? "BUY " : "SELL");
        labelSize.setText("" + size);
        labelPrice.setText("" + price);
And here is the resulting view:

custom-window.png (152.87 KiB) Viewed 7372 times