package singlejartest;

import com.dukascopy.api.*;
import com.dukascopy.api.feed.IFeedDescriptor;
import com.dukascopy.api.feed.IFeedListener;
import com.dukascopy.api.feed.util.RenkoFeedDescriptor;
import com.dukascopy.api.IIndicators.AppliedPrice;

public class IndicatorValueRenko4 implements IStrategy, IFeedListener {

    @Configurable("")
    public IFeedDescriptor renkoFeedDescriptor = new RenkoFeedDescriptor(Instrument.AUDUSD, PriceRange.valueOf(1), OfferSide.BID);

    private IConsole    console;
    private IIndicators indicators;

    public void onStart(IContext context) throws JFException {
        this.console    = context.getConsole();
        this.indicators = context.getIndicators();

        context.setSubscribedInstruments(java.util.Collections.singleton(renkoFeedDescriptor.getInstrument()), true);
        context.subscribeToFeed(renkoFeedDescriptor, this);
    }

    @Override
    public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) {
        console.getOut().println("completed " + feedData);
        try {
            Object[] WaddahATFeed = indicators.calculateIndicator(feedDescriptor, new OfferSide[] { feedDescriptor.getOfferSide() }, "WaddahAT", null, null, 1);
            double   WaddahAT     = (double)WaddahATFeed[0];
            print("WaddahAT=%f", WaddahAT);
        } catch (JFException e) {
            console.getErr().println(e);
            e.printStackTrace();
        }
    }

    private void print(String format, Object... args) {
        console.getOut().format(format, args).println();
    }

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