package jforex.orders2;
import com.dukascopy.api.*;
public class ModifyLimitOrderWithMessages implements IStrategy {
private IConsole console;
private IEngine engine;
private IHistory history;
private IOrder order;
@Override
public void onStart(IContext context) throws JFException {
engine = context.getEngine();
console = context.getConsole();
history = context.getHistory();
context.setSubscribedInstruments(java.util.Collections.singleton(Instrument.EURUSD), true);
ITick tick = history.getLastTick(Instrument.EURUSD);
double openPrice = tick.getBid() + 0.0010;
double slippage = 1;
order = engine.submitOrder("order1" , Instrument.EURUSD, IEngine.OrderCommand.BUYSTOP, 0.01, openPrice, slippage, 0, 0);
console.getOut().println(String.format("%s, 取引数量=%s, エントリー価格=%s",
order.getLabel(), order.getAmount(), order.getOpenPrice()));
order.waitForUpdate(2000, IOrder.State.OPENED);
order.setOpenPrice(openPrice + 0.0010);
order.waitForUpdate(2000);
console.getOut().println(String.format("%s, 取引数量=%s, エントリー価格=%s",
order.getLabel(), order.getAmount(), order.getOpenPrice()));
order.setRequestedAmount(0.02);
order.waitForUpdate(2000);
console.getOut().println(String.format("%s, 取引数量=%s, エントリー価格=%s",
order.getLabel(), order.getAmount(), order.getOpenPrice()));
order.setRequestedAmount(0.03);
order.setRequestedAmount(0.04);
}
@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 {
console.getOut().println(message);
}
@Override
public void onAccount(IAccount account) throws JFException {}
@Override
public void onStop() throws JFException {
for(IOrder o : engine.getOrders())
o.close();
}
}