Stop & Iceberg API

Custom indicators, trading strategies, data export and recording and more...
oceanis400
Posts: 10
Joined: Wed Oct 03, 2018 11:03 am
Has thanked: 1 time

Stop & Iceberg API

Post by oceanis400 » Wed Jan 06, 2021 9:11 pm

hello,

What is Java to get Iceberg and Stop  value directly from module or how to use alert in a Strategy ?
Have you Java sample ?

thank you
 

Andry API support
Posts: 548
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 25 times
Been thanked: 85 times

Re: Stop & Iceberg API

Post by Andry API support » Mon Jan 11, 2021 11:03 am

Hi oceanis,
to get Iceberg and Stop  value directly from module
currently not supported but you can leave your request in this topic.
how to use alert in a Strategy ? Have you Java sample ?
Take a look at this example. An alert is played on every n-th trade.

Code: Select all

package velox.api.layer1.simplified.demo;

import velox.api.layer1.annotations.Layer1ApiVersion;
import velox.api.layer1.annotations.Layer1ApiVersionValue;
import velox.api.layer1.annotations.Layer1SimpleAttachable;
import velox.api.layer1.annotations.Layer1StrategyName;
import velox.api.layer1.data.InstrumentInfo;
import velox.api.layer1.data.TradeInfo;
import velox.api.layer1.layers.utils.SoundSynthHelper;
import velox.api.layer1.messages.Layer1ApiSoundAlertCancelMessage;
import velox.api.layer1.messages.Layer1ApiSoundAlertCancelMessage.Layer1ApiSoundMessagesFilter;
import velox.api.layer1.messages.Layer1ApiSoundAlertMessage;
import velox.api.layer1.simplified.Api;
import velox.api.layer1.simplified.CustomModule;
import velox.api.layer1.simplified.InitialState;
import velox.api.layer1.simplified.TradeDataListener;

@Layer1SimpleAttachable
@Layer1StrategyName("Sound Alerts")
@Layer1ApiVersion(Layer1ApiVersionValue.VERSION2)
public class LastTradeSoundAlert implements CustomModule, TradeDataListener {
    private Api api;
    private int tradeCounter;
    private String alias;

    // an alert will be played for every n-th trade
    private int n = 10;
    private byte[] alertSound = SoundSynthHelper.synthesize("alert");
    private Layer1ApiSoundAlertMessage alertMessage = new Layer1ApiSoundAlertMessage(alertSound, "", 1, null,
            (a, s) -> {
            }, this.getClass(),
            alias);

    @Override
    public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
        this.api = api;
        this.alias = alias;
    }

    @Override
    public void onTrade(double price, int size, TradeInfo tradeInfo) {
        tradeCounter++;

        // play alert for every n-th trade
        if (tradeCounter % n == 0) {
            api.sendUserMessage(alertMessage);
        }
    }

    @Override
    public void stop() {
        // cancel queued alerts for this module if there are any
        // so they will not be played when the module is stopped
        Layer1ApiSoundMessagesFilter soundMessagesFilter = new Layer1ApiSoundAlertCancelMessage.Layer1ApiSoundMessagesFilter() {
            @Override
            public boolean shouldCancelMessage(Layer1ApiSoundAlertMessage message) {
                if (alias.equals(message.metadata)) {
                    return true;
                }
                return false;
            }
        };
        api.sendUserMessage(new Layer1ApiSoundAlertCancelMessage(this.getClass(), soundMessagesFilter));
    }

}






 

oceanis400
Posts: 10
Joined: Wed Oct 03, 2018 11:03 am
Has thanked: 1 time

Re: Stop & Iceberg API

Post by oceanis400 » Tue Jan 12, 2021 6:14 pm

Hello,

Thank you for this answer.

It will be more simple to Log all Alert in a file.

Post Reply