public interface IEngine
| Modifier and Type | Interface and Description | 
|---|---|
| static class  | IEngine.OrderCommandSpecifies type of the order | 
| static class  | IEngine.RunModeStands for strategy run mode - if it is ran locally or on remote server | 
| static class  | IEngine.StrategyModeSpecifies strategy running mode. | 
| static class  | IEngine.TypeType of the engine | 
| Modifier and Type | Method and Description | 
|---|---|
| void | broadcast(java.lang.String topic,
         java.lang.String message)Broadcast message. | 
| void | closeOrders(java.util.Collection<IOrder> orders)Mass close. | 
| void | closeOrders(IOrder... orders)Mass close. | 
| java.lang.String | getAccount()Deprecated. 
 | 
| IOrder | getOrder(java.lang.String label)Returns order by label, or null if no order was found | 
| IOrder | getOrderById(java.lang.String orderId)Returns order in  IOrder.State.CREATED,IOrder.State.OPENEDandIOrder.State.FILLEDstate by id, or null if no order was found | 
| java.util.List<IOrder> | getOrders() | 
| java.util.List<IOrder> | getOrders(IFinancialInstrument financialInstrument)Deprecated.  | 
| java.util.List<IOrder> | getOrders(Instrument instrument)Returns list of orders in  IOrder.State.CREATED,IOrder.State.OPENEDandIOrder.State.FILLEDstate for
 specified instrument | 
| IEngine.RunMode | getRunMode()Returns strategy run mode - if it is ran locally or on remote server | 
| IEngine.StrategyMode | getStrategyMode()Returns strategy running mode, one of the  IEngine.StrategyMode.INDEPENDENTorIEngine.StrategyMode.SIGNALS. | 
| IEngine.Type | getType()Returns type of the engine, one of the  IEngine.Type.LIVE,IEngine.Type.DEMOorIEngine.Type.TESTfor tester. | 
| boolean | isTradable(Instrument instrument)Checks whether instrument is currently tradable. | 
| void | mergeOrders(IOrder... orders)Deprecated. 
 | 
| IOrder | mergeOrders(java.lang.String label,
           java.util.Collection<IOrder> orders)Merges positions. | 
| IOrder | mergeOrders(java.lang.String label,
           IOrder... orders)Merges positions. | 
| IOrder | mergeOrders(java.lang.String label,
           java.lang.String comment,
           java.util.Collection<IOrder> orders)Merges positions. | 
| IOrder | mergeOrders(java.lang.String label,
           java.lang.String comment,
           IOrder... orders)Merges positions. | 
| IOrder | submitOrder(java.lang.String label,
           IFinancialInstrument financialInstrument,
           IEngine.OrderCommand orderCommand,
           double amount)Deprecated.  | 
| IOrder | submitOrder(java.lang.String label,
           IFinancialInstrument financialInstrument,
           IEngine.OrderCommand orderCommand,
           double amount,
           double price)Deprecated.  | 
| IOrder | submitOrder(java.lang.String label,
           IFinancialInstrument financialInstrument,
           IEngine.OrderCommand orderCommand,
           double amount,
           double price,
           double slippage)Deprecated.  | 
| IOrder | submitOrder(java.lang.String label,
           IFinancialInstrument financialInstrument,
           IEngine.OrderCommand orderCommand,
           double amount,
           double price,
           double slippage,
           double stopLossPrice,
           double takeProfitPrice)Deprecated.  | 
| IOrder | submitOrder(java.lang.String label,
           IFinancialInstrument financialInstrument,
           IEngine.OrderCommand orderCommand,
           double amount,
           double price,
           double slippage,
           double stopLossPrice,
           double takeProfitPrice,
           long goodTillTime)Deprecated.  | 
| IOrder | submitOrder(java.lang.String label,
           IFinancialInstrument financialInstrument,
           IEngine.OrderCommand orderCommand,
           double amount,
           double price,
           double slippage,
           double stopLossPrice,
           double takeProfitPrice,
           long goodTillTime,
           java.lang.String comment)Deprecated.  | 
| IOrder | submitOrder(java.lang.String label,
           Instrument instrument,
           IEngine.OrderCommand orderCommand,
           double amount)Submits new order. | 
| IOrder | submitOrder(java.lang.String label,
           Instrument instrument,
           IEngine.OrderCommand orderCommand,
           double amount,
           double price)Submits new order. | 
| IOrder | submitOrder(java.lang.String label,
           Instrument instrument,
           IEngine.OrderCommand orderCommand,
           double amount,
           double price,
           double slippage)Submits new order. | 
| IOrder | submitOrder(java.lang.String label,
           Instrument instrument,
           IEngine.OrderCommand orderCommand,
           double amount,
           double price,
           double slippage,
           double stopLossPrice,
           double takeProfitPrice)Submits new order. | 
| IOrder | submitOrder(java.lang.String label,
           Instrument instrument,
           IEngine.OrderCommand orderCommand,
           double amount,
           double price,
           double slippage,
           double stopLossPrice,
           double takeProfitPrice,
           long goodTillTime)Submits new order. | 
| IOrder | submitOrder(java.lang.String label,
           Instrument instrument,
           IEngine.OrderCommand orderCommand,
           double amount,
           double price,
           double slippage,
           double stopLossPrice,
           double takeProfitPrice,
           long goodTillTime,
           java.lang.String comment)Submits new order. | 
