Historical Data Service
The IDataService interface provides information about the first available historical data of all data feeds.
Multiple feed types
Consider a strategy which retrieves times of first available data of the following data feeds of EUR/USD:
- daily candle sticks,
- ticks,
- renko bars.
- kagi bars
- line break bars
- point and figure bars
@Override
public void onStart(IContext context) throws JFException {
console = context.getConsole();
dataService = context.getDataService();
long timeCandle = dataService.getTimeOfFirstCandle(Instrument.EURUSD, Period.DAILY);
long timeRenko = dataService.getTimeOfFirstRenko(Instrument.EURUSD, Period.ONE_HOUR);
long timeTick = dataService.getTimeOfFirstCandle(Instrument.EURUSD, Period.TICK);
long timeRange = dataService.getTimeOfFirstRangeBar(Instrument.EURUSD, PriceRange.THREE_PIPS, DataInterpolationDescriptor.DEFAULT);
long timeKagi = dataService.getTimeOfFirstKagi(Instrument.EURUSD, Period.ONE_HOUR);
long timeLineBreak = dataService.getTimeOfFirstLineBreak(Instrument.EURUSD, Period.ONE_HOUR);
long timePointAndFigure = dataService.getTimeOfFirstPointAndFigure(Instrument.EURUSD, PriceRange.THREE_PIPS, ReversalAmount.ONE, DataInterpolationDescriptor.DEFAULT);
print("daily candle=%s,\nrenko=%s,\ntick=%s,\nrange=%s,\nkagi=%s,\nline break=%s,\npoint and figure=%s",
sdf.format(timeCandle),
sdf.format(timeRenko),
sdf.format(timeTick),
sdf.format(timeRange),
sdf.format(timeKagi),
sdf.format(timeLineBreak),
sdf.format(timePointAndFigure)
);
}
private void print (String format, Object...args){
console.getOut().println(String.format(format, args));
}
Multiple candle periods
Consider a strategy which retrieves first historical data for multiple candle stick periods:
package jforex;
import java.util.List;
import com.dukascopy.api.*;
import com.dukascopy.api.util.DateUtils;
import static com.dukascopy.api.Period.*;
/**
* The strategy retrieves first historical data for:
* - all periods that get fed in IStrategy.onBar
*/
public class FirstDataTimesMultiPeriods implements IStrategy {
private IDataService dataService;
private IHistory history;
private IConsole console;
private Period[] periods = new Period[]{
TEN_SECS, ONE_MIN, FIVE_MINS, TEN_MINS, FIFTEEN_MINS, THIRTY_MINS, ONE_HOUR, FOUR_HOURS, DAILY, WEEKLY, MONTHLY
};
@Override
public void onStart(IContext context) throws JFException {
console = context.getConsole();
history = context.getHistory();
dataService = context.getDataService();
for(Period period : periods){
long timeCandle = dataService.getTimeOfFirstCandle(Instrument.EURUSD, period);
List<IBar> bars = null;
try{
long from = history.getBarStart(period, timeCandle + period.getInterval());
long to = history.getBarStart(period, timeCandle + 2 * period.getInterval());
bars = history.getBars(Instrument.EURUSD, period, OfferSide.BID, from, to);
} catch (JFException e){
console.getErr().println(e);
}
console.getOut().format("daily candle=%s bars from history: %s", DateUtils.format(timeCandle), bars ).println();
}
}
@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {}
@Override
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
@Override
public void onMessage(IMessage message) throws JFException {}
@Override
public void onAccount(IAccount account) throws JFException {}
@Override
public void onStop() throws JFException {}
}
FirstDataTimesMultiPeriods.java
The information on this web site is provided only as general information, which may be incomplete or outdated. Click here for full disclaimer.