Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

onMessage method do not catch all event? Again...
 Post subject: onMessage method do not catch all event? Again... Post rating: 0   New post Posted: Mon 10 Feb, 2014, 11:20 

User rating: 3
Joined: Thu 28 Jul, 2011, 19:40
Posts: 72
Location: PolandPoland
Hello,

I opne this topic again because by mistake I press "is Answered" instead "Replay" Sory.

It is possible that if we have a lot of events in the same time, then onMessage method do nto catch all of this events?

Because I have situation, when in the same time it was change TP in one position and it was submit new order. And onMessages catch that TP was changed but do not catch that new order was filled.

How much this method is reliable?


So I attach strategy which display message on proper event in onMessage method and all time in onTick method check if we have new OPEN or FILLED order.
And sometimes it happened that if there was a lot of event in the same time, I have message from onTick method that we have new order, but I have not message from onMessage method neither "ORDER FILL ..." nor "ORDER SUBMIT ...", but have message e.g. "ORDER CHANGED TP " which happened in the same moment.

I want to mention that, I use DEMO platform and all position was opened by Signal Trading. (I subscribe a lot of signals providers)

Thanks and regards


Attachments:
OnMessageTest.java [3.52 KiB]
Downloaded 65 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: onMessage method do not catch all event? Again... Post rating: 0   New post Posted: Tue 11 Feb, 2014, 10:17 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We created a strategy that explicitly shows that what you claim is false. Launch the following strategy and see its messages:
package jforex.messages;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IEngine;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IOrder;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.Period;

public class MessageTest implements IStrategy {

    private IEngine engine;
    private IConsole console;
    private final Map<IOrder, List<IMessage.Type>> messages = new HashMap<IOrder, List<IMessage.Type>>();
    private Instrument instrument = Instrument.EURUSD;
    private int counter;
    private final Set<IOrder> tpSetInProgress = new HashSet<IOrder>();
    private final Set<IOrder> closeInProgress = new HashSet<IOrder>();

    @Override
    public void onStart(IContext context) throws JFException {
        engine = context.getEngine();
        console = context.getConsole();
        context.setSubscribedInstruments(EnumSet.of(Instrument.EURUSD));
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        if(instrument != this.instrument){
            return;
        }
//        console.getOut().println(tick);
        if(engine.getOrders().size() > 50){
            for(IOrder o : engine.getOrders()){
                if(o.getState() == IOrder.State.FILLED
                        && o.getTakeProfitPrice() > 0
                        && !closeInProgress.contains(o)){
                    o.close();
                    closeInProgress.add(o);
                }
            }
            return;
        }
        for(IOrder o : engine.getOrders()){
            if(o.getState() == IOrder.State.FILLED && o.getTakeProfitPrice() == 0 && !tpSetInProgress.contains(o)){
                double tpPrice = o.isLong()
                        ? tick.getBid() + instrument.getPipValue() * 10
                        : tick.getAsk() - instrument.getPipValue() * 10;
                o.setTakeProfitPrice(tpPrice);
                tpSetInProgress.add(o);
            }
        }
        for(int i = 0; i<10; i++){
            engine.submitOrder(String.format("o_%s_%s", counter++, System.currentTimeMillis()), instrument, OrderCommand.BUY, 0.001);
        }
       
    }

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

    @Override
    public void onMessage(IMessage message) throws JFException {
        IOrder order = message.getOrder();
        if(order == null || message.getType() == IMessage.Type.NOTIFICATION){
            return;
        }
        List<IMessage.Type> messageTypes = messages.get(order);
        if(messageTypes == null){
            messageTypes = new ArrayList<IMessage.Type>();
            messages.put(order, messageTypes);
        }
        messageTypes.add(message.getType());
        if(message.getType() == IMessage.Type.ORDER_CLOSE_OK){
            closeInProgress.remove(order);
            if(messageTypes.containsAll(Arrays.asList(IMessage.Type.ORDER_SUBMIT_OK, IMessage.Type.ORDER_FILL_OK))){
                console.getInfo().format("closed order %s has received all necessary messages: %s", order.getLabel(), messageTypes).println();
            } else {
                console.getErr().format("closed order %s has NOT received all necessary messages: %s", order.getLabel(), messageTypes).println();
            }
            messages.remove(order);
        }
        if(message.getReasons().contains(IMessage.Reason.ORDER_CHANGED_TP)){
            tpSetInProgress.remove(order);
        }
       
    }

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

    @Override
    public void onStop() throws JFException {
    }

}
The strategy sends a lot of requests at the same time to the server and as you see all necessary order change messages have been received by the onMessage. You can use the same strategy to make sure that also manual-trading orders' messages get received - simply remove the parts of the strategy that generate the orders and modifies them.


Attachments:
MessageTest.java [4.04 KiB]
Downloaded 67 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com