Package com.collective2.signalEntry.adapter.dynamicSimulator.quantity

Source Code of com.collective2.signalEntry.adapter.dynamicSimulator.quantity.QuantityFactory

package com.collective2.signalEntry.adapter.dynamicSimulator.quantity;

import com.collective2.signalEntry.C2ServiceException;
import com.collective2.signalEntry.Parameter;
import com.collective2.signalEntry.adapter.dynamicSimulator.SystemManager;
import com.collective2.signalEntry.implementation.Request;

/**
* This notice shall not be removed.
* See the "LICENSE.txt" file found in the root folder
* for the full license governing this code.
* Nathan Tippy  7/30/12
*/

public class QuantityFactory {

    public QuantityComputable computable(Request request, SystemManager systemManager) {
        //Dollars, Quantity, AccountPercent

        Integer quantity = (Integer)request.get(Parameter.Quantity);
        if (quantity != null) {
            return new QuantityComputableFixed(quantity);
        }
        Number dollars = (Number)request.get(Parameter.Dollars);
        if (dollars != null) {
            return new QuantityComputableDollars(dollars);
        }
        Number percent = (Number)request.get(Parameter.AccountPercent);
        if (percent != null) {
            return new QuantityComputablePercent(percent, systemManager.portfolio());
        }

        //part of all-in-one signal where we need to close out the same sized position we opened
        Integer condUpon = (Integer)request.get(Parameter.ConditionalUpon);
        if (condUpon != null) {
            return new QuantityComputableEntry(systemManager.lookupOrder(condUpon));
        }

        throw new C2ServiceException("Unable to determine how to calculate quantity. "+request,false);

    }


}
TOP

Related Classes of com.collective2.signalEntry.adapter.dynamicSimulator.quantity.QuantityFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.