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.

detect in strategy a manual Market Orders
 Post subject: detect in strategy a manual Market Orders Post rating: 0   New post Posted: Thu 10 Sep, 2015, 20:19 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Dear Support,

I have used the following piece of code to detect in a strategy if a user submitted a Market Order on the platform.
public void onMessage(IMessage message) throws JFException {
    IOrder anOrder;
 
    anOrder = message.getOrder();
    if (anOrder == null) {
        return;
    }

    switch (message.getType()) {
        case ORDER_FILL_OK:
            if (myMarketOrders.contains(anOrder)) {
                // The previously detected Market Order was submitted.
                // Execute the super secret strategy code
            }
            break;

        case ORDER_SUBMIT_OK:
            if (anOrder.getOpenPrice() == 0.0) {
                // This is a Market Order manually submitted on the platform
                myMarketOrders.add(anOrder); // <-- this is a private Set<IOrder> that I use to store the market orders
            }
            break;

        default:
            break;
    }
}

This code was working fine till last Sunday/Monday, but not currently.
Currently the order's price is already 'available' when the order is in the OPENED state, so the above code is not working anymore.

Currently I have to following code that properly detects a manual Market Order submission:
public void onMessage(IMessage message) throws JFException {
   IOrder anOrder;

   anOrder = message.getOrder();
   if (anOrder == null) {
      return;
   }

   switch (message.getType()) {
       case NOTIFICATION:
      if (message.toString().contains("ORDER_ACCEPTED-Order ACCEPTED")
       && message.toString().contains(" @ MKT")
       && !message.toString().contains(" @ MKT IF ASK")
       && !message.toString().contains(" @ MKT IF BID")
       && !message.toString().contains("-FILLED ")
         ) {
                    // This is a Market Order manually submitted on the platform
                    myMarketOrders.add(anOrder); // <-- this is a private Set<IOrder> that I use to store the market orders
      }
      else
      if (message.toString().contains("ORDER_FILLED-Order FILLED")
       && message.toString().contains(" @ MKT")
       && !message.toString().contains(" @ MKT IF ASK")
       && !message.toString().contains(" @ MKT IF BID")
       && !message.toString().contains("-FILLED ")
         ) {
                    if (myMarketOrders.contains(anOrder)) {
                        // The previously detected Market Order was submitted.
                        // Execute the super secret strategy code
                    }
      }
      break;

       default:
      break;
   }
}


Processing the NOTIFICATION message doesn't look too elegant. And I am not sure if the message content will not be changed in the future, so I am looking for a better way to detect if a Market Order was submitted on the platform.

It is important to distinguish between Market Orders that are really submitted by the user from the Market Orders that are:
- created when a filled order is closed (aka when we close a BUY order, a SELL order will be created)
- created when a condition of a conditional order is fulfilled

So please give me some tips about this.
I know about the Order State diagram on the wiki, but I cannot figure out the difference between the above mentioned Market Orders.


 
 Post subject: Re: detect in strategy a manual Market Orders Post rating: 0   New post Posted: Mon 21 Sep, 2015, 12:45 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Dear Support,

Could you update me on this manner?

Thanks.


 
 Post subject: Re: detect in strategy a manual Market Orders Post rating: 0   New post Posted: Mon 21 Sep, 2015, 17:34 
User avatar

User rating: 70
Joined: Sat 22 Sep, 2012, 17:43
Posts: 118
Location: Brazil, Fortaleza, Ceará
1. What is wrong with using OrderCommand e.g. anOrder.getOrderCommand()?

https://www.dukascopy.com/client/javado ... mmand.html

BUY Buy by current market price.
BUYLIMIT Buy when ask price is <= specified price
BUYSTOP Buy when ask price is >= specified price
SELL Sell by current market price.
SELLLIMIT Sell when bid price is >= specified price
SELLSTOP Sell when bid price is <= specified price

These could be useful to you.


 
 Post subject: Re: detect in strategy a manual Market Orders Post rating: 0   New post Posted: Thu 07 Apr, 2016, 21:19 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Quote:
1. What is wrong with using OrderCommand e.g. anOrder.getOrderCommand()?

When a conditional order gets filled, there will be a message with the OrderCommand SELL/BUY accordingly. So only 'filtering' on anOrder.getOrderCommand() is not sufficient, as it cannot catch the difference between a 'real' market order (submitted by the user) and a fulfilled pending order.

And the same goes for closing orders. When I close a SELL order, an opposite BUY order is submitted, which BUY order is again 'caught' by the anOrder.getOrderCommand(), as 'BUY'.

So anOrder.getOrderCommand() doesn't deal with those extra cases I have submitted.


ps: sorry for bringing up such an old topic, but I haven't got the chance to test it sooner


 
 Post subject: Re: detect in strategy a manual Market Orders Post rating: 0   New post Posted: Tue 12 Apr, 2016, 08:20 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
CriticalSection wrote:
1. What is wrong with using OrderCommand e.g. anOrder.getOrderCommand()?

https://www.dukascopy.com/client/javado ... mmand.html

BUY Buy by current market price.
BUYLIMIT Buy when ask price is <= specified price
BUYSTOP Buy when ask price is >= specified price
SELL Sell by current market price.
SELLLIMIT Sell when bid price is >= specified price
SELLSTOP Sell when bid price is <= specified price

These could be useful to you.


Hello,CriticalSelection was right.
You can distinguish Orders by OrderCommand. At this moment, platform cant differ automatically using what Order was made, but there's a tricky thing you can do - using labels on orders and then retrieve them as you wish.For more information:Click Here


Good luck and have a nice day


 
 Post subject: Re: detect in strategy a manual Market Orders Post rating: 0   New post Posted: Wed 13 Apr, 2016, 08:14 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
I beg your pardon, but you are contradicting yourself.

Quote:
You can distinguish Orders by OrderCommand.

vs.
Quote:
At this moment, platform cant differ...



The label trick is not working, as the orders are placed on the JForex platform by the user, not by a strategy.
Anyway, there is another trick, the one that I have explained in the first post. But I as have said, I don't see that too robust.

Let's hope that the Message generation is not being modified in an upcoming release, without explicitly mentioning it in the Changelog...


 
 Post subject: Re: detect in strategy a manual Market Orders Post rating: 0   New post Posted: Wed 13 Apr, 2016, 11:39 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The only way to determine if order was created by a strategy is to look at the IOrder.getLabel().
When creating orders from a strategy labels could have a prefix.
This prefix could be then be checked to determine the origin of the strategy.


 

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