package jforex.orders;
import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
@RequiresFullAccess
public class TestWaitForUpdateResubmit implements IStrategy {
private IEngine engine;
private IConsole console;
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
context.setSubscribedInstruments(java.util.Collections.singleton(Instrument.EURUSD), true);
IOrder order = engine.submitOrder("order", Instrument.EURUSD, OrderCommand.BUY, -0.001);
IMessage message = order.waitForUpdate(2000, IOrder.State.OPENED);
if(message.getType() == IMessage.Type.ORDER_SUBMIT_REJECTED){
order = engine.submitOrder("order", Instrument.EURUSD, OrderCommand.BUY, 0.001);
message = order.waitForUpdate(2000, IOrder.State.OPENED);
}
print(String.format("更新後: オーダー状態=%s, メッセージ=%s", order.getState(), message));
}
public void onMessage(IMessage message) throws JFException {
print("<html><font color=\"gray\">"+message+"</font>");
}
public void print(Object message) {
console.getOut().println(message);
}
public void onStop() throws JFException {
for (IOrder order : engine.getOrders()) {
order.close();
}
}
public void onAccount(IAccount account) throws JFException {
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
}