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
Stop & Iceberg API
-
- Posts: 545
- Joined: Mon Jul 09, 2018 11:18 am
- Has thanked: 22 times
- Been thanked: 83 times
Re: Stop & Iceberg API
Hi oceanis,
currently not supported but you can leave your request in this topic.to get Iceberg and Stop value directly from module
Take a look at this example. An alert is played on every n-th trade.how to use alert in a Strategy ? Have you Java sample ?
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));
}
}
-
- Posts: 10
- Joined: Wed Oct 03, 2018 11:03 am
- Has thanked: 1 time
Re: Stop & Iceberg API
Hello,
Thank you for this answer.
It will be more simple to Log all Alert in a file.
Thank you for this answer.
It will be more simple to Log all Alert in a file.