package jforex.orders2;
import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.util.DateUtils;
public class PartialCloseByPrice implements IStrategy {
private IOrder order;
private IEngine engine;
private IConsole console;
private IHistory history;
private Instrument instrument = Instrument.EURUSD;
public void onStart(IContext context) throws JFException {
engine = context.getEngine();
console = context.getConsole();
history = context.getHistory();
context.setSubscribedInstruments(java.util.Collections.singleton(instrument), true);
double lastBid = history.getLastTick(instrument).getBid();
order = engine.submitOrder("orderPartialClose", instrument, OrderCommand.BUY, 0.01);
order.waitForUpdate(2000, IOrder.State.FILLED);
order.close(0.003, lastBid + 100 * instrument.getPipValue(), 5);
order.waitForUpdate(2000);
order.close(0.003, lastBid - 100 * instrument.getPipValue(), 5);
order.waitForUpdate(2000);
order.close();
context.stop();
}
public void onMessage(IMessage message) throws JFException {
console.getOut().format("%s\n%s クローズ価格=%.5f, 取引数量=%.3f, リクエストした取引数量=%.3f, クローズ時間=%s, オーダー状態=%s",
message, order.getLabel(), order.getClosePrice(), order.getAmount(), order.getRequestedAmount(),
DateUtils.format(order.getCloseTime()), order.getState()).println();
}
public void onTick(Instrument instrument, ITick tick) throws JFException {}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
public void onAccount(IAccount account) throws JFException {}
public void onStop() throws JFException {}
}