MarketIsOffline.java

注意事項:
サンプルソースコードには実際にオーダーを発注するものがあります。
サンプルソースコードのストラテジーを起動する場合は、注意して下さい。



// Copyright (c) 2009 Dukascopy (Suisse) SA. All Rights Reserved.
package jforex.dataservice;

import java.text.SimpleDateFormat;
import java.util.Set;
import java.util.TimeZone;

import com.dukascopy.api.*;

/**
 過去7日前から7日後でマーケットクローズしている時間をチェックします
 */
public class MarketIsOffline implements IStrategy {
        
    private IDataService dataService;
    private IHistory history;
    private IConsole console;
    
    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");    

    @Override
    public void onStart(IContext context) throws JFException {
        dataService = context.getDataService();
        history = context.getHistory();
        console = context.getConsole();
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        
        long lastTickTime = history.getLastTick(Instrument.EURUSD).getTime();
        // 7日前から7日後までをチェック
        for(int i = -7; i < 7; i++){
            long time = lastTickTime + Period.DAILY.getInterval() * i;
            console.getOut().println(sdf.format(time) + " マーケットクローズ判定=" + isOffline(time));
        }
    }
    
    private boolean isOffline(long time) throws JFException{
        Set<ITimeDomain> offlines = dataService.getOfflineTimeDomains(time - Period.WEEKLY.getInterval(),
                                                                      time + Period.WEEKLY.getInterval());

        for(ITimeDomain offline : offlines){
            if( time > offline.getStart() &&  time < offline.getEnd()){
                return true;
            }
        }
        return false;
    }

    @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 {}
}






スポンサーリンク

スポンサーリンク
検索
リファレンスツリー


Copyright ©2016 JForexAPIで自動売買させ隊! All Rights Reserved.


Top

inserted by FC2 system