import com.dukascopy.api.Configurable;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IEngine;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IIndicators;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.IUserInterface;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.Period;
import com.dukascopy.api.feed.ITickFeedListener;

public class Subscribe_to_realtime_tick_data implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;

    @Configurable("Instrument")
    public Instrument instrument = Instrument.EURUSD;

    @Configurable("Print tick")
    public boolean print = false;

    public void onStart(IContext context) throws JFException {
        this.setEngine(context.getEngine());
        this.console = context.getConsole();
        this.setHistory(context.getHistory());
        this.setContext(context);
        this.setIndicators(context.getIndicators());
        this.setUserInterface(context.getUserInterface());
        
        context.subscribeToTicksFeed(instrument, new ITickFeedListener() {
            public void onTick(Instrument instrument, ITick tick) {
                if (print) {console.getOut().println(tick);}
            }
        }
        );
    }

    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 {
    }

    public IEngine getEngine() {
        return engine;
    }

    public void setEngine(IEngine engine) {
        this.engine = engine;
    }

    public IHistory getHistory() {
        return history;
    }

    public void setHistory(IHistory history) {
        this.history = history;
    }

    public IContext getContext() {
        return context;
    }

    public void setContext(IContext context) {
        this.context = context;
    }

    public IIndicators getIndicators() {
        return indicators;
    }

    public void setIndicators(IIndicators indicators) {
        this.indicators = indicators;
    }

    public IUserInterface getUserInterface() {
        return userInterface;
    }

    public void setUserInterface(IUserInterface userInterface) {
        this.userInterface = userInterface;
    }
}