IOrder submitOrder(java.lang.String label, Instrument instrument, IEngine.OrderCommand orderCommand, double amount, double price, double slippage, double stopLossPrice, double takeProfitPrice, long goodTillTime, java.lang.String comment) throws JFException
IOrder.State.CREATED status and will be updated to IOrder.State.OPENED status
 after server confirmation.
 
 
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IHistory history = context.getHistory();
     Instrument instrument = Instrument.EURUSD;
     context.setSubscribedInstruments(java.util.Collections.singleton(instrument), true);
     
     ITick lastTick = history.getLastTick(instrument);
     double price = lastTick.getAsk() + instrument.getPipValue() * 5;
     double sl = lastTick.getAsk() - instrument.getPipValue() * 20;
     double tp = lastTick.getAsk() + instrument.getPipValue() * 10;
     long SECOND = 1000;
     long gtt = lastTick.getTime() + 30 * SECOND; //withdraw after 30 secs
     IOrder order = engine.submitOrder("BuyStopOrder", instrument, OrderCommand.BUYSTOP, 0.1, price, 20, sl, tp, gtt, "My comment"); 
 }
 label - user defined identifier for the order. Label must be unique for the given user account among the current orders.
                        Allowed characters: letters, numbers and "_". Label must have at most 256 characters.instrument - instrumentorderCommand - type of submitted orderamount - amount in millions for the orderprice - preferred price for order. If zero, then last market price visible on the JForex will be used.
          Price should be divisible by 0.1 pips or order will be rejected.
          In case of market orders, incorrect price (worse than current market) will be changed to current price and slippageslippage - slippage. The value of slippage means following:
      Double.isNaN(slippage) == true then no slippage is used
          stopLossPrice - price of the stop loss. Price should be divisible by 0.1 pips or order will be rejectedtakeProfitPrice - price of the take profit. Price should be divisible by 0.1 pips or order will be rejectedgoodTillTime - how long order should live if not executed. Only if > 0, then orderCommand should NOT be
          neither IEngine.OrderCommand.BUY nor IEngine.OrderCommand.SELL market order.comment - comment that will be saved in orderIOrder.State.CREATED stateJFException - if label is not valid or already exists, if goodTillTime > 0 and orderCommand is not BID/OFFER, if amount is less
          than minimum allowed, if some of the required parameters is nullIOrder submitOrder(java.lang.String label, Instrument instrument, IEngine.OrderCommand orderCommand, double amount, double price, double slippage, double stopLossPrice, double takeProfitPrice, long goodTillTime) throws JFException
IOrder.State.CREATED status and will be updated to IOrder.State.OPENED status
 after server confirmation
 
 
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IHistory history = context.getHistory();
     Instrument instrument = Instrument.EURUSD;
     context.setSubscribedInstruments(java.util.Collections.singleton(instrument), true);
     
     ITick lastTick = history.getLastTick(instrument);
     double price = lastTick.getAsk() + instrument.getPipValue() * 5;
     double sl = lastTick.getAsk() - instrument.getPipValue() * 20;
     double tp = lastTick.getAsk() + instrument.getPipValue() * 10;
     long SECOND = 1000;
     long gtt = lastTick.getTime() + 30 * SECOND; //withdraw after 30 secs
     IOrder order = engine.submitOrder("BuyStopOrder", instrument, OrderCommand.BUYSTOP, 0.1, price, 20, sl, tp, gtt); 
 }
 label - user defined identifier for the order. Label must be unique for the given user account among the current orders.
                        Allowed characters: letters, numbers and "_". Label must have at most 256 characters.instrument - instrumentorderCommand - type of submitted orderamount - amount in millions for the orderprice - preferred price for order. If zero, then last market price visible on the JForex will be used.
          Price should be divisible by 0.1 pips or order will be rejected.
          In case of market orders, incorrect price (worse than current market) will be changed to current price and slippageslippage - slippage. The value of slippage means following:
      Double.isNaN(slippage) == true then no slippage is used
          stopLossPrice - price of the stop loss. Price should be divisible by 0.1 pips or order will be rejectedtakeProfitPrice - price of the take profit. Price should be divisible by 0.1 pips or order will be rejectedgoodTillTime - how long order should live if not executed. Only if > 0, then orderCommand should NOT be
          neither IEngine.OrderCommand.BUY nor IEngine.OrderCommand.SELL market order.IOrder.State.CREATED stateJFException - if label is not valid or already exists, if goodTillTime > 0 and orderCommand is not BID/OFFER, if amount is less
          than minimum allowed, if some of the required parameters is nullIOrder submitOrder(java.lang.String label, Instrument instrument, IEngine.OrderCommand orderCommand, double amount, double price, double slippage, double stopLossPrice, double takeProfitPrice) throws JFException
