Ejemplo n.º 1
0
 /// <summary>
 /// Send a pendingorder to a sepcific account
 /// </summary>
 /// <param name="order"></param>
 /// <param name="account"></param>
 public PendingOrderImpl(OrderImpl order, IAccount account)
 {
     _order  = order;
     Account = account;
 }
Ejemplo n.º 2
0
        public PendingOrder CreateOrder(string symbol, Direction direction, decimal quantity, decimal limitPrice, decimal stopPrice, string comment, int agentid)
        {
            //Order creation logic
            ISecurity security = _portfolio.Securities[symbol];

            //Pre-Check flatten order
            //Create a market flat order
            if (direction == Direction.Flat)
            {
                var position = _portfolio.Positions[security];
                if (!position.IsFlat)
                {
                    quantity = (decimal)position.FlatSize / (decimal)security.LotSize;
                }
                if (position.IsLong || _portfolio.TradingAgents.First(x => x.AgentId == agentid).CurrentState[symbol].TrueForAll(x => x == AgentState.EntryLong))
                {
                    direction = Direction.Short;
                }
                else if (position.IsShort || _portfolio.TradingAgents.First(x => x.AgentId == agentid).CurrentState[symbol].TrueForAll(x => x == AgentState.EntryShort))
                {
                    direction = Direction.Long;
                }
            }

            //Set initial objects
            OrderImpl norder = new OrderImpl(security, direction, quantity, limitPrice, stopPrice, comment)
            {
                AgentId       = agentid,
                ValidInstruct = OrderInstructionType.GTC
            };

            var toreturn = new PendingOrderImpl(norder, _portfolio.Account)
            {
                OrderStatus = security == null ? StatusType.SYMBOL_NOT_LOADED : StatusType.OK
            };

            //Check for security

            //Check order action and sizing
            norder.Quantity = quantity;
            if (direction != Direction.Short && quantity < 0)
            {
                toreturn.OrderStatus = StatusType.ORDER_INVALID_VOLUME;
                toreturn.Cancel();
            }

            //Check order size is positive
            if (quantity == 0)
            {
                toreturn.OrderStatus = StatusType.ORDER_INVALID_VOLUME;
                toreturn.Cancel();
            }

            //Check order quantity stepsize
            if (norder.Quantity % norder.Security.OrderStepQuantity > 0)
            {
                toreturn.OrderStatus = StatusType.ORDER_INVALID_VOLUME;
                toreturn.Cancel();
            }

            //Check order minimum size
            if (norder.UnsignedSize < norder.Security.OrderMinSize)
            {
                toreturn.OrderStatus = StatusType.ORDER_INVALID_VOLUME;
                toreturn.Cancel();
            }

            //Check order type
            //Set Order Limit Price
            if (limitPrice >= 0)
            {
                norder.LimitPrice = limitPrice;
            }
            else
            {
                toreturn.OrderStatus = StatusType.ORDER_INVALID_PRICE;
                toreturn.Cancel();
            }

            //Create a stop order
            if (stopPrice >= 0)
            {
                norder.StopPrice = stopPrice;
            }
            else
            {
                toreturn.OrderStatus = StatusType.ORDER_INVALID_STOP;
                toreturn.Cancel();
            }

            //Return the newly created, pending state order
            return(toreturn);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a new pending order, based on the requested order object
 /// </summary>
 /// <param name="order"></param>
 public PendingOrderImpl(OrderImpl order)
 {
     _order = order;
 }