package jforex.orders;

import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;

public class SLwithSlippage implements IStrategy {

    IConsole console;
    IEngine engine;
    IHistory history;
    Instrument instrument = Instrument.EURUSD;

    @Override
    public void onStart(IContext context) throws JFException {
        console = context.getConsole();
        engine = context.getEngine();
        history = context.getHistory();
        
        IOrder order = engine.submitOrder("order1", instrument, OrderCommand.BUY, 0.001);
        order.waitForUpdate(2000, IOrder.State.FILLED);
        double ask = history.getLastTick(instrument).getAsk();
        order.setStopLossPrice(ask - instrument.getPipValue() * 10, OfferSide.BID, 0.00);

    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }

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

    @Override
    public void onMessage(IMessage message) throws JFException {}

    @Override
    public void onAccount(IAccount account) throws JFException {}

    @Override
    public void onStop() throws JFException {}
}
