package jforex;

import java.util.*;

import com.dukascopy.api.*;
import java.text.SimpleDateFormat;

public class RemoteModeTest implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    
    private Set<Instrument> instruments = new HashSet<Instrument>();
    private int instruments_num; 
    private Period framePeriod;
    private IBar dailyBar;  
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");   
    private SimpleDateFormat dayOfWeek = new SimpleDateFormat("EEEE");
    private SimpleDateFormat timeOfDay = new SimpleDateFormat("HH:mm"); 
    private SimpleDateFormat hourOfDay = new SimpleDateFormat("H"); 
    
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        
        console.getOut().println("The Strategy started in a "+engine.getRunMode()+" "+engine.getType()+" mode");
        
        sdf.setTimeZone(TimeZone.getTimeZone("GMT+1")); 
        dayOfWeek.setTimeZone(TimeZone.getTimeZone("GMT+1"));
        timeOfDay.setTimeZone(TimeZone.getTimeZone("GMT+1"));
        hourOfDay.setTimeZone(TimeZone.getTimeZone("GMT+1"));
        
        if (engine.getType() == IEngine.Type.TEST)    // DEMO, LIVE, TEST
        {    
             instruments = context.getSubscribedInstruments();
             instruments_num = instruments.size();
             console.getOut().println("Subscribed instruments: "+instruments);
           
        }
        else
        {   // explicit subscription            
                     
            instruments.add(Instrument.EURUSD);
            instruments.add(Instrument.GBPUSD);
            instruments.add(Instrument.USDJPY);
                
            context.setSubscribedInstruments(instruments, true);
            instruments_num = instruments.size();
            
                                                                          
            console.getOut().println("Subscribed instruments: "+context.getSubscribedInstruments());
        } 
        
        framePeriod=Period.createCustomPeriod(Unit.Day, 1, JFTimeZone.EET);
        //framePeriod=Period.DAILY;
        dailyBar=history.getBar(Instrument.EURUSD,framePeriod, OfferSide.BID, 3);
        
        
        console.getOut().println("Daily Bar test: High="+ dailyBar.getHigh()+", Low="+dailyBar.getLow()+", time="+sdf.format(dailyBar.getTime()));
        
        context.stop();
        
    }

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