Support wrote:
Could you please provide an example code and a launch scenario for the case when when you manage to create two orders with the same label?
In a case you're only concerned about making your labels unique, you might consider the following method which ensures the label uniqueness between both of the strategies:
private String getLabel(String prefix){
return prefix + UUID.randomUUID().toString().replace('-', '0');
}
For instance, the attached code. It works when runned twice through the jforex platform: One of the instances introduces the order, and the other throw the following exception:
Quote:
07:48:38 com.dukascopy.api.JFException: Label not unique(code 2). (Order already exists) [DLUSDJPY20110525_094830]:label=DLUSDJPY20110525_094830;getId()=null;groupId=null;openingOrderId=null;pendingOrderId=null;parentOrderId=null;tpOrderId=null;slOrderId=null;state=CREATED;instrument=USD/JPY;openPrice=82.151;requestedAmount=0.01;amount=0.01;lastServerRequest=SUBMIT;awaitingResubmit=false;localCreationTime=1306309718116;
But when I run the strategy two times at the same time through Java API, I got no exception, and two orders are introduced with same label. See the screenshot:
https://postimage.org/image/1n0uysfb8/Labels DLEURUSD20110525_095850 and DLEURUSD20110525_095910 are duplicated. Label DLEURUSD20110525_095900 is not, because that time it worked fine: one of the instances detected the duplicated label and throw the exception.
Source code:
package jforex;
import java.text.SimpleDateFormat;
import com.dukascopy.api.*;
public class DuplicatedLabel implements IStrategy {
private IEngine engine;
private IConsole console;
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
}
public void onAccount(IAccount account) throws JFException {
}
public void onMessage(IMessage message) throws JFException {
}
public void onStop() throws JFException {
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
if (period!=Period.TEN_SECS) return;
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
String label = "DL"+instrument.toString().replaceAll("/", "")+sdf.format(bidBar.getTime());
console.getOut().println("Introducing order BUY "+instrument.toString()+" with label "+label);
try {
engine.submitOrder(label, instrument, IEngine.OrderCommand.BUY, 0.01);
} catch (Exception e) {
console.getErr().println(e.toString());
}
}
}