package jforex.orders2;
import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.util.DateUtils;
public class ImmediateOrCancel2 implements IStrategy {
@Configurable("通貨ペア")
public Instrument instrument = Instrument.EURUSD;
private IConsole console;
private IEngine engine;
private IHistory history;
private IOrder order;
private final String label = "iocOrder";
@Override
public void onStart(IContext context) throws JFException {
engine = context.getEngine();
console = context.getConsole();
history = context.getHistory();
context.setSubscribedInstruments(java.util.Collections.singleton(instrument), true);
console.getOut().println("開始");
double price = history.getLastTick(instrument).getBid() - 5 * instrument.getPipValue();
order = engine.submitOrder(label, instrument, OrderCommand.BUYLIMIT, 0.010, price, 0, 0, 0);
}
@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {}
@Override
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
@Override
public void onMessage(IMessage message) throws JFException {
if( message.getOrder() == order && order.getState() == IOrder.State.FILLED
&& Double.compare(order.getRequestedAmount(), order.getAmount()) != 0){
order.setRequestedAmount(0);
}
if(message.getOrder() != null){
console.getOut().println(DateUtils.format(message.getCreationTime()) + " " +message);
}
}
@Override
public void onAccount(IAccount account) throws JFException {}
@Override
public void onStop() throws JFException {
if (engine.getOrder(label) != null)
engine.getOrder(label).close();
}
}