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

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



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

import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.util.DateUtils;

/**
 このストラテジーは起動時に成行オーダー送信し、オーダー更新に関する情報をログ出力します。
 */
public class TestWaitForUpdate implements IStrategy {
    private IEngine engine;
    private IConsole console;    
    
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        context.setSubscribedInstruments(java.util.Collections.singleton(Instrument.EURUSD), true);
        
        IOrder order = engine.submitOrder("orderValid", Instrument.EURUSD, OrderCommand.BUY, 0.001);
        print(String.format("オーダー送信後: オーダー状態=%s, オープン価格=%.5f, オーダー作成時間=%s",
                order.getState(), order.getOpenPrice(), DateUtils.format(order.getCreationTime())));
        
        order.waitForUpdate(2000); // オーダー状態OPENED待ちの為の2秒待ち
        print(String.format("オーダー状態更新後(OPENED): オーダー状態=%s, オープン価格=%.5f, オーダー作成時間=%s",
                order.getState(), order.getOpenPrice(), DateUtils.format(order.getCreationTime())));
        
        order.waitForUpdate(2000); // オーダー状態FILLED待ちの為の2秒待ち
        print(String.format("オーダー状態更新後(FILLED): オーダー状態=%s, オープン価格=%.5f, 約定時間=%s",
                order.getState(),order.getOpenPrice(), DateUtils.format(order.getFillTime())));
         
    }

    public void onMessage(IMessage message) throws JFException {  
        print("<html><font color=\"gray\">"+message+"</font>");
    }
    
    public void print(Object message) {
        console.getOut().println(message);
    }

    // ストラテジー停止時に全オーダークローズ
    public void onStop() throws JFException {
        for (IOrder order : engine.getOrders()) {
            order.close();
        }
    }    

    public void onAccount(IAccount account) 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