Page 1 of 1

Stop & Iceberg API

Posted: Wed Jan 06, 2021 9:11 pm
by oceanis400
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
 

Re: Stop & Iceberg API

Posted: Mon Jan 11, 2021 11:03 am
by Andry API support
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));
    }

}






 

Re: Stop & Iceberg API

Posted: Tue Jan 12, 2021 6:14 pm
by oceanis400
Hello,

Thank you for this answer.

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