IOrder.State.CREATED status and will be updated to IOrder.State.OPENED status
 after server confirmation
 
 
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IHistory history = context.getHistory();
     Instrument instrument = Instrument.EURUSD;
     context.setSubscribedInstruments(java.util.Collections.singleton(instrument), true);
     
     ITick lastTick = history.getLastTick(instrument);
     double price = lastTick.getAsk() + instrument.getPipValue() * 5;
     double sl = lastTick.getAsk() - instrument.getPipValue() * 20;
     double tp = lastTick.getAsk() + instrument.getPipValue() * 10;
     IOrder order = engine.submitOrder("BuyStopOrder", instrument, OrderCommand.BUYSTOP, 0.1, price, 20, sl, tp); 
 }
 label - user defined identifier for the order. Label must be unique for the given user account among the current orders.
                        Allowed characters: letters, numbers and "_". Label must have at most 256 characters.instrument - instrumentorderCommand - type of submitted orderamount - amount in millions for the orderprice - preferred price for order. If zero, then last market price visible on the JForex will be used.
          Price should be divisible by 0.1 pips or order will be rejected.
          In case of market orders, incorrect price (worse than current market) will be changed to current price and slippageslippage - slippage. The value of slippage means following:
      Double.isNaN(slippage) == true then no slippage is used
          stopLossPrice - price of the stop loss. Price should be divisible by 0.1 pips or order will be rejectedtakeProfitPrice - price of the take profit. Price should be divisible by 0.1 pips or order will be rejectedIOrder.State.CREATED stateJFException - if label is not valid or already exists, if amount is less than minimum allowed, if some of the required
          parameters is nullIOrder submitOrder(java.lang.String label, Instrument instrument, IEngine.OrderCommand orderCommand, double amount, double price, double slippage) throws JFException
IOrder.State.CREATED status and will be updated to IOrder.State.OPENED status
 after server confirmation
 
 
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IHistory history = context.getHistory();
     Instrument instrument = Instrument.EURUSD;
     context.setSubscribedInstruments(java.util.Collections.singleton(instrument), true);
     
     ITick lastTick = history.getLastTick(instrument);
     double price = lastTick.getAsk() + instrument.getPipValue() * 5;
     IOrder order = engine.submitOrder("BuyStopOrder", instrument, OrderCommand.BUYSTOP, 0.1, price, 20); 
 }
 label - user defined identifier for the order. Label must be unique for the given user account among the current orders.
                        Allowed characters: letters, numbers and "_". Label must have at most 256 characters.instrument - instrumentorderCommand - type of submitted orderamount - amount in millions for the orderprice - preferred price for order. If zero, then last market price visible on the JForex will be used.
          Price should be divisible by 0.1 pips or order will be rejected.
          In case of market orders, incorrect price (worse than current market) will be changed to current price and slippageslippage - slippage. The value of slippage means following:
      Double.isNaN(slippage) == true then no slippage is used
          IOrder.State.CREATED stateJFException - if label is not valid or already exists, if amount is less than minimum allowed, if some of the required
          parameters is nullIOrder submitOrder(java.lang.String label, Instrument instrument, IEngine.OrderCommand orderCommand, double amount, double price) throws JFException
IOrder.State.CREATED status and will be updated to IOrder.State.OPENED status
 after server confirmation.
 
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IHistory history = context.getHistory();
     Instrument instrument = Instrument.EURUSD;
     context.setSubscribedInstruments(java.util.Collections.singleton(instrument), true);
     
     ITick lastTick = history.getLastTick(instrument);
     double price = lastTick.getAsk() + instrument.getPipValue() * 5;
     IOrder order = engine.submitOrder("BuyStopOrder", instrument, OrderCommand.BUYSTOP, 0.1, price); 
 }
  
 Note: default value of 5 pips slippage is used. To specify custom slippage, or disable slippage at all, please use extended submitOrder(...) methods.label - user defined identifier for the order. Label must be unique for the given user account among the current orders. 
                        Allowed characters: letters, numbers and "_". Label must have at most 256 characters.instrument - instrumentorderCommand - type of submitted orderamount - amount in millions for the orderprice - preferred price for order. If zero, then last market price visible on the JForex will be used.
          Price should be divisible by 0.1 pips or order will be rejected.
          In case of market orders, incorrect price (worse than current market) will be changed to current price and slippageIOrder.State.CREATED stateJFException - if label is not valid or already exists, if amount is less than minimum allowed, if some of the required
          parameters is nullsubmitOrder(String, Instrument, OrderCommand, double, double, double), 
submitOrder(String, Instrument, OrderCommand, double, double, double, double, double), 
submitOrder(String, Instrument, OrderCommand, double, double, double, double, double, long), 
submitOrder(String, Instrument, OrderCommand, double, double, double, double, double, long, String)IOrder submitOrder(java.lang.String label, Instrument instrument, IEngine.OrderCommand orderCommand, double amount) throws JFException
IOrder.State.CREATED status and will be updated to IOrder.State.OPENED status
 after server confirmation.
 
 
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     context.setSubscribedInstruments(java.util.Collections.singleton(Instrument.EURUSD), true);
     
     IOrder order = engine.submitOrder("MarketOrder", Instrument.EURUSD, OrderCommand.BUY, 0.1);
 }
  
 Note: default value of 5 pips slippage is used. To specify custom slippage, or disable slippage at all, please use extended submitOrder(...) methods.label - user defined identifier for the order. Label must be unique for the given user account among the current orders.
                        Allowed characters: letters, numbers and "_". Label must have at most 256 characters.instrument - instrumentorderCommand - type of submitted order. Only IEngine.OrderCommand.BUY and IEngine.OrderCommand.SELL allowed in this methodamount - amount in millions for the orderIOrder.State.CREATED stateJFException - if label is not valid or already exists, if amount is less than minimum allowed, if some of the required
          parameters is null or if orderCommand is not BUY or SELLsubmitOrder(String, Instrument, OrderCommand, double, double, double), 
