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.

Submitting Orders for instruments
 Post subject: Submitting Orders for instruments Post rating: 0   New post Posted: Fri 23 Oct, 2009, 16:06 

User rating: 0
Joined: Fri 23 Oct, 2009, 15:48
Posts: 5
Hi,
I am new to Jforex coding. I need to submitOrders for the 4 instruments and display them. Request you to help me in achieving this.


 
 Post subject: Re: Submitting Orders for instruments Post rating: 0   New post Posted: Mon 26 Oct, 2009, 11:57 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
we prepared for you strategy example. Strategy places several orders for different instruments. After orders are filled, it places on current instruments chart new chart object (IChart.Type.TEXT) with message.
package jforex;

import java.util.*;
import com.dukascopy.api.*;

/**
 * This is simple strategy example. Strategy places several
 * orders for different instruments. After orders are filled,
 * it places on current instruments chart new chart object (IChart.Type.TEXT)
 * with message.   
 */
public class OrdersForFourInstruments implements IStrategy{
   
   private IContext context;
   private IEngine engine;
   private List<IOrder> orders;
   
   public void onStart(IContext context) throws JFException {
      this.context = context;
      this.engine = context.getEngine();
      this.orders = new ArrayList<IOrder>();
   }

   public void onAccount(IAccount account) throws JFException {
   }

   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar)throws JFException {      
   }

   public void onMessage(IMessage message) throws JFException {
      
      //Case filled is one of our orders
      if (message.getType().equals(IMessage.Type.ORDER_FILL_OK)){
         if (message.getOrder().getInstrument().equals(Instrument.EURUSD)||
               message.getOrder().getInstrument().equals(Instrument.EURJPY)||
               message.getOrder().getInstrument().equals(Instrument.EURGBP)||
               message.getOrder().getInstrument().equals(Instrument.EURAUD)) {
            
            // create chart object
            IChart chart = context.getChart(message.getOrder().getInstrument());
             if (chart != null) {
                
                long creationTime = message.getOrder().getCreationTime();
                double openPrice = message.getOrder().getOpenPrice();
                
                // use chart object to create and manipulate drawings
                chart.draw("chart", IChart.Type.TEXT, creationTime, openPrice);
                IChartObject chartObject = chart.get("chart");
                 chartObject.setText("Order Filled");                
                
             }
         }
      }      
   }

   public void onStop() throws JFException {
      
      // closing orders
      for (IOrder order : orders) {
         if (order.getState() == IOrder.State.FILLED
            || order.getState() == IOrder.State.OPENED){
            order.close();            
         }
      }
   }

   public void onTick(Instrument instrument, ITick tick) throws JFException {
      
      // placing orders once on first tick (one for each instrument)
      if (orders != null && orders.isEmpty()){   
         orders.add(engine.submitOrder("order_EURUSD", Instrument.EURUSD, IEngine.OrderCommand.BUY, 5));
         orders.add(engine.submitOrder("order_EURJPY", Instrument.EURJPY, IEngine.OrderCommand.BUY, 5));
         orders.add(engine.submitOrder("order_EURGBP", Instrument.EURGBP, IEngine.OrderCommand.BUY, 5));
         orders.add(engine.submitOrder("order_EURAUD", Instrument.EURAUD, IEngine.OrderCommand.BUY, 5));
      }      
   }
}


Attachments:
OrdersForFourInstruments.java [2.95 KiB]
Downloaded 518 times
OrdersForFourInstruments.jfx [3.76 KiB]
Downloaded 496 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 

Jump to:  

cron
  © 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