|
How to overwrite Label not unique(code 1). (Order already exists) |
JP7
|
Post subject: How to overwrite Label not unique(code 1). (Order already exists) |
Post rating: 0
|
Posted: Tue 18 Apr, 2017, 05:51
|
|
User rating: 13
Joined: Mon 27 Jul, 2015, 16:30 Posts: 110 Location: Canada, Mission
|
Some strategies work with the same open trades over and over again, but some strategies just once - if order exists posts: Label not unique(code 1). (Order already exists)
How to override Label not unique(code 1). (Order already exists) ???
04:43:05 com.dukascopy.api.JFException: Label not unique(code 1). (Order already exists) [EURUSD0]:label=EURUSD0;getId()=132954410;groupId=132954410;openingOrderId=504757624;pendingOrderId=null;pendingOrderCommand=null;parentOrderId=null;tpOrderId=null;slOrderId=null;state=FILLED;instrument=EUR/USD;openPrice=1.06475;requestedAmount=0.001;amount=0.001;lastServerRequest=NONE;awaitingResubmit=false;localCreationTime=1492490582794; fill history: [time=2017-04-18 04:42:16, price=1.06475, amount=0.001] @ com.dukascopy.api.impl.connect.cr.a(L:77)
|
|
|
|
|
JP7
|
Post subject: Re: How to overwrite Label not unique(code 1). (Order already exists) |
Post rating: 0
|
Posted: Tue 16 May, 2017, 13:16
|
|
User rating: 13
Joined: Mon 27 Jul, 2015, 16:30 Posts: 110 Location: Canada, Mission
|
Answering to my own question after some time !
Label must be unique to generate another order. A simple Label will generate only one order. Example of simple label: public void onTick(Instrument instrument, ITick tick) throws JFException { if (!ordersSubmitted) { ordersSubmitted = true; // engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL, TP, GTC; "note" engine.submitOrder("Buy_EURCHF", Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "B"); engine.submitOrder("Sell_EURUSD", Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "S"); engine.submitOrder("SellUSDCHF", Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "S"); }}
One solution used by may is to auto generate a label with a unique number. Example: protected String getLabel() { String label; label = "IVF" + generateRandom(10000) + generateRandom(10000); return label; }
private static String generateRandom(int n) { int randomNumber = (int) (Math.random() * n); String answer = "" + randomNumber; if (answer.length() > 3) { answer = answer.substring(0, 4);
But the simplest easiest way is to add to the label System.currentTimeMillis which is unique and continuously calculates time in milliseconds since 1 January 1970. Example:
public void onTick(Instrument instrument, ITick tick) throws JFException { if (!ordersSubmitted) { ordersSubmitted = true; // engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL,TP, GTC; "note" engine.submitOrder("X"+System.currentTimeMillis(), Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "Buy"); engine.submitOrder("X"+System.currentTimeMillis(), Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell"); engine.submitOrder("X"+System.currentTimeMillis(), Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell"); }} //:)
|
|
|
|
|
JP7
|
Post subject: Re: How to overwrite Label not unique(code 1). (Order already exists) |
Post rating: 0
|
Posted: Fri 15 Jun, 2018, 06:23
|
|
User rating: 13
Joined: Mon 27 Jul, 2015, 16:30 Posts: 110 Location: Canada, Mission
|
////label order - one label - one execution - messgae Label Not Unique if more ....
public void onTick(Instrument instrument, ITick tick) throws JFException { if (!ordersSubmitted) { ordersSubmitted = true; // engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL, TP, GTC; "note" engine.submitOrder("Buy_EURCHF", Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "B"); engine.submitOrder("Sell_EURUSD", Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "S"); engine.submitOrder("SellUSDCHF", Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "S");
}}
SOLUTIONS:
1. Using a simple counter //public class Counter implements IStrategy { private int counter = 0;
// engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL,TP, GTC; "note" engine.submitOrder("EURCHF"+counter , Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "Buy");counter++; engine.submitOrder("EURUSD"+counter , Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell");counter++; engine.submitOrder("USDCHF"+counter , Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell");counter++;
2. to add to the label System.currentTimeMillis which is unique and continuously calculates time in milliseconds since 1 January 1970. Example:
public void onTick(Instrument instrument, ITick tick) throws JFException { if (!ordersSubmitted) { ordersSubmitted = true; // engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL,TP, GTC; "note" engine.submitOrder("EURCHF"+System.currentTimeMillis(), Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "Buy"); engine.submitOrder("EURUSD"+System.currentTimeMillis(), Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell"); engine.submitOrder("USDCHF"+System.currentTimeMillis(), Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell"); }}
3, Counter + System.currentTimeMillis() //public class Counter implements IStrategy { private int counter = 0;
// engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL,TP, GTC; "note" engine.submitOrder("EURCHF"+counter+"T"+System.currentTimeMillis(), Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "Buy");counter++; engine.submitOrder("EURUSD"+counter+"T"+System.currentTimeMillis(), Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell");counter++; engine.submitOrder("USDCHF"+counter+"T"+System.currentTimeMillis(), Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell");counter++;
4. getLabel
////////////////// //4.1 label instrument+counter
private int counter = 0;
private String getLabel(Instrument instrument) { String label = instrument.name(); label = label + (counter++); label = label.toUpperCase(); return label; }
engine.submitOrder(getLabel(instr), instr, orderCmd, amount, 0, slippage); // engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL,TP, GTC; "note" engine.submitOrder(getLabel(instr), Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "Buy"); engine.submitOrder(getLabel(instr), , Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell"); engine.submitOrder(getLabel(instr), , Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell");
///////////////////// //4.2 label = "IVF" + currentTime + random + random engine.submitOrder(getLabel(tick.getTime()), selectedInstrument, IEngine.OrderCommand.SELL, tradeAmount, 0, slippage, stopLoss, takeProfit, 0, "SELL");
engine.submitOrder(getLabel(tick.getTime()), selectedInstrument, IEngine.OrderCommand.BUY, tradeAmount, 0, slippage, stopLoss, takeProfit, 0, "BUY"); protected String getLabel() { String label; label = "IVF" + getCurrentTime(LastTick.getTime()) + generateRandom(10000) + generateRandom(10000); return label; }
private String getCurrentTime(long time) { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); return sdf.format(time); }
private static String generateRandom(int n) { int randomNumber = (int) (Math.random() * n); String answer = "" + randomNumber; if (answer.length() > 3) { answer = answer.substring(0, 4); } return answer; } //////////////////////// //4.3 label instrument+counter+currentTimeMillis
private int counter = 0;
private String getLabel(Instrument instrument) { String label = instrument.name(); label = label + (counter++) +"T"+System.currentTimeMillis; label = label.toUpperCase(); return label; }
// engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL,TP, GTC; "note" engine.submitOrder(getLabel(instr), Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "Buy"); engine.submitOrder(getLabel(instr), , Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell"); engine.submitOrder(getLabel(instr), , Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell"); ///////////////////////////////////// //4.4
engine.submitOrder(getLabel(tick.getTime()), selectedInstrument, IEngine.OrderCommand.BUY, tradeAmount, 0, slippage, stopLoss, takeProfit, 0, "BUY");
private String getLabel(long time) { return "IVF" + DATE_FORMAT.format(time) + generateRandom(10000) + generateRandom(10000); }
private String generateRandom(int n) { int randomNumber = (int) (Math.random() * n); String answer = "" + randomNumber; if (answer.length() > 3) { answer = answer.substring(0, 4); } return answer; }
|
|
|
|
|
JudgeDredd
|
Post subject: Re: How to overwrite Label not unique(code 1). (Order already exists) |
Post rating: 0
|
Posted: Tue 26 Jun, 2018, 14:53
|
|
User rating: 0
Joined: Fri 19 Apr, 2013, 10:17 Posts: 31 Location: Ukraine, Kiev
|
|
|
|
|
JP7
|
Post subject: Re: How to overwrite Label not unique(code 1). (Order already exists) |
Post rating: 1
|
Posted: Wed 25 Jul, 2018, 10:29
|
|
User rating: 13
Joined: Mon 27 Jul, 2015, 16:30 Posts: 110 Location: Canada, Mission
|
////label order - one label - one execution - messgae Label Not Unique if more ....
public void onTick(Instrument instrument, ITick tick) throws JFException { if (!ordersSubmitted) { ordersSubmitted = true; // engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL, TP, GTC; "note" engine.submitOrder("Buy_EURCHF", Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "B"); engine.submitOrder("Sell_EURUSD", Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "S"); engine.submitOrder("SellUSDCHF", Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "S");
}}
SOLUTIONS:
1. Using a simple counter //public class Counter implements IStrategy { private int counter = 0;
// engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL,TP, GTC; "note" engine.submitOrder("EURCHF"+counter , Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "Buy");counter++; engine.submitOrder("EURUSD"+counter , Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell");counter++; engine.submitOrder("USDCHF"+counter , Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell");counter++;
2. to add to the label System.currentTimeMillis which is unique and continuously calculates time in milliseconds since 1 January 1970. Example:
public void onTick(Instrument instrument, ITick tick) throws JFException { if (!ordersSubmitted) { ordersSubmitted = true; // engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL,TP, GTC; "note" engine.submitOrder("EURCHF"+System.currentTimeMillis(), Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "Buy"); engine.submitOrder("EURUSD"+System.currentTimeMillis(), Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell"); engine.submitOrder("USDCHF"+System.currentTimeMillis(), Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell"); }}
3, Counter + System.currentTimeMillis() //public class Counter implements IStrategy { private int counter = 0;
// engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL,TP, GTC; "note" engine.submitOrder("EURCHF"+counter+"T"+System.currentTimeMillis(), Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "Buy");counter++; engine.submitOrder("EURUSD"+counter+"T"+System.currentTimeMillis(), Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell");counter++; engine.submitOrder("USDCHF"+counter+"T"+System.currentTimeMillis(), Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell");counter++;
4. getLabel
////////////////// //4.1 label instrument+counter
private int counter = 0;
private String getLabel(Instrument instrument) { String label = instrument.name(); label = label + (counter++); label = label.toUpperCase(); return label; }
// engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL,TP, GTC; "note" engine.submitOrder(getLabel(instr), Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "Buy"); engine.submitOrder(getLabel(instr), Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell"); engine.submitOrder(getLabel(instr), Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell");
///////////////////// //4.2 label = "IVF" + currentTime + random + random
engine.submitOrder(getLabel(tick.getTime()), selectedInstrument, IEngine.OrderCommand.SELL, tradeAmount, 0, slippage, stopLoss, takeProfit, 0, "SELL");
engine.submitOrder(getLabel(tick.getTime()), selectedInstrument, IEngine.OrderCommand.BUY, tradeAmount, 0, slippage, stopLoss, takeProfit, 0, "BUY"); protected String getLabel() { String label; label = "IVF" + getCurrentTime(LastTick.getTime()) + generateRandom(10000) + generateRandom(10000); return label; }
private String getCurrentTime(long time) { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); return sdf.format(time); }
private static String generateRandom(int n) { int randomNumber = (int) (Math.random() * n); String answer = "" + randomNumber; if (answer.length() > 3) { answer = answer.substring(0, 4); } return answer; } //////////////////////// //4.3 label instrument+counter+currentTimeMillis
private int counter = 0;
private String getLabel(Instrument instrument) { String label = instrument.name(); label = label + (counter++) +"T"+System.currentTimeMillis; label = label.toUpperCase(); return label; }
// engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL,TP, GTC; "note" engine.submitOrder(getLabel(instr), Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "Buy"); engine.submitOrder(getLabel(instr), Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell"); engine.submitOrder(getLabel(instr), Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell"); ///////////////////////////////////// //4.4 label long time random random
private String getLabel(long time) { return "IVF" + DATE_FORMAT.format(time) + generateRandom(10000) + generateRandom(10000); }
private String generateRandom(int n) { int randomNumber = (int) (Math.random() * n); String answer = "" + randomNumber; if (answer.length() > 3) { answer = answer.substring(0, 4); } return answer; }
// engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL,TP, GTC; "note" engine.submitOrder(getLabel(tick.getTime()), Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "Buy"); engine.submitOrder(getLabel(tick.getTime()), Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell"); engine.submitOrder(getLabel(tick.getTime()), Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell");
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //4.5 "IVF" + getCurrentTime
protected String getLabel() { String label; label = "IVF" + getCurrentTime(LastTick.getTime()); return label; }
private String getCurrentTime(long time) { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); return sdf.format(time); }
// engine.submitOrder("LABEL", Instrument.EURCHF, IEngine.OrderCommand.BUY, LOT , Price, Slip, SL,TP, GTC; "note" engine.submitOrder(getLabel(LastTick.getTime()), Instrument.EURCHF, IEngine.OrderCommand.BUY, 0.001, 0, 2, 0, 0, 0, "Buy"); engine.submitOrder(getLabel(LastTick.getTime()), Instrument.EURUSD, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell"); engine.submitOrder(getLabel(LastTick.getTime()), Instrument.USDCHF, IEngine.OrderCommand.SELL, 0.001, 0, 2, 0, 0, 0, "Sell");
|
|
|
|
|
|
Pages: [
1
]
|
|
|
|
|