/*     
 * This is a test programm only, do not use for trading! 
 * It checks submitOrder method of IEngine for BTC/USD
 *
 * (c) Stash GmbH Muenchen / Germany, 12.4.2018
 *     http://www.stash.de
 *     Author: Bernhard Schicht
 *     Email: exp@stash.de
 */

package jforex;
import java.util.*;
import com.dukascopy.api.*;
public class SizeTest2 implements IStrategy {
    @Configurable("trading volume")                
    public double amount  = 1.2D;  
    
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;

    private boolean runEntryOnce = false;
    private boolean runCheckOnce = false;
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        if (instrument != Instrument.BTCUSD) return;
        if (!runEntryOnce){
            runEntryOnce = true;
            double size = amount / 1000000D;
            console.getOut().println("try to enter volume of "+size);
            engine.submitOrder("test"+System.currentTimeMillis(),instrument,IEngine.OrderCommand.BUY, size, tick.getAsk(), 1000D);
            return;
        }
        if (!runCheckOnce){
            runCheckOnce = false;
            for(IOrder order : engine.getOrders()){
                console.getOut().println(order.toString()+", order.getOriginalAmount() = "+order.getOriginalAmount()+", order.getAmount() = "+order.getAmount()+", order.getRequestedAmount() =  "+order.getRequestedAmount());
            }    
        }
    }
    public void onMessage(IMessage message) throws JFException {   
        IOrder order = message.getOrder();
        if (order == null) return;
        if (message.getType() != IMessage.Type.ORDER_FILL_OK) return;
        console.getOut().println(order.toString()+", order.getOriginalAmount() = "+order.getOriginalAmount()+", order.getAmount() = "+order.getAmount()+", order.getRequestedAmount() =  "+order.getRequestedAmount());
    }
    
    // initial stuff
    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();
    }
    public void onAccount(IAccount account) throws JFException {   }

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