PipConvertTest3.java

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



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

import java.util.Arrays;
import java.util.Currency;
import java.util.HashSet;
import java.util.Set;

import com.dukascopy.api.*;

/**
 JFUtils.convertPipToCurrency関数を使用してピップコスト変換を行います。

 このストラテジーは以下のセットを使用します。
  - instruments(通貨ペア)のセット 
  - currencies(現在通貨)のセット

 上記セットから、各現在通貨の各通貨ペアのピップ値を算出し、
 各通貨ペアのピップ値とレートと反転レートをログ出力します。
 */
public class PipConvertTest3 implements IStrategy {
    private IConsole console;    
    private JFUtils utils;
    
    private final Set<Currency> currencies = new HashSet<Currency>(Arrays.asList(new Currency[] {
            Currency.getInstance("JPY"),
            Currency.getInstance("USD"),
            Currency.getInstance("EUR")
    }));
    
    private final Set<Instrument> instruments = new HashSet<Instrument>(Arrays.asList(new Instrument[] {
            Instrument.EURJPY,
            Instrument.EURUSD,
            Instrument.USDJPY
    }));
    
    public void onStart(IContext context) throws JFException {
        this.console = context.getConsole();
        this.utils = context.getUtils();

        context.setSubscribedInstruments(instruments);

        // 通貨ペア登録待ち(最大1sec)
        int i = 10;
        while (!context.getSubscribedInstruments().containsAll(instruments)) {
            try {
                console.getOut().println("通貨ペアがまだ銘柄登録されていません" + i);
                Thread.sleep(100);
            } catch (InterruptedException e) {
                console.getOut().println(e.getMessage());
            }
            i--;
        }
        
        // 複数変換
        for (Instrument instrument : instruments) {
            for (Currency currency : currencies) {
                try {
                    double pipValue = utils.convertPipToCurrency(instrument, currency, null);
                    print("%s -> %s, pip値= %.8f (%s/%s レート: %.8f, 反転レート: %.8f)",
                            instrument, currency, pipValue, 
                            instrument.getSecondaryCurrency(), currency, 
                            pipValue / instrument.getPipValue(), (1/pipValue * instrument.getPipValue()));
                } catch (JFException e) {
                    console.getErr().println(String.format("%s->%s 変換エラー: %s", instrument, currency, e));
                }
            }
        }

        context.stop();
    }
    
    private void print(String format, Object...args){
        print(String.format(format, args));
    }

    private void print(Object message) {
        console.getOut().println(message);
    }

    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 {}
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {    }
}






スポンサーリンク

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


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


Top

inserted by FC2 system