package jforex; import java.util.*; import com.dukascopy.api.*; /** * @author Dmitry Shohov */ public class GetTimeOfLastTickExample implements IStrategy { private IEngine engine; private IConsole console; private IHistory history; private IContext context; private IIndicators indicators; private IUserInterface userInterface; private IOrder order; public void onStart(IContext context) throws JFException { this.engine = context.getEngine(); this.console = context.getConsole(); this.history = context.getHistory(); this.context = context; this.indicators = context.getIndicators(); this.userInterface = context.getUserInterface(); } public void onAccount(IAccount account) throws JFException { } public void onMessage(IMessage message) throws JFException { } public void onStop() throws JFException { } public void onTick(Instrument instrument, ITick tick) throws JFException { if (order == null) { double bid = tick.getBid(); order = engine.submitOrder("tenSecondsOrder", instrument, IEngine.OrderCommand.PLACE_BID, 0.1, bid - instrument.getPipValue() * 50, 0, 0, 0, tick.getTime() + 10000); while (order.getState() != IOrder.State.FILLED && order.getState() != IOrder.State.CANCELED && !context.isStopped()) { //wait for 30 seconds, by this time order should be filled or canceled order.waitForUpdate(30000); } long currentTime = history.getTimeOfLastTick(instrument); console.getOut().println((currentTime - tick.getTime()) + " milliseconds difference between tick passed in method and latest tick"); context.stop(); } } public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { } }