Results 1 to 5 of 5
  1. #1
    franky is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default How to export historical data every 1 minute automatically

    Hi everyone,

    The attached program works well to export historical data upon a prompt
    for manual inputs including file path.

    Is it possible to add a loop to enable it export data continuously every
    1 minute without further outside intervention once started?

    Thank you very much in advance for enlightening me.

    frank




    ------------------------------------------
    package jforex;

    import java.util.*;
    import java.io.*;
    import java.text.*;

    import com.dukascopy.api.*;

    /**
    * @author Dmitry Shohov
    */
    @RequiresFullAccess
    public class ExportToCSV implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;

    @Configurable("Instrument")
    public Instrument instrument = Instrument.EURUSD;

    @Configurable("Period")
    public Period period = Period.ONE_MIN;

    @Configurable("OfferSide")
    public OfferSide offerSide = OfferSide.BID;

    @Configurable("File")
    public File file;

    private Writer out;
    private DateFormat dateFormat;
    private DecimalFormat priceFormat;

    public void onStart(IContext context) throws JFException {
    this.engine = context.getEngine();
    this.console = context.getConsole();
    this.history = context.getHistory();
    this.context = context;
    this.indicators = context.getIndicators();
    this.userInterface = context.getUserInterface();

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

    priceFormat = new DecimalFormat("0.#####");

    if (file == null || file.getPath().equals("")) {
    console.getErr().println("File not selected");
    context.stop();
    return;
    }
    try {
    out = new BufferedWriter(new FileWriter(file));
    } catch (Exception e) {
    console.getErr().println(e.getMessage());
    e.printStackTrace(console.getErr());
    context.stop();
    }
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {
    if (out != null) {
    try {
    out.close();
    } catch (Exception e) {
    console.getErr().println(e.getMessage());
    e.printStackTrace(console.getErr());
    context.stop();
    }
    }
    }

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

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    if (instrument != this.instrument || period != this.period) {
    return;
    }
    IBar bar = offerSide == OfferSide.ASK ? askBar : bidBar;
    try {
    out.write(dateFormat.format(bar.getTime()) + "," + priceFormat.format(bar.getOpen()) + "," + priceFormat.format(bar.getHigh()) + ","
    + priceFormat.format(bar.getLow()) + "," + priceFormat.format(bar.getClose()) + "," + priceFormat.format(askBar.getVolume()) + "\r\n");
    } catch (Exception e) {
    console.getErr().println(e.getMessage());
    e.printStackTrace(console.getErr());
    context.stop();
    }
    }
    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Consider using quartz

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    There are several classes you can use to schedule a task to run on its own thread. You would have to consider locking the resources or blocking updates while the background thread is outputing the data.

  4. #4
    franky is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default

    Thank you all for pointing me in the right direction. Though some experiences
    in other languages, I am new to java and may take time to figure it out
    eventually.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Be sure to look in the Java Tutorial. There are a lot of good examples there.

Similar Threads

  1. Export data to xls
    By trill in forum Advanced Java
    Replies: 5
    Last Post: 03-24-2011, 05:13 AM
  2. How to export data from web page to msword or pdf
    By verma1986 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 04-04-2010, 09:26 AM
  3. Replies: 3
    Last Post: 08-05-2008, 03:19 AM
  4. Java experts needed- 30 minute online Java projects
    By michelle in forum Jobs Offered
    Replies: 0
    Last Post: 03-05-2008, 11:47 PM
  5. problem with the way to export data to CSV file
    By gonne in forum Java Servlet
    Replies: 0
    Last Post: 07-01-2007, 02:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •