According to the Conditional Order States Diagram provided in the wiki (at the time of writing) order state should change from CREATED to CANCELLED when an ORDER_SUBMIT_REJECTED message is received.
In reality, however, orders seem to remain in CREATED state after an ORDER_SUBMIT_REJECTED message is received. To reproduce this bug, you can run a back-test on the following strategy on EURUSD ("All Ticks") from 2010.01.08 to 2010.01.11.
package jforex;
import java.util.*;
import com.dukascopy.api.*;
public class StateChartTest implements IStrategy {
@Configurable("Verbose mode")
public boolean verboseMode = false;
private IEngine engine;
private IConsole console;
private long nextActionTime = 0;
private final long halfhour = 1000*60*30;
private IOrder order;
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 {
IOrder order = message.getOrder();
if(order != null){
console.getOut().println(order.getLabel() + ": state is " + order.getState() + " after receiving message " + message);
}
}
public void onStop() throws JFException {
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
long t = tick.getTime();
if(t > nextActionTime){
nextActionTime = t + halfhour - t % halfhour;
long i = nextActionTime/halfhour-1;
if(i%2 == 0){
String label = "order" + (i/2);
if(order != null)
throw new IllegalStateException("order should be null");
if(verboseMode)
console.getOut().println("SUBMITTING NEW ORDER: " + label);
order = engine.submitOrder(label, instrument, IEngine.OrderCommand.BUYSTOP, 0.01, tick.getBid() + 0.01);
}else{
if(verboseMode)
console.getOut().println("CLOSING ORDER");
order.close();
order = null;
}
}
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
}
Inspecting the last output before the exceptions are thrown, you will see that the order state is CREATED after ORDER_SUBMIT_REJECTED message is received.
So there is either a mistake in the state diagram, or a bug in the API. However, if the mistake is in the state diagram, that would be problematic, since there is then no way (based on order state) to distinguish between an order whose submission is still pending, and an order whose submission was rejected. (And one cannot rely on monitoring for the ORDER_SUBMIT_REJECTED message, since message delivery is not guaranteed according to
https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=61&t=34820).