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.

How to store messages in .csv from JForex SDK?
 Post subject: How to store messages in .csv from JForex SDK? Post rating: 0   New post Posted: Mon 07 Jan, 2013, 23:00 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Dear Support,

If I run my strategy in the JForex client, the messages of the strategy can be saved to a .csv file. These messages are generated by console.getOut().println();

If I run the same strategy using the TesterMain class from the JForex SDK in Eclipse, I can see the same messages appear in Console of Eclipse, together with some other messages. I have 2 questions regarding this Console output:
1) How can I avoid messages like
2013-01-07 22:15:06.256 INFO  singlejartest.Main - Running, Sun 2011.07.10 04:30 Eq: 49,785.92 UoL: .00%
2013-01-07 22:15:06.270 INFO  singlejartest.Main - Running, Sun 2011.07.10 05:00 Eq: 49,785.92 UoL: .00%
2013-01-07 22:15:06.283 INFO  singlejartest.Main - Running, Sun 2011.07.10 05:30 Eq: 49,785.92 UoL: .00%
2013-01-07 22:15:06.296 INFO  singlejartest.Main - Running, Sun 2011.07.10 06:00 Eq: 49,785.92 UoL: .00%
2013-01-07 22:15:06.308 INFO  singlejartest.Main - Running, Sun 2011.07.10 06:30 Eq: 49,785.92 UoL: .00%

to appear in the Console. I don`t need these.

2) How can I store the messages that are important for me (the ones that are coming from the strategy`s console.getOut().println()) in a .csv file, just like the JForex Client does.


Thanks and regards.


 
The Best Answer  Post subject: Re: How to store messages in .csv from JForex SDK? Post rating: 0   New post Posted: Tue 08 Jan, 2013, 18:31 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
tcsabina wrote:
1) How can I avoid messages like
Modify the logging settings found in JForex-SDK\rc\log4j.properties. For more on logging see:
https://logging.apache.org/log4j/1.2/manual.html
tcsabina wrote:
2) How can I store the messages that are important for me (the ones that are coming from the strategy`s console.getOut().println()) in a .csv file, just like the JForex Client does.
See:
https://docs.oracle.com/javase/tutorial/essential/io/file.html
If you wish to intercept the IConsole outputs, then you need modify the IConsole implementation that you use, for instance:
package jforex.sdk;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;

import com.dukascopy.api.*;

public class BarPrinterUni implements IStrategy {

   private IConsole console;

   @Override
   public void onStart(final IContext context) throws JFException {
      try {
         console = new IConsole() {
            PrintStream printStream = new PrintStream( new FileOutputStream("myLogFile.csv", true)){
               //intercept string logging
               @Override
                public void println(String x) {                  
                  super.println(x); //will go to the file
                  context.getConsole().getOut().println(x); //to strategy console
               }
            };

            @Override
            public PrintStream getOut() {
               return printStream;
            }

            @Override
            public PrintStream getErr() {
               return printStream;
            }

            @Override
            public PrintStream getWarn() {
               return printStream;
            }

            @Override
            public PrintStream getInfo() {
               return printStream;
            }

            @Override
            public PrintStream getNotif() {
               return printStream;
            }

         };
      } catch (FileNotFoundException e) {
         e.printStackTrace();
      }
   }

   @Override
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
      console.getOut().println(instrument + " bar: " + period + " " + askBar);
   }

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

   public void onMessage(IMessage message) throws JFException {
   }

   public void onAccount(IAccount account) throws JFException {
   }

   public void onStop() throws JFException {
   }
}



 
 Post subject: Re: How to store messages in .csv from JForex SDK? Post rating: 0   New post Posted: Wed 09 Jan, 2013, 11:02 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Thank you. I will dive into this...


 
 Post subject: Re: How to store messages in .csv from JForex SDK? Post rating: 0   New post Posted: Wed 09 Jan, 2013, 21:58 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Dear Support,

This worked like charm...
Thanks again!


Edit: Just discovered a little issue:
If I run the strategy from the platform, I got
Strategy tester: java.security.AccessControlException: access denied ("java.io.FilePermission" "E:\work\JForex\Messages\myLogFile.csv" "write") @ singlejartest.MyStrategy.onStart(MyStrategy.java:220)


The same strategy runs fine (and creates the file without a problem) from Eclipse. Any tips how to make this working from the platform as well? Would be nice if I don`t have to modify the strategy if I want to change between Eclipse and the platform. But of course it isn`t that big of a problem...


 
 Post subject: Re: How to store messages in .csv from JForex SDK? Post rating: 0   New post Posted: Thu 10 Jan, 2013, 08:20 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See the first paragraph of:
https://www.dukascopy.com/wiki/#Write_in_File


 
 Post subject: Re: How to store messages in .csv from JForex SDK? Post rating: 0   New post Posted: Thu 10 Jan, 2013, 22:57 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Thanks,

@RequiresFullAccess
did the trick...


 

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