submitOrder(String, Instrument, OrderCommand, double, double, double, double, double), 
submitOrder(String, Instrument, OrderCommand, double, double, double, double, double, long), 
submitOrder(String, Instrument, OrderCommand, double, double, double, double, double, long, String)IOrder getOrder(java.lang.String label) throws JFException
label - order's labelIOrder.State.CREATED, IOrder.State.OPENED and IOrder.State.FILLED state or nullJFException - if an error occurredIOrder getOrderById(java.lang.String orderId)
IOrder.State.CREATED, IOrder.State.OPENED and IOrder.State.FILLED state by id, or null if no order was foundorderId - order's idjava.util.List<IOrder> getOrders(Instrument instrument) throws JFException
IOrder.State.CREATED, IOrder.State.OPENED and IOrder.State.FILLED state for
 specified instrumentinstrument - instrumentJFException - if an error occurredjava.util.List<IOrder> getOrders() throws JFException
JFException - if an error occurredIOrder mergeOrders(java.lang.String label, IOrder... orders) throws JFException
IMessage.Type.ORDER_CLOSE_OK
 message for each of the positions) and a new - resulting position gets created and the IMessage.Type.ORDERS_MERGE_OK message gets sent. 
 There is no resulting position if the amount sum is 0 (short order amounts get negated).
 
 For full merge workflow see Merge states diagram
There is no merging for global accounts as there is never more than one position per instrument.
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IConsole console = context.getConsole();
     Instrument instrument = Instrument.EURUSD;
     context.setSubscribedInstruments(java.util.Collections.singleton(instrument), true);
     //0.01/BUY + 0.01/BUY + 0.01/BUY -> FILLED 0.03/BUY
     IOrder buy1 = engine.submitOrder("buy1", instrument, OrderCommand.BUY, 0.01);
     IOrder buy2 = engine.submitOrder("buy2", instrument, OrderCommand.BUY, 0.01);
     IOrder buy3 = engine.submitOrder("buy3", instrument, OrderCommand.BUY, 0.01);
     buy1.waitForUpdate(2000, IOrder.State.FILLED);
     buy2.waitForUpdate(2000, IOrder.State.FILLED);
     buy3.waitForUpdate(2000, IOrder.State.FILLED);
     IOrder buyMerge = engine.mergeOrders("mergedBuyPosition", buy1, buy2, buy3);
     buyMerge.waitForUpdate(2000, IOrder.State.FILLED);
     
     //0.03/BUY + 0.03/SELL -> Closed position with amount=0
     IOrder sell = engine.submitOrder("sell", instrument, OrderCommand.SELL, 0.03);
     sell.waitForUpdate(2000, IOrder.State.FILLED);
     IOrder mergedToZeroPos = engine.mergeOrders("mergedToZeroPosition", buyMerge, sell);
     mergedToZeroPos.waitForUpdate(2000, IOrder.State.CLOSED);     
     
     for (IOrder o : new IOrder[] {buy1, buy2, buy3, buyMerge, sell, mergedToZeroPos}) {
         console.getOut().format(
                 "%s cmd=%s created=%s closed=%s open price=%.5f close price=%.5f",
                 o,
                 o.getOrderCommand(),
                 DateUtils.format(o.getCreationTime()),
                 DateUtils.format(o.getCloseTime()),
                 o.getOpenPrice(),
                 o.getClosePrice()).println();
     }
 }	
 label - user defined identifier for the resulting order. Label must be unique for the given user account among the current ordersorders - orders to mergeJFException - if there are less than 2 positions passed; if any position:
                IOrder.State.FILLED state
          IOrder mergeOrders(java.lang.String label, java.lang.String comment, IOrder... orders) throws JFException
IMessage.Type.ORDER_CLOSE_OK
 message for each of the positions) and a new - resulting position gets created and the IMessage.Type.ORDERS_MERGE_OK message gets sent. 
 There is no resulting position if the amount sum is 0 (short order amounts get negated).
 
 For full merge workflow see Merge states diagram
