FeedHistory.java

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



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

import java.util.List;
import java.util.concurrent.TimeUnit;

import com.dukascopy.api.*;
import com.dukascopy.api.feed.*;
import com.dukascopy.api.feed.util.*;
import com.dukascopy.api.util.DateUtils;


public class FeedHistory implements IStrategy, IFeedListener {

    private IConsole console;
    private IHistory history;
    int dataCount = 0;

    @Configurable(value = "フィードタイプ", description = "choose any type of feed (except ticks) in the strategy parameters dialog")
    public IFeedDescriptor feedDescriptor = new RangeBarFeedDescriptor(Instrument.EURUSD, PriceRange.TWO_PIPS, OfferSide.ASK);    

    @Override
    public void onStart(final IContext context) throws JFException {

        history = context.getHistory();
        console = context.getConsole();

        context.setSubscribedInstruments(java.util.Collections.singleton(feedDescriptor.getInstrument()), true);
        // フィードキャッシュ(ヒストリーメソッドパフォーマンス)を有効にする為の重要な登録
        context.subscribeToFeed(feedDescriptor, this); 
        
        ITimedData lastFeedData = history.getFeedData(feedDescriptor, 0); // フィード形式での最新のデータ
        List<ITimedData> feedDataList = history.getFeedData(feedDescriptor, 3, lastFeedData.getTime(), 0);

        console.getOut().format("フィードタイプ:%s 最新のデータ=%s \n 3つ前のデータ=%s", 
                feedDescriptor.getDataType(), lastFeedData, feedDataList).println();
        

       final long from = lastFeedData.getTime() - TimeUnit.DAYS.toMillis(1);
       final long to   = lastFeedData.getTime();

        history.readFeedData(
               feedDescriptor,
               from,
               to, 

               new IFeedListener(){
                   @Override
   
                   public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) {
                       dataCount++;
                   }
               }, 

               new LoadingProgressListener(){
                   @Override
                   public void dataLoaded(long start, long end, long currentPosition, String information) {
                   }
   
                   @Override
                   public void loadingFinished(boolean allDataLoaded, long start, long end, long currentPosition) {
                       if(allDataLoaded){
                           console.getOut().format("取得期間:%s 〜 %s、 ロード件数:%s、 %sフィードでのロード完了", 
                                   DateUtils.format(from), DateUtils.format(to), dataCount, feedDescriptor.getDataType()).println();
                           context.stop();
                       }
                   }
   
                   @Override
                   public boolean stopJob() {
                       return false;
                   }
               }
        );

    }

    @Override
    public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) {}

    @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