トップ  >  リファレンス  >  サンプルソースコード  >  ストラテジーAPI  >  PositionPLandAmount.java
PositionPLandAmount.java

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



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

import com.dukascopy.api.*;

/**
 ストラテジー起動時に各通貨ペア毎の損益とポジションの集計結果をログ出力します。
 */
public class PositionPLandAmount implements IStrategy {

    private IEngine engine;
    private IConsole console;
    
    @Override
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        for(Instrument instrument : context.getSubscribedInstruments()){
            double profitLoss = 0;
            double amount = 0;
            int filledOrders = 0;
            for (IOrder order : engine.getOrders(instrument)) {
                if (order.getState() == IOrder.State.FILLED){
                    profitLoss += order.getProfitLossInUSD();
                    amount += order.isLong() ? order.getAmount() : -order.getAmount();
                    filledOrders++;
                }
            }
            if(filledOrders > 0){
                console.getOut().format("%s 損益合計 = $%.5f, ポジション合計 = %.5f", instrument ,profitLoss, amount).println();
            }
        }
        context.stop(); // ストラテジー停止
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {}   
    public void onMessage(IMessage message) throws JFException {}
    public void onAccount(IAccount account) throws JFException {}
    public void onStop() 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