package com.dukascopy;


import com.dukascopy.api.*;
import com.dukascopy.api.feed.*;
import com.dukascopy.api.feed.util.RenkoFeedDescriptor;
import com.dukascopy.api.feed.util.TickBarFeedDescriptor;
import com.dukascopy.api.feed.util.TimePeriodAggregationFeedDescriptor;

import java.util.Arrays;
import java.util.HashSet;


public class StrategyrRenko implements IStrategy, IFeedListener {


    @Configurable("Instrument")
    public Instrument selectedInstrument = Instrument.EURUSD;
    @Configurable("OfferSide")
    public OfferSide selectedOfferSide = OfferSide.BID;
    @Configurable("Renko bar size (in pips)")
    public int selectedRenkoBarSizeInPips = 10;
    @Configurable("Renko type")
    public RenkoType renkoType = RenkoType.MEDIAN;

    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
    private IFeedDescriptor feedDescriptor;


    @Override
    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();

        this.feedDescriptor = new RenkoFeedDescriptor(
                selectedInstrument,
                PriceRange.ONE_PIP,
                selectedOfferSide,
                Period.TEN_SECS,
                CreationPoint.CLOSE
        );
        
        context.setSubscribedInstruments(new HashSet<>(Arrays.asList(selectedInstrument)), true);
        this.context.subscribeToFeed(feedDescriptor, this);
        
        context.openChart(feedDescriptor);
    }

    @Override
    public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) {
        console.getOut().println("new data");
        console.getOut().println(feedData);
    }


    private void print(String message) {
        console.getOut().println(message);
    }

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

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }


}

