private String getLabel(OrderCommand cmd) { return cmd.toString() + UUID.randomUUID().toString().replace('-', '0'); // + System.currentTimeMillis(); } ////label order comm
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");
}} //:)
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; }
|