package jforex.strategies.oneorder; 
import java.text.SimpleDateFormat;
import java.util.TimeZone; 
import com.dukascopy.api.*; 


public class OrderXAUUSD implements IStrategy {         
    private IEngine engine;    
    private IConsole console;    
    private IOrder order;    
    private SimpleDateFormat sdf;         
    private Instrument instrument = Instrument.XAUUSD;         

    private long counter = 0;
            
    public void onStart(IContext context) throws JFException {        
        engine = context.getEngine();        
        console = context.getConsole();        
        context.getConsole().getOut().println("Start");        
    }     
        
    public void onTick(Instrument instrument, ITick tick) throws JFException {    }         
    
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {        
        if(!period.equals(Period.ONE_HOUR) || !(instrument.equals(this.instrument))) return;        
        counter++;
        order = engine.submitOrder("order"+counter, instrument, IEngine.OrderCommand.BUY, 0.001);         


        for (IOrder order : engine.getOrders(instrument))
        {   if(order.getState() == IOrder.State.FILLED) order.close();
            
            console.getOut().println("CLOSED Position");             
        }

    }         


                
    public void onMessage(IMessage message) throws JFException {        
        console.getOut().println(message.getContent());    }         
        
    public void onAccount(IAccount account) throws JFException {}         
    
    public void onStop() throws JFException {         for(IOrder o: engine.getOrders()) o.close();        
 
    } 
} 

