package jforex.data;
import java.util.List;
import com.dukascopy.api.*;
import com.dukascopy.api.util.DateUtils;
public class HistoryTicksSynch implements IStrategy {
private IHistory history;
private IConsole console;
@Override
public void onStart(IContext context) throws JFException {
history = context.getHistory();
console = context.getConsole();
context.setSubscribedInstruments(java.util.Collections.singleton(Instrument.EURUSD), true);
getTickByShift();
getTicksByTimeInterval();
}
private void getTickByShift() throws JFException{
ITick tick0 = history.getTick(Instrument.EURUSD, 0);
ITick tick1 = history.getTick(Instrument.EURUSD, 1);
console.getOut().println(String.format("[シフト指定]最後に受信したティック : %s", tick0));
console.getOut().println(String.format("[シフト指定]一つ前に受信したティック: %s", tick1));
}
private void getTicksByTimeInterval() throws JFException{
ITick lastTick = history.getLastTick(Instrument.EURUSD);
List<ITick> ticks = history.getTicks(Instrument.EURUSD, lastTick.getTime() - 10 * 1000, lastTick.getTime());
int last = ticks.size() - 1;
console.getOut().println(String.format(
"[タイムインターバル指定]取得したティック数=%s; 最後(最新)に受信したティックのBid価格=%.5f, 時刻=%s",
ticks.size(),
ticks.get(0).getBid() , DateUtils.format(ticks.get(0).getTime())
));
console.getOut().println(String.format(
"[タイムインターバル指定]取得したティック数=%s; 最も古い時間に取得したティックのBid価格=%.5f, 時刻=%s",
ticks.size(),
ticks.get(last).getBid(), DateUtils.format(ticks.get(last).getTime())
));
}
@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 {}
}