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

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



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

import com.dukascopy.api.*;

/**
 このストラテジーは最初にBUYSTOPの条件付きオーダーを送信します。 After the order has
 オーダー状態がOPENEDになった後に、取引数量とエントリー価格を変更します。
*/
public class ModifyLimitOrderWithMessages implements IStrategy {

    private IConsole console;
    private IEngine engine;
    private IHistory history;    

    private IOrder order;
    
    @Override
    public void onStart(IContext context) throws JFException {
        engine = context.getEngine();
        console = context.getConsole();
        history = context.getHistory();
        context.setSubscribedInstruments(java.util.Collections.singleton(Instrument.EURUSD), true);
        
        ITick tick = history.getLastTick(Instrument.EURUSD);
        
        double openPrice = tick.getBid() + 0.0010;
        double slippage = 1;

        order = engine.submitOrder("order1" , Instrument.EURUSD, IEngine.OrderCommand.BUYSTOP, 0.01, openPrice, slippage, 0, 0);
        console.getOut().println(String.format("%s, 取引数量=%s, エントリー価格=%s",
                                 order.getLabel(), order.getAmount(), order.getOpenPrice()));
        order.waitForUpdate(2000, IOrder.State.OPENED); // IOrder.State.OPENED遷移待ち
        
        // エントリー価格の変更
        order.setOpenPrice(openPrice + 0.0010);
        order.waitForUpdate(2000); // 変更待ち
        console.getOut().println(String.format("%s, 取引数量=%s, エントリー価格=%s",
                                 order.getLabel(), order.getAmount(), order.getOpenPrice()));
        
        // 取引数量の変更
        order.setRequestedAmount(0.02);        
        order.waitForUpdate(2000); // 変更待ち
        console.getOut().println(String.format("%s, 取引数量=%s, エントリー価格=%s",
                                 order.getLabel(), order.getAmount(), order.getOpenPrice()));    
        order.setRequestedAmount(0.03);   
        order.setRequestedAmount(0.04);  
    }

    @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 {
        console.getOut().println(message);
    }

    @Override
    public void onAccount(IAccount account) throws JFException {}

    @Override
    public void onStop() throws JFException {
        for(IOrder o : engine.getOrders())
            o.close();
    }

}






スポンサーリンク

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


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


Top

inserted by FC2 system