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.

"Label not Unique"
 Post subject: "Label not Unique" Post rating: 0   New post Posted: Mon 23 Mar, 2009, 11:51 

User rating: 0
Joined: Thu 06 Sep, 2007, 13:58
Posts: 4
Hi.

Sometimes I get following error message and my strategy stops:

-----------------------------------------------------------------------------------------------------------
02:05:50 com.dukascopy.api.JFException: Label not unique. (Order already exists) @ jforex.bttrader_v106.sendorder(bttrader_v106.java:118)
-----------------------------------------------------------------------------------------------------------

In my code I count all the positions that are open:


   protected int positionsTotal(Instrument currentInstrument) throws JFException {
      int counter = 0;
        for (IOrder order : engine.getOrders(currentInstrument)) {
            if (order.getState() == IOrder.State.FILLED) {
                counter++;
            }
        }
        return counter;
   }


...and
if (positionsTotal(currentInstrument)==0 && /*some other trade conditions here....*/)
I allow sending orders:
engine.submitOrder("LONG", currentInstrument, IEngine.OrderCommand.BUY,lot,0, 0, tick.getBid() - values_get("Pip") * stopLoss,   tick.getBid()+values_get("Pip") * takeProfit);


As I said, it only happens sometimes. I assume the following is happening:
1.) An order is sent, but not yet filled.
2.) The quotes change quickly, but order is still not filled.
3.) The "positionsTotal(currentInstrument)" still returns the value "0".
4.) Another order is sent, of course with the same label.
5.) Error message. Strategy stops.

How do I prevent the strategy from stopping?

Thanks for your help.

-Fuzzy


 
 Post subject: Re: "Label not Unique" Post rating: 0   New post Posted: Wed 01 Apr, 2009, 07:37 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
JForex is asynchronous API that means when you sent trade request function invokes immediately , but trade execution can take some time.
You can handle this by checking on ontick entry if there any order which is submited but result not known yet :

for (IOrder order : engine.getOrders(instrument)) {
    if (order.getState() == IOrder.State.CREATED) {
        haveCreatedState = true;
    }
}
iF(haveCreatedState){
//pass this tick since we have order in progress
return;
}


OR
you can use following code to wait for changes in submited order:

IOrder order = engine.submitOrder(generateLabel(magic), instrument, cmd, lot, isMarket ? 0 : price, slippage, slPrice, tpPrice, 0L, comment);
order.waitForUpdate(2000); //


OR simply change your statement so that your order can be in state other then FILLED before it fills (CREATED then SUBMITED then FILLED)


 
 Post subject: Re: "Label not Unique" Post rating: 0   New post Posted: Tue 26 May, 2009, 05:05 

User rating: 0
Joined: Tue 09 Dec, 2008, 05:20
Posts: 4
in my idea, It is because Api send 2 orders or more in a short time. when the first order was not filled ,the second order come,so it caused the "label not unique" error


 

Jump to:  

  © 1998-2024 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