package singlejartest;
import java.text.SimpleDateFormat;

import java.text.SimpleDateFormat;     
import java.text.DateFormat;
import java.util.*;      
import com.dukascopy.api.*;
import java.math.*;



public class NewsTest implements IStrategy {

	private IEngine engine;

    private static final String DATE_FORMAT_NOW = "yyyyMMdd_HHmmssSSS";
    private static Random random = new Random();
    public IConsole console;  
   
      public void onStart(IContext context) throws JFException {
      this.console = context.getConsole();
      this.engine = context.getEngine();
    }
  
    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {

    if(message.getType() == IMessage.Type.CALENDAR)
    {
    	DateFormat formatter = new SimpleDateFormat("dd/MMM/yyyy hh:mm:ss");        
	    long pastdt = message.getCreationTime(); 
	    Calendar calendar = Calendar.getInstance();                                                                                            
	    calendar.setTimeInMillis(pastdt);   
	    String dt3 = formatter.format(calendar.getTime()); 
	    	
    console.getOut().println(" Inside Calendar Message. milli=" + pastdt +" mili2="+ message.getCreationTime() + " Actual=" + dt3 + " -> "+ message.getContent()) ;
   	}	
   }
    
// Executes on strategy stop    
    public void onStop() throws JFException {
        for (IOrder order : engine.getOrders()){
            if (order.getLabel().startsWith("I") && order.getState() == IOrder.State.OPENED) {
                order.close();                                                         
            }
        }
    }

// Executes on every tick    
    public void onTick(Instrument instrument, ITick tick) throws JFException {  
    }                   

// Executes on completion of a complete bar    
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {                 
	}
    
}


