Hello,
I want to make trades at specific time by timer. In order to achieve this I wrote the following code:
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
this.history = context.getHistory();
this.context = context;
this.timer = new Timer();
tt = new TimerTask(){
@Override
public void run() {
try {
InitiateTrading();
} catch (Exception e) {
};
}
};
timer.scheduleAtFixedRate(tt, 0, 1000);
}
private void InitiateTrading() throws JFException
{
Date d = new Date();
Calendar calCurrentTick = GregorianCalendar.getInstance();
calCurrentTick.setTime(d);
int year = calCurrentTick.get(Calendar.YEAR);
int month = calCurrentTick.get(Calendar.MONTH);
int day = calCurrentTick.get(Calendar.DAY_OF_MONTH);
int hour = calCurrentTick.get(Calendar.HOUR_OF_DAY);
int minute = calCurrentTick.get(Calendar.MINUTE);
int second = calCurrentTick.get(Calendar.SECOND);
if(year == 2014 && month == 1 && day == 29 && hour == 23 && minute == 01 && second > 55 )
{
print("hour: " + Integer.toString(hour) + " : minute tick " + Integer.toString( minute) + " second=" + second );
}
}
Full code is available in attachment.
But sadly print is not executed at all.
N.B. Please don't propose for me to use onTick because ticks doesn't happen EVERY second. If to look in tick history sometime it happens that last tick of the minute was at 22 second especially in expectation of some news, but I need some specific way to execute trade at some specific date time. Specific till second. For example as in code
2014-01-29 23:01:55