package renkoOnBarTestSimple;

import java.io.File;

import com.dukascopy.api.*;
import com.dukascopy.api.feed.FeedDescriptor;
import com.dukascopy.api.feed.IRenkoBar;
import com.dukascopy.api.feed.IRenkoBarFeedListener;


import org.slf4j.LoggerFactory;
import org.slf4j.Logger;

public class renkoTestStrategy3 implements IStrategy 
{

	// used for logging
	private static final Logger LOGGER = LoggerFactory.getLogger(renkoTestStrategy3.class);

    private FeedDescriptor renkoFeedDescriptor = null;

    private wtlRenkoBarFeedListener renkoListener = null;
    
	//Configurable strategy parameters
    // general
    @Configurable("Instrument") public Instrument instrument = Instrument.EURUSD;    
    @Configurable("Renko Block Size") public PriceRange renkoBarPriceRange = PriceRange.valueOf(15);
    
        
// *****  JFOREX API EVENT HANDLERS ****************************************************************

    class wtlRenkoBarFeedListener implements IRenkoBarFeedListener
    {
		@Override
		public void onBar(Instrument instrument, OfferSide offerSide, PriceRange priceRange, IRenkoBar bar) 
		{
	       	LOGGER.info("wtlRenkoBarFeedListener.onBar() [" + instrument.toString() + "]: " + priceRange.toString() + " " + bar.toString());

	       	
		}
    }
    
    public void onStart(IContext context) throws JFException 
    {

		// create feed descriptor to use when getting indicator values
		renkoFeedDescriptor = new FeedDescriptor();
		renkoFeedDescriptor.setDataType(DataType.RENKO);
		renkoFeedDescriptor.setInstrument(instrument);
		renkoFeedDescriptor.setOfferSide(OfferSide.BID);
		renkoFeedDescriptor.setPriceRange(renkoBarPriceRange);

		// subscribe to Renko Bar Feed
		renkoListener = new wtlRenkoBarFeedListener();
		context.subscribeToRenkoBarFeed(instrument, OfferSide.BID, renkoBarPriceRange, renkoListener);
        
	}

    public void onMessage(IMessage message) throws JFException 
    {        

    }
    
    public void onStop() throws JFException 
    {

    }
    
    public void onBar(Instrument instrument, Period period, IBar askbar, IBar bidbar) throws JFException 
    {
    	if (instrument == this.instrument && period == Period.DAILY)
    	{	
    		LOGGER.info("renkoTestStrategy.onBar() [" + instrument.toString() + "]: " + bidbar.toString());
    	}
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException 
    {
    
    }
    
    public void onAccount(IAccount account) throws JFException 
    {
        
    }

}