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.

IHistory.getOrdersHistory(...) bug in JForex ver. 2.4.5
 Post subject: IHistory.getOrdersHistory(...) bug in JForex ver. 2.4.5 Post rating: 0   New post Posted: Wed 11 Aug, 2010, 17:14 
User avatar

User rating: 21
Joined: Thu 19 May, 2011, 20:50
Posts: 413
Location: Germany, Munich
After some testing I found the new JForex ver. 2.4.5, API ver. 2.6.12 buggy:
Function IHistory.getOrdersHistory(Instrument instrument, long from, long to) does not return any history orders any more.

Here is an example to demonstrate the bug:
package jforex;
import java.util.Calendar;
import java.util.List;
import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;

public class TestStrategy implements IStrategy {
  private IEngine engine;
  private IOrder order;
  private IContext context;
  private IConsole console;
  private IAccount account;
 

  public void onStart(IContext context) throws JFException {
    this.engine = context.getEngine();
    this.context = context;   
    this.console = context.getConsole();               
        Calendar startDate = Calendar.getInstance();
         startDate.roll(Calendar.DAY_OF_YEAR, -1);
        // startDate.roll(10, -5);
        Calendar endDate = Calendar.getInstance();
       
        console.getOut().print("startDate: "+startDate.getTime());
        console.getOut().println(", endDate: "+endDate.getTime());
        List<IOrder> orders = null;
        try{
             for (Instrument instr : context.getSubscribedInstruments()) {
                console.getOut().println("checking "+instr.toString());
                orders = context.getHistory().getOrdersHistory(instr, startDate.getTimeInMillis(), endDate.getTimeInMillis());
                if (!orders.isEmpty()){
                   console.getOut().println("Last Element: ClosePrice: "+orders.get(orders.size()-1).getClosePrice()+", closeTime: "+orders.get(orders.size()-1).getCloseTime()+", openTime: "+orders.get(orders.size()-1).getCreationTime() );
                }
             }
        }
        catch (Exception e) {
                console.getErr().println("Fehler: "+e.toString());
        }

  }

  public void onAccount(IAccount account) throws JFException {
    this.account = account;
  }

  public void onMessage(IMessage message) throws JFException {
  }

  public void onStop() throws JFException {
  }

  public void onTick(Instrument instrument, ITick tick) throws JFException {
  }

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


If you run the same strategy on JForex ver. 2.4.3, API ver. 2.6.8 it returns values.

Please correct asap.


 
 Post subject: Re: IHistory.getOrdersHistory(...) bug in JForex ver. 2.4.5 Post rating: 0   New post Posted: Wed 18 Aug, 2010, 08:25 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
Please make sure orders were actually submitted during the specified time period.
Please consider the following code:
package jforex;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IMessage.Type;

public class TestStrategy implements IStrategy {
  private IEngine engine;
  private IContext context;
  private IConsole console;

  public void onStart(IContext context) throws JFException {
    this.engine = context.getEngine();
    this.context = context;   
    this.console = context.getConsole();               
       
    engine.submitOrder("eurusd_order", Instrument.EURUSD, OrderCommand.BUY, 0.001);           
  }

  public void onAccount(IAccount account) throws JFException {
  }

  public void onMessage(IMessage message) throws JFException {
     if (message.getType() == Type.ORDER_FILL_OK){
        message.getOrder().close();
     }
     if (message.getType() == Type.ORDER_CLOSE_OK){
        printOrderHistory();
     }
  }

  public void onStop() throws JFException {
  }

  public void onTick(Instrument instrument, ITick tick) throws JFException {
  }

  public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
  }
 
  private void printOrderHistory() throws JFException{
     Calendar startDate = Calendar.getInstance();    
     startDate.roll(Calendar.DAY_OF_YEAR, -1);      
     Calendar endDate = Calendar.getInstance();    
          
     console.getOut().print("startDate: " + startDate.getTime());
     console.getOut().println(", endDate: " + endDate.getTime());
      
     SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
     List<IOrder> orders = null;
     try{
         for (Instrument instr : context.getSubscribedInstruments()) {
            console.getOut().println("Checking " + instr.toString() + ": ");
           orders = context.getHistory().getOrdersHistory(instr, startDate.getTimeInMillis(), endDate.getTimeInMillis());
           if (orders.isEmpty()) continue;
              
           IOrder lastOrder = orders.get(orders.size() - 1);           
           console.getOut().println("Last Element: ClosePrice: " + lastOrder.getClosePrice() + ", closeTime: " + format.format(lastOrder.getCloseTime()) +
                ", openTime: " + format.format(lastOrder.getCreationTime()));                       
         }   
     }catch (Exception e) {
        console.getErr().println("Fehler: " + e.toString());
     }
  }
}


 

Jump to:  

  © 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