There is no merging for global accounts as there is never more than one position per instrument.
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IConsole console = context.getConsole();
     Instrument instrument = Instrument.EURUSD;
     context.setSubscribedInstruments(java.util.Collections.singleton(instrument), true);
     //0.01/BUY + 0.01/BUY + 0.01/BUY -> FILLED 0.03/BUY
     IOrder buy1 = engine.submitOrder("buy1", instrument, OrderCommand.BUY, 0.01);
     IOrder buy2 = engine.submitOrder("buy2", instrument, OrderCommand.BUY, 0.01);
     IOrder buy3 = engine.submitOrder("buy3", instrument, OrderCommand.BUY, 0.01);
     buy1.waitForUpdate(2000, IOrder.State.FILLED);
     buy2.waitForUpdate(2000, IOrder.State.FILLED);
     buy3.waitForUpdate(2000, IOrder.State.FILLED);
     IOrder buyMerge = engine.mergeOrders("mergedBuyPosition", buy1, buy2, buy3);
     buyMerge.waitForUpdate(2000, IOrder.State.FILLED);
     
     //0.03/BUY + 0.03/SELL -> Closed position with amount=0
     IOrder sell = engine.submitOrder("sell", instrument, OrderCommand.SELL, 0.03);
     sell.waitForUpdate(2000, IOrder.State.FILLED);
     IOrder mergedToZeroPos = engine.mergeOrders("mergedToZeroPosition", buyMerge, sell);
     mergedToZeroPos.waitForUpdate(2000, IOrder.State.CLOSED);     
     
     for (IOrder o : new IOrder[] {buy1, buy2, buy3, buyMerge, sell, mergedToZeroPos}) {
         console.getOut().format(
                 "%s cmd=%s created=%s closed=%s open price=%.5f close price=%.5f",
                 o,
                 o.getOrderCommand(),
                 DateUtils.format(o.getCreationTime()),
                 DateUtils.format(o.getCloseTime()),
                 o.getOpenPrice(),
                 o.getClosePrice()).println();
     }
 }	
 label - user defined identifier for the resulting order. Label must be unique for the given user account among the current orderscomment - comment that will be saved in merged orderorders - orders to mergeJFException - if there are less than 2 positions passed; if any position:
                IOrder.State.FILLED state
          IOrder mergeOrders(java.lang.String label, java.util.Collection<IOrder> orders) throws JFException
IMessage.Type.ORDER_CLOSE_OK
 message for each of the positions) and a new - resulting position gets created and the IMessage.Type.ORDERS_MERGE_OK message gets sent. 
 There is no resulting position if the amount sum is 0 (short order amounts get negated).
 
 For full merge workflow see Merge states diagram
There is no merging for global accounts as there is never more than one position per instrument.
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IConsole console = context.getConsole();
     Instrument instrument = Instrument.EURUSD;
     context.setSubscribedInstruments(java.util.Collections.singleton(instrument), true);
     //0.01/BUY + 0.01/BUY + 0.01/BUY -> FILLED 0.03/BUY
     IOrder buy1 = engine.submitOrder("buy1", instrument, OrderCommand.BUY, 0.01);
     IOrder buy2 = engine.submitOrder("buy2", instrument, OrderCommand.BUY, 0.01);
     IOrder buy3 = engine.submitOrder("buy3", instrument, OrderCommand.BUY, 0.01);
     buy1.waitForUpdate(2000, IOrder.State.FILLED);
     buy2.waitForUpdate(2000, IOrder.State.FILLED);
     buy3.waitForUpdate(2000, IOrder.State.FILLED);
     IOrder buyMerge = engine.mergeOrders("mergedBuyPosition", buy1, buy2, buy3);
     buyMerge.waitForUpdate(2000, IOrder.State.FILLED);
     
     //0.03/BUY + 0.03/SELL -> Closed position with amount=0
     IOrder sell = engine.submitOrder("sell", instrument, OrderCommand.SELL, 0.03);
     sell.waitForUpdate(2000, IOrder.State.FILLED);
     IOrder mergedToZeroPos = engine.mergeOrders("mergedToZeroPosition", buyMerge, sell);
     mergedToZeroPos.waitForUpdate(2000, IOrder.State.CLOSED);     
     
     for (IOrder o : new IOrder[] {buy1, buy2, buy3, buyMerge, sell, mergedToZeroPos}) {
         console.getOut().format(
                 "%s cmd=%s created=%s closed=%s open price=%.5f close price=%.5f",
                 o,
                 o.getOrderCommand(),
                 DateUtils.format(o.getCreationTime()),
                 DateUtils.format(o.getCloseTime()),
                 o.getOpenPrice(),
                 o.getClosePrice()).println();
     }
 }	
 label - user defined identifier for the resulting order. Label must be unique for the given user account among the current ordersorders - orders to mergeJFException - if there are less than 2 positions passed; if any position:
                IOrder.State.FILLED state
          IOrder mergeOrders(java.lang.String label, java.lang.String comment, java.util.Collection<IOrder> orders) throws JFException
IMessage.Type.ORDER_CLOSE_OK
 message for each of the positions) and a new - resulting position gets created and the IMessage.Type.ORDERS_MERGE_OK message gets sent. 
 There is no resulting position if the amount sum is 0 (short order amounts get negated).
 
 For full merge workflow see Merge states diagram
There is no merging for global accounts as there is never more than one position per instrument.
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IConsole console = context.getConsole();
     Instrument instrument = Instrument.EURUSD;
     context.setSubscribedInstruments(java.util.Collections.singleton(instrument), true);
     //0.01/BUY + 0.01/BUY + 0.01/BUY -> FILLED 0.03/BUY
     IOrder buy1 = engine.submitOrder("buy1", instrument, OrderCommand.BUY, 0.01);
     IOrder buy2 = engine.submitOrder("buy2", instrument, OrderCommand.BUY, 0.01);
     IOrder buy3 = engine.submitOrder("buy3", instrument, OrderCommand.BUY, 0.01);
     buy1.waitForUpdate(2000, IOrder.State.FILLED);
     buy2.waitForUpdate(2000, IOrder.State.FILLED);
     buy3.waitForUpdate(2000, IOrder.State.FILLED);
     IOrder buyMerge = engine.mergeOrders("mergedBuyPosition", "my comment", buy1, buy2, buy3);
     buyMerge.waitForUpdate(2000, IOrder.State.FILLED);
     
     //0.03/BUY + 0.03/SELL -> Closed position with amount=0
     IOrder sell = engine.submitOrder("sell", instrument, OrderCommand.SELL, 0.03);
     sell.waitForUpdate(2000, IOrder.State.FILLED);
     IOrder mergedToZeroPos = engine.mergeOrders("mergedToZeroPosition", "my comment", buyMerge, sell);
     mergedToZeroPos.waitForUpdate(2000, IOrder.State.CLOSED);     
     
     for (IOrder o : new IOrder[] {buy1, buy2, buy3, buyMerge, sell, mergedToZeroPos}) {
         console.getOut().format(
                 "%s cmd=%s created=%s closed=%s open price=%.5f close price=%.5f",
                 o,
                 o.getOrderCommand(),
                 DateUtils.format(o.getCreationTime()),
                 DateUtils.format(o.getCloseTime()),
                 o.getOpenPrice(),
                 o.getClosePrice()).println();
     }
 }	
 label - user defined identifier for the resulting order. Label must be unique for the given user account among the current orderscomment - comment that will be saved in merged orderorders - orders to mergeJFException - if there are less than 2 positions passed; if any position:
                IOrder.State.FILLED state
          void closeOrders(IOrder... orders) throws JFException
Not applicable for global accounts
orders - orders to closeJFException - if orders not in IOrder.State.FILLED state.void closeOrders(java.util.Collection<IOrder> orders) throws JFException
Not applicable for global accounts
orders - orders to closeJFException - if orders not in IOrder.State.FILLED state.IEngine.Type getType()
IEngine.Type.LIVE, IEngine.Type.DEMO or IEngine.Type.TEST for tester.void broadcast(java.lang.String topic,
               java.lang.String message)
        throws JFException
topic - topic of messagemessage - text of messageJFException - if broadcast schedule was not successfulIEngine.StrategyMode getStrategyMode()
IEngine.StrategyMode.INDEPENDENT or IEngine.StrategyMode.SIGNALS.IEngine.RunMode getRunMode()
boolean isTradable(Instrument instrument)
Instrument.isTradable() instead.instrument - instrument to check@Deprecated IOrder submitOrder(java.lang.String label, IFinancialInstrument financialInstrument, IEngine.OrderCommand orderCommand, double amount, double price, double slippage, double stopLossPrice, double takeProfitPrice, long goodTillTime, java.lang.String comment) throws JFException
IOrder.State.CREATED status and will be updated to IOrder.State.OPENED status
 after server confirmation.
 
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IHistory history = context.getHistory();
     IFinancialInstrumentProvider instrumentProvider = context.getFinancialInstrumentProvider();
     IFinancialInstrument financialInstrument = instrumentProvider.getFinancialInstrument("EUR/USD");
     context.setSubscribedFinancialInstruments(Collections.singleton(financialInstrument), true);
     ITick lastTick = history.getLastTick(financialInstrument);
     double price = lastTick.getAsk() + financialInstrument.getPipValue() * 5;
     double sl = lastTick.getAsk() - financialInstrument.getPipValue() * 20;
     double tp = lastTick.getAsk() + financialInstrument.getPipValue() * 10;
     long SECOND = 1000;
     long gtt = lastTick.getTime() + 30 * SECOND; //withdraw after 30 secs
     IOrder order = engine.submitOrder("BuyStopOrder", financialInstrument, IEngine.OrderCommand.BUYSTOP, 0.1, price, 20, sl, tp, gtt, "My comment");
 }
 label - user defined identifier for the order. Label must be unique for the given user account among the current orders.
                        Allowed characters: letters, numbers and "_". Label must have at most 256 characters.financialInstrument - financial instrumentorderCommand - type of submitted orderamount - amount in millions for the orderprice - preferred price for order. If zero, then last market price visible on the JForex will be used.
          Price should be divisible by 0.1 pips or order will be rejected.
          In case of market orders, incorrect price (worse than current market) will be changed to current price and slippageslippage - slippage. The value of slippage means following:
      Double.isNaN(slippage) == true then no slippage is used
          stopLossPrice - price of the stop loss. Price should be divisible by 0.1 pips or order will be rejectedtakeProfitPrice - price of the take profit. Price should be divisible by 0.1 pips or order will be rejectedgoodTillTime - how long order should live if not executed. Only if > 0, then orderCommand should NOT be
          neither IEngine.OrderCommand.BUY nor IEngine.OrderCommand.SELL market order.comment - comment that will be saved in orderIOrder.State.CREATED stateJFException - if label is not valid or already exists, if goodTillTime > 0 and orderCommand is not BID/OFFER, if amount is less
          than minimum allowed, if some of the required parameters is null@Deprecated IOrder submitOrder(java.lang.String label, IFinancialInstrument financialInstrument, IEngine.OrderCommand orderCommand, double amount, double price, double slippage, double stopLossPrice, double takeProfitPrice, long goodTillTime) throws JFException
IOrder.State.CREATED status and will be updated to IOrder.State.OPENED status
 after server confirmation.
 
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IHistory history = context.getHistory();
     IFinancialInstrumentProvider instrumentProvider = context.getFinancialInstrumentProvider();
     IFinancialInstrument financialInstrument = instrumentProvider.getFinancialInstrument("EUR/USD");
     context.setSubscribedFinancialInstruments(Collections.singleton(financialInstrument), true);
     ITick lastTick = history.getLastTick(financialInstrument);
     double price = lastTick.getAsk() + financialInstrument.getPipValue() * 5;
     double sl = lastTick.getAsk() - financialInstrument.getPipValue() * 20;
     double tp = lastTick.getAsk() + financialInstrument.getPipValue() * 10;
     long SECOND = 1000;
     long gtt = lastTick.getTime() + 30 * SECOND; //withdraw after 30 secs
     IOrder order = engine.submitOrder("BuyStopOrder", financialInstrument, IEngine.OrderCommand.BUYSTOP, 0.1, price, 20, sl, tp, gtt);
 }
 label - user defined identifier for the order. Label must be unique for the given user account among the current orders.
                        Allowed characters: letters, numbers and "_". Label must have at most 256 characters.financialInstrument - financial instrumentorderCommand - type of submitted orderamount - amount in millions for the orderprice - preferred price for order. If zero, then last market price visible on the JForex will be used.
          Price should be divisible by 0.1 pips or order will be rejected.
          In case of market orders, incorrect price (worse than current market) will be changed to current price and slippageslippage - slippage. The value of slippage means following:
      Double.isNaN(slippage) == true then no slippage is used
          stopLossPrice - price of the stop loss. Price should be divisible by 0.1 pips or order will be rejectedtakeProfitPrice - price of the take profit. Price should be divisible by 0.1 pips or order will be rejectedgoodTillTime - how long order should live if not executed. Only if > 0, then orderCommand should NOT be
          neither IEngine.OrderCommand.BUY nor IEngine.OrderCommand.SELL market orderIOrder.State.CREATED stateJFException - if label is not valid or already exists, if goodTillTime > 0 and orderCommand is not BID/OFFER, if amount is less
          than minimum allowed, if some of the required parameters is null@Deprecated IOrder submitOrder(java.lang.String label, IFinancialInstrument financialInstrument, IEngine.OrderCommand orderCommand, double amount, double price, double slippage, double stopLossPrice, double takeProfitPrice) throws JFException
IOrder.State.CREATED status and will be updated to IOrder.State.OPENED status
 after server confirmation.
 
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IHistory history = context.getHistory();
     IFinancialInstrumentProvider instrumentProvider = context.getFinancialInstrumentProvider();
     IFinancialInstrument financialInstrument = instrumentProvider.getFinancialInstrument("EUR/USD");
     context.setSubscribedFinancialInstruments(Collections.singleton(financialInstrument), true);
     ITick lastTick = history.getLastTick(financialInstrument);
     double price = lastTick.getAsk() + financialInstrument.getPipValue() * 5;
     double sl = lastTick.getAsk() - financialInstrument.getPipValue() * 20;
     double tp = lastTick.getAsk() + financialInstrument.getPipValue() * 10;
     IOrder order = engine.submitOrder("BuyStopOrder", financialInstrument, IEngine.OrderCommand.BUYSTOP, 0.1, price, 20, sl, tp);
 }
 label - user defined identifier for the order. Label must be unique for the given user account among the current orders.
                        Allowed characters: letters, numbers and "_". Label must have at most 256 characters.financialInstrument - financial instrumentorderCommand - type of submitted orderamount - amount in millions for the orderprice - preferred price for order. If zero, then last market price visible on the JForex will be used.
          Price should be divisible by 0.1 pips or order will be rejected.
          In case of market orders, incorrect price (worse than current market) will be changed to current price and slippageslippage - slippage. The value of slippage means following:
      Double.isNaN(slippage) == true then no slippage is used
          stopLossPrice - price of the stop loss. Price should be divisible by 0.1 pips or order will be rejectedtakeProfitPrice - price of the take profit. Price should be divisible by 0.1 pips or order will be rejectedIOrder.State.CREATED stateJFException - if label is not valid or already exists, if goodTillTime > 0 and orderCommand is not BID/OFFER, if amount is less
          than minimum allowed, if some of the required parameters is null@Deprecated IOrder submitOrder(java.lang.String label, IFinancialInstrument financialInstrument, IEngine.OrderCommand orderCommand, double amount, double price, double slippage) throws JFException
IOrder.State.CREATED status and will be updated to IOrder.State.OPENED status
 after server confirmation.
 
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IHistory history = context.getHistory();
     IFinancialInstrumentProvider instrumentProvider = context.getFinancialInstrumentProvider();
     IFinancialInstrument financialInstrument = instrumentProvider.getFinancialInstrument("EUR/USD");
     context.setSubscribedFinancialInstruments(Collections.singleton(financialInstrument), true);
     ITick lastTick = history.getLastTick(financialInstrument);
     double price = lastTick.getAsk() + financialInstrument.getPipValue() * 5;
     IOrder order = engine.submitOrder("BuyStopOrder", financialInstrument, IEngine.OrderCommand.BUYSTOP, 0.1, price, 20);
 }
 label - user defined identifier for the order. Label must be unique for the given user account among the current orders.
                        Allowed characters: letters, numbers and "_". Label must have at most 256 characters.financialInstrument - financial instrumentorderCommand - type of submitted orderamount - amount in millions for the orderprice - preferred price for order. If zero, then last market price visible on the JForex will be used.
          Price should be divisible by 0.1 pips or order will be rejected.
          In case of market orders, incorrect price (worse than current market) will be changed to current price and slippageslippage - slippage. The value of slippage means following:
      Double.isNaN(slippage) == true then no slippage is used
          IOrder.State.CREATED stateJFException - if label is not valid or already exists, if goodTillTime > 0 and orderCommand is not BID/OFFER, if amount is less
          than minimum allowed, if some of the required parameters is null@Deprecated IOrder submitOrder(java.lang.String label, IFinancialInstrument financialInstrument, IEngine.OrderCommand orderCommand, double amount, double price) throws JFException
IOrder.State.CREATED status and will be updated to IOrder.State.OPENED status
 after server confirmation.
 
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IHistory history = context.getHistory();
     IFinancialInstrumentProvider instrumentProvider = context.getFinancialInstrumentProvider();
     IFinancialInstrument financialInstrument = instrumentProvider.getFinancialInstrument("EUR/USD");
     context.setSubscribedFinancialInstruments(Collections.singleton(financialInstrument), true);
     ITick lastTick = history.getLastTick(financialInstrument);
     double price = lastTick.getAsk() + financialInstrument.getPipValue() * 5;
     IOrder order = engine.submitOrder("BuyStopOrder", financialInstrument, IEngine.OrderCommand.BUYSTOP, 0.1, price);
 }
 
 Note: default value of 5 pips slippage is used. To specify custom slippage, or disable slippage at all, please use extended submitOrder(...) methods.label - user defined identifier for the order. Label must be unique for the given user account among the current orders.
                        Allowed characters: letters, numbers and "_". Label must have at most 256 characters.financialInstrument - financial instrumentorderCommand - type of submitted orderamount - amount in millions for the orderprice - preferred price for order. If zero, then last market price visible on the JForex will be used.
          Price should be divisible by 0.1 pips or order will be rejected.
          In case of market orders, incorrect price (worse than current market) will be changed to current price and slippageIOrder.State.CREATED stateJFException - if label is not valid or already exists, if amount is less than minimum allowed, if some of the required
          parameters is nullsubmitOrder(String, IFinancialInstrument, OrderCommand, double, double, double), 
submitOrder(String, IFinancialInstrument, OrderCommand, double, double, double, double, double), 
submitOrder(String, IFinancialInstrument, OrderCommand, double, double, double, double, double, long), 
submitOrder(String, IFinancialInstrument, OrderCommand, double, double, double, double, double, long, String)@Deprecated IOrder submitOrder(java.lang.String label, IFinancialInstrument financialInstrument, IEngine.OrderCommand orderCommand, double amount) throws JFException
IOrder.State.CREATED status and will be updated to IOrder.State.OPENED status
 after server confirmation.
 
 public void onStart(IContext context) throws JFException {
     IEngine engine = context.getEngine();
     IHistory history = context.getHistory();
     IFinancialInstrumentProvider instrumentProvider = context.getFinancialInstrumentProvider();
     IFinancialInstrument financialInstrument = instrumentProvider.getFinancialInstrument("EUR/USD");
     context.setSubscribedFinancialInstruments(Collections.singleton(financialInstrument), true);
     IOrder order = engine.submitOrder("BuyStopOrder", financialInstrument, IEngine.OrderCommand.BUYSTOP, 0.1);
 }
 
 Note: default value of 5 pips slippage is used. To specify custom slippage, or disable slippage at all, please use extended submitOrder(...) methods.label - user defined identifier for the order. Label must be unique for the given user account among the current orders.
                        Allowed characters: letters, numbers and "_". Label must have at most 256 characters.financialInstrument - financialInstrumentorderCommand - type of submitted order. Only IEngine.OrderCommand.BUY and IEngine.OrderCommand.SELL allowed in this methodamount - amount in millions for the orderIOrder.State.CREATED stateJFException - if label is not valid or already exists, if amount is less than minimum allowed, if some of the required
          parameters is null or if orderCommand is not BUY or SELLsubmitOrder(String, IFinancialInstrument, OrderCommand, double, double, double), 
submitOrder(String, IFinancialInstrument, OrderCommand, double, double, double, double, double), 
submitOrder(String, IFinancialInstrument, OrderCommand, double, double, double, double, double, long), 
submitOrder(String, IFinancialInstrument, OrderCommand, double, double, double, double, double, long, String)@Deprecated java.util.List<IOrder> getOrders(IFinancialInstrument financialInstrument) throws JFException
IOrder.State.CREATED, IOrder.State.OPENED and IOrder.State.FILLED state for
 specified instrumentfinancialInstrument - financial instrumentJFException - if an error occurred@Deprecated void mergeOrders(IOrder... orders) throws JFException
mergeOrders(String label, IOrder... orders)IMessage.Type.ORDER_CLOSE_OK
 message for each of the positions) and a new - resulting position gets created and the IMessage.Type.ORDERS_MERGE_OK message gets sent.
 There is no resulting position if the amount sum is 0 (short order amounts get negated).
 For full merge workflow see Merge states diagram
There is no merging for global accounts as there is never more than one position per instrument.
orders - positions to mergeJFException - if there are less than 2 positions passed; if any position:
                IOrder.State.FILLED state
          @Deprecated java.lang.String getAccount()
IAccount.getUserName()Copyright © 2025. All rights reserved.