package jforex;
import com.dukascopy.api.*;
public class ReadBarsExample implements IStrategy {
private IContext context;
private IConsole console;
private IHistory history;
private int numberOfBarsLoaded;
private boolean executed;
public void onStart(IContext context) throws JFException {
this.context = context;
this.history = context.getHistory();
this.console = context.getConsole();
}
public void onAccount(IAccount account) throws JFException { }
public void onMessage(IMessage message) throws JFException { }
public void onStop() throws JFException { }
public void onTick(Instrument instrument, ITick tick) throws JFException {
if (!executed) {
console.getOut().println("readBarsメソッド呼び出し中");
history.readBars(
Instrument.EURUSD,
Period.TEN_SECS,
OfferSide.BID,
history.getBarStart(Period.DAILY, tick.getTime()) - Period.DAILY.getInterval() ,
history.getBarStart(Period.DAILY, tick.getTime()) - Period.TEN_SECS.getInterval(),
new LoadingDataListener() {
public void newTick(Instrument instrument, long time, double ask, double bid,
double askVol, double bidVol) {
}
public void newBar(Instrument instrument, Period period, OfferSide side, long time,
double open, double close, double low, double high, double vol) {
++numberOfBarsLoaded;
}
},
new LoadingProgressListener() {
public void dataLoaded(long startTime, long endTime, long currentTime, String information) {
console.getOut().println(information);
}
public void loadingFinished(boolean allDataLoaded, long startTime, long endTime, long currentTime) {
if (allDataLoaded) {
console.getOut().println("全データロード完了。ロード済みバー数: " + numberOfBarsLoaded);
context.stop();
} else {
console.getOut().println("ロード失敗したか、ユーザー操作によってキャンセルされました。");
context.stop();
}
}
public boolean stopJob() {
return false;
}
}
);
console.getOut().println("readBarsメソッド呼び出し終了。読み込んだバー数:" + numberOfBarsLoaded);
executed = true;
context.stop();
}
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { }
}