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.