2013年9月23日月曜日

Client action on order fill and close

Client action on order fill and close
オーダー記入とクローズする上でのクライアントアクション

Consider that from the program you wish to do some extra logging on both order fill and close.
オーダー記入とクローズの両方において、拡張的ロギングが必要ならば、プログラム上で行うことを検討して欲しい。
And also you wish to set order stop loss:
また、あなたはストップロスオーダーを望むだろう:
client.startStrategy(new StrategyPublicMethods(new StrategyPublicMethods.ClientActions() {
                       
    @Override
    public void onOrderFill(IOrder order) {
        LOGGER.info("Order filled, execute here some logic on client side, say set stop loss if the order is long");
        if(order.isLong()){
            try {
                order.setStopLossPrice(order.getOpenPrice() - order.getInstrument().getPipValue() * 10);
            } catch (JFException e) {
                e.printStackTrace();
            }
        }
    }
                       
    @Override
    public void onOrderClose(IOrder order) {
        LOGGER.info("Order closed, execute here some logic on client side");                                  
    }
}));
Consider introducing an interface in a strategy which would serve as an order fill and close listener.
オーダー記入とクローズの助けとして、ストラテジの中でインタフェイスの導入を検討して欲しい。
Implementation of the interface would get passed from the IClient program:
インタフェイスの実装はIClientプログラムから渡されるだろう。
public class StrategyPublicMethods implements IStrategy {
       
    private IConsole console;
    private IEngine engine;
    private StrategyPublicMethods.ClientActions clientActions;
   
    public interface ClientActions {
        void onOrderClose(IOrder order);
        void onOrderFill(IOrder order);
    }
   
    //for the launch from standalone
    public StrategyPublicMethods (StrategyPublicMethods.ClientActions clientActions){
        this.clientActions = clientActions;
    }

    //...
}
Then on every order fill and close execute the logic that has been passed from the IClient program:
そして、全てのオーダー記入とクローズ時、IClientプログラムから渡されたロジックが実行される。 
@Override
public void onMessage(IMessage message) throws JFException {
    if(message.getType() == IMessage.Type.ORDER_FILL_OK){
        clientActions.onOrderFill(message.getOrder());
    }
    if(message.getType() == IMessage.Type.ORDER_CLOSE_OK){
        clientActions.onOrderClose(message.getOrder());
    }
}

0 件のコメント:

コメントを投稿