import com.dukascopy.api.*;
import com.dukascopy.api.bar.*;
import com.dukascopy.api.listener.*;

@RequiresFullAccess
public class TickBarStratJForexClient implements IStrategy {
    private IConsole console;
    private IHistory history;

    public void onStart(IContext context) throws JFException {

        this.history = context.getHistory();
        this.console = context.getConsole();

        // otherwise we will get "You are not subscribed"
        context.subscribeToTickBarFeed(Instrument.EURUSD, OfferSide.BID, TickBarSize.valueOf(5),
                new ITickBarFeedListener() {
                    public void onBar(Instrument instrument, OfferSide offerSide, TickBarSize tickBarSize, ITickBar bar) {
                        console.getOut().println(
                                "On Tick Bar " + " " + instrument + " " + offerSide + " " + tickBarSize + " " + bar);
                    }
                });
        /*
         * try { ITick tick = history.getLastTick(Instrument.EURUSD); java.util.List<ITickBar> tickBars =
         * history.getTickBars( Instrument.EURUSD, OfferSide.BID, TickBarSize.valueOf(5), //tick.getTime(), to - 31 * 24
         * * 3600 * 1000 100, tick.getTime(), 0 );
         * 
         * console.getOut().println("---------- getTickBars CALLED.");
         * console.getOut().println("---------- GOT TICKBARS, COUNT = " + tickBars.size()); } catch(Throwable th) {
         * console.getOut().println("Error! " + th);
         * 
         * // here I get // com.dukascopy.api.JFException: Passed Time [2011.08.12 00:00:00 457] // has to be in
         * interval [2007.03.30 16:01:15 688; 292269055.12.02 16:47:04 192] }
         */
    }

    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 {
    }

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}