Results 1 to 5 of 5
- 05-26-2010, 09:46 AM #1
Member
- Join Date
- May 2010
- Posts
- 2
- Rep Power
- 0
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();
}
}
}
- 05-26-2010, 09:50 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Consider using quartz
- 05-26-2010, 04:59 PM #3
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.
- 05-26-2010, 07:50 PM #4
Member
- Join Date
- May 2010
- Posts
- 2
- Rep Power
- 0
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.
- 05-26-2010, 08:30 PM #5
Similar Threads
-
Export data to xls
By trill in forum Advanced JavaReplies: 5Last Post: 03-24-2011, 05:13 AM -
How to export data from web page to msword or pdf
By verma1986 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 04-04-2010, 09:26 AM -
How do i export data from an oracle database to a CSV file
By BharathL in forum JDBCReplies: 3Last Post: 08-05-2008, 03:19 AM -
Java experts needed- 30 minute online Java projects
By michelle in forum Jobs OfferedReplies: 0Last Post: 03-05-2008, 11:47 PM -
problem with the way to export data to CSV file
By gonne in forum Java ServletReplies: 0Last Post: 07-01-2007, 02:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks