ReadBarsExample.java

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



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

import com.dukascopy.api.*;

/**
 Dmitry Shohov氏作成のサンプルソース
 readBarsメソッドでバーデータロードのリスナー設定を行い、そのままreadBarsメソッドから抜け、
 リスナーがバーデータのロード処理とロード完了チェックを行う。
*/
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 {    }
}






スポンサーリンク

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


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


Top

inserted by FC2 system