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.

Additional information in reports
 Post subject: Additional information in reports Post rating: 0   New post Posted: Fri 03 Jun, 2011, 14:52 

User rating: 0
Joined: Wed 18 May, 2011, 08:40
Posts: 43
Location: RU
Hi everybody,

Would be interesting to know if it's possible to add some user defined information to the reports page after the strategy testing was finished. For example: maximal/minimal price between position open and close times, profit/loss of long and short orders and so on.

Is it possible to implement such things with the API?


 
 Post subject: Re: Additional information in reports Post rating: 0   New post Posted: Tue 07 Jun, 2011, 07:20 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The report is just an html file, so you might add content to it in a similar way to this:

package singlejartest;

import com.dukascopy.api.*;
import com.dukascopy.api.system.ISystemListener;
import com.dukascopy.api.system.ITesterClient;
import com.dukascopy.api.system.TesterFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.Future;

/**
 * This small program demonstrates how to initialize Dukascopy tester and start a strategy
 * with a customization of strategy's report
 */
@RequiresFullAccess
public class TesterMainCustomReport {
   private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);

   // url of the DEMO jnlp
   private static String jnlpUrl = "https://www.dukascopy.com/client/demo/jclient/jforex.jnlp";
   // user name
   private static String userName = "USERNAME";
   // password
   private static String password = "PASSWORD";
   
   public static void insertStringInFile(File inFile, int lineno, String lineToBeInserted) throws Exception {
      // temp file
      File outFile = new File("$$$$$$$$.tmp");

      // input
      FileInputStream fis = new FileInputStream(inFile);
      BufferedReader in = new BufferedReader(new InputStreamReader(fis));

      // output
      FileOutputStream fos = new FileOutputStream(outFile);
      PrintWriter out = new PrintWriter(fos);

      String thisLine = "";
      int i = 1;
      while ((thisLine = in.readLine()) != null) {
         if (i == lineno)
            out.println(lineToBeInserted);
         out.println(thisLine);
         i++;
      }
      out.flush();
      out.close();
      in.close();

      inFile.delete();
      outFile.renameTo(inFile);
   }

   public static void main(String[] args) throws Exception {
      // get the instance of the IClient interface
      final ITesterClient client = TesterFactory.getDefaultInstance();
      // set the listener that will receive system events
      client.setSystemListener(new ISystemListener() {
         @Override
         public void onStart(long processId) {
            LOGGER.info("Strategy started: " + processId);
         }

         @Override
         public void onStop(long processId) {
            LOGGER.info("Strategy stopped: " + processId);
            File reportFile = new File("C:\\temp\\report.html");
            try {
               client.createReport(processId, reportFile);
               insertStringInFile(reportFile, 90, "<tr><th>__________INSERTED LINE__________</th><td>1.2345</td></tr>");
            } catch (Exception e) {
               LOGGER.error(e.getMessage(), e);
            }
            if (client.getStartedStrategies().size() == 0) {
               System.exit(0);
            }
         }

         @Override
         public void onConnect() {
            LOGGER.info("Connected");
         }

         @Override
         public void onDisconnect() {
            // tester doesn't disconnect
         }
      });

      LOGGER.info("Connecting...");
      // connect to the server using jnlp, user name and password
      // connection is needed for data downloading
      client.connect(jnlpUrl, userName, password);

      // wait for it to connect
      int i = 10; // wait max ten seconds
      while (i > 0 && !client.isConnected()) {
         Thread.sleep(1000);
         i--;
      }
      if (!client.isConnected()) {
         LOGGER.error("Failed to connect Dukascopy servers");
         System.exit(1);
      }

      // custom historical data
      String dateFromStr = "05/25/2011 00:00:00";
      String dateToStr = "05/26/2011 00:00:00";

      final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
      dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));

      Date dateFrom = dateFormat.parse(dateFromStr);
      Date dateTo = dateFormat.parse(dateToStr);

      client.setDataInterval(Period.THIRTY_MINS, OfferSide.BID, ITesterClient.InterpolationMethod.CLOSE_TICK, dateFrom.getTime(),
            dateTo.getTime());

      // set instruments that will be used in testing
      Set<Instrument> instruments = new HashSet<Instrument>();
      instruments.add(Instrument.EURUSD);
      LOGGER.info("Subscribing instruments...");
      client.setSubscribedInstruments(instruments);
      // setting initial deposit
      client.setInitialDeposit(Instrument.EURUSD.getSecondaryCurrency(), 50000);
      // load data
      LOGGER.info("Downloading data");
      Future<?> future = client.downloadData(null);
      // wait for downloading to complete
      future.get();
      // start the strategy
      LOGGER.info("Starting strategy");

      client.startStrategy(new MA_Play(), new LoadingProgressListener() {

         @Override
         public void dataLoaded(long startTime, long endTime, long currentTime, String information) {
            LOGGER.info(information);
         }

         @Override
         public void loadingFinished(boolean allDataLoaded, long startTime, long endTime, long currentTime) {
         }

         @Override
         public boolean stopJob() {
            return false;
         }
      });
      // now it's running

   }
}


 
 Post subject: Re: Additional information in reports Post rating: 0   New post Posted: Tue 07 Jun, 2011, 09:36 

User rating: 0
Joined: Wed 18 May, 2011, 08:40
Posts: 43
Location: RU
Thanks for example code. But so far I understand I need additional libraries for drawing of charts.


 
 Post subject: Re: Additional information in reports Post rating: 0   New post Posted: Tue 07 Jun, 2011, 13:42 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please elaborate what additional libraries for drawing of charts do you mean.


 
 Post subject: Re: Additional information in reports Post rating: 0   New post Posted: Tue 07 Jun, 2011, 14:32 

User rating: 0
Joined: Wed 18 May, 2011, 08:40
Posts: 43
Location: RU
For example OpenOffice SDK to create spreadsheets programmatically and insert charts or JFreeChart.
So far I know there is no way to draw charts in HTML only by using HTML-tags. You can only insert an image which contains the chart.


 
 Post subject: Re: Additional information in reports Post rating: 0   New post Posted: Tue 21 Jun, 2011, 13:50 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
trottel wrote:
For example OpenOffice SDK to create spreadsheets programmatically and insert charts or JFreeChart.So far I know there is no way to draw charts in HTML only by using HTML-tags. You can only insert an image which contains the chart.
You are right, there is no built-in support for such libraries and probably the best you can do is to insert an image in a similar fashion than that of the example above.


 

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