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 error
 Post subject: onMessage error Post rating: 0   New post Posted: Tue 29 Jan, 2013, 00:14 

User rating: 0
Joined: Mon 28 Jan, 2013, 23:59
Posts: 2
Hi,

Could you please help me with the following error message I get mostly after starting the strategy (before putting in orders), sometimes a bit later (after putting in orders, with label "OVERNIGHT"):

java.lang.NullPointerException @ Strategy.on.onMessage(on.java:92)


This is the code:

90 public void onMessage(IMessage message) throws JFException {
91
92 if(message.getOrder().getLabel().startsWith("OVERNIGHT")) {
93 if (message.getType() == Type.ORDER_CLOSE_OK) {
94 if (message.getReasons().contains(IMessage.Reason.ORDER_CLOSED_BY_SL) ) {

Thanks in advance!


 
 Post subject: Re: onMessage error Post rating: 0   New post Posted: Tue 29 Jan, 2013, 10:04 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
straightforwardly you can't process order if it is null, consider processing the IMessage in the following way:
   @Override
   public void onMessage(IMessage message) throws JFException {
      if (message.getOrder() == null) {
         return; // the message is not order-related
      }
      if (message.getOrder().getLabel().startsWith("OVERNIGHT")
            && message.getType() == IMessage.Type.ORDER_CLOSE_OK
            && message.getReasons().contains(IMessage.Reason.ORDER_CLOSED_BY_SL)) {
         //your order-related logic comes here
      }
   }


 
 Post subject: Re: onMessage error Post rating: 0   New post Posted: Tue 29 Jan, 2013, 22:40 

User rating: 0
Joined: Mon 28 Jan, 2013, 23:59
Posts: 2
Great, thanks for the fast help, it's working now.

Regards!


 

Jump to:  

  © 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