Exemplo n.º 1
0
        protected IPosition GetExisitingPosition(IOrder order)
        {
            var key = PositionKey.Create(order.Portfolio, order.SecurityMasterId);
            var existingPosition = this.positionService.GetPositionByKey(key);

            return(existingPosition);
        }
Exemplo n.º 2
0
        private void ProcessBuyOrder(IOrder order, PositionKey key)
        {
            IPosition position;

            if (this.positions.TryGetValue(key, out position))
            {
                var pos = this.CreatePositionFromSource(position);
                pos.AvgPrice = ((position.AvgPrice * position.Quantity) + (order.Quantity * order.Price)) / (order.Quantity + position.Quantity);
                if (position.IsShort)
                {
                    pos.IsShort  = position.Quantity > order.Quantity;
                    pos.Quantity = Math.Abs(position.Quantity - order.Quantity);
                }
                else
                {
                    pos.IsShort   = false;
                    pos.Quantity += order.Quantity;
                }

                this.positions[key] = pos;
            }
            else
            {
                position = this.ToPosition(order);
                this.positions.Add(key, position);
            }
        }
Exemplo n.º 3
0
        public IPosition GetPositionByKey(PositionKey key)
        {
            IPosition result;

            if (this.positions.TryGetValue(key, out result))
            {
                return(result);
            }

            return(null);
        }
Exemplo n.º 4
0
        public void SubmitOrder(IOrder order)
        {
            if (order == null)
            {
                return;
            }

            var key = PositionKey.Create(order.Portfolio, order.SecurityMasterId);

            switch (order.OrderType)
            {
            case OrderType.Buy:
                this.ProcessBuyOrder(order, key);
                break;

            case OrderType.Sell:
                this.ProcessSellOrder(order, key);
                break;
            }
        }