/*     
 * This is a test programm only, do not use for trading! 
 * It checks submitOrder
 * method of IEngine
 * At current JForex version it produces a strategy crash
 *
 * (c) Stash GmbH Muenchen / Germany, December 5th 2017
 *     www.stash.de
 *     Author: Bernhard Schicht
 *     Email: exp@stash.de
 */

package jforex;
import java.util.*;
import com.dukascopy.api.IEngine.*;
import com.dukascopy.api.*;

public class AnotherPlaceBidOfferBug implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;   
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.context = context;
    }
    public void onAccount(IAccount account) throws JFException {
        Set<Instrument> subscribe = new HashSet<Instrument>();    
        subscribe.add(Instrument.EURUSD);
        context.setSubscribedInstruments(subscribe, true);   
    }
    public void onMessage(IMessage message) throws JFException {
        console.getOut().println("<html><font color=\"#2020FF\">message = "+message+"</font>");
    }  
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        // at  12-12-2017 06:49:31.266 GMT  
        if (tick.getTime() == 1513061371266L){
            // place bid order 
            IOrder longOrder = engine.submitOrder(
                    "Test_"+System.currentTimeMillis(),instrument,
                    OrderCommand.PLACE_BID, 
                    0.01, 1.17780, 0, 1.17681, 1.17831, 0L);                     
            context.getConsole().getOut().println("longOrder = " +longOrder);
            
            // place another bid order 
            IOrder anotherLongOrder = engine.submitOrder(
                    "AnotherTest_"+System.currentTimeMillis(),instrument,
                    OrderCommand.PLACE_BID,                                          
                    // 0.02, 1.17780, 20, 1.17681, 1.17831, 0L);    // this gets a fill
                       0.02, 1.17780, 0, 1.17681, 1.17981, 0L);    // this does NOT get filled!    
            
            context.getConsole().getOut().println("anotherLongOrder = " +anotherLongOrder);
        }
    }    
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {    }
    public void onStop() throws JFException { }    
}