示例#1
0
        private void FillPairs(
            GooOperation operation,
            ICollection <GooOperationPair> instrumentPairs,
            GooDealCompleteStrategy dealCompleteStrategy)
        {
            var isBuy = operation.OperationType == GooOperationType.Buy;

            bool Predicate(GooOperationPair pair) => isBuy
                ? pair.Sell != null && pair.Buy == null
                : pair.Buy != null && pair.Sell == null;

            var activePairs = instrumentPairs.Where(Predicate);

            var orderedActivePairs = SortActivePairs(isBuy, activePairs, dealCompleteStrategy);

            foreach (var activePair in orderedActivePairs)
            {
                if (operation.Quantity == 0)
                {
                    break;
                }

                if (operation.Quantity < activePair.Quantity)
                {
                    var pairOperation     = isBuy ? activePair.Sell : activePair.Buy;
                    var splittedOperation = pairOperation.Split(pairOperation.Quantity - operation.Quantity);

                    if (isBuy)
                    {
                        activePair.Buy = operation;
                    }
                    else
                    {
                        activePair.Sell = operation;
                    }

                    var newwPair = new GooOperationPair();
                    if (isBuy)
                    {
                        newwPair.Sell = splittedOperation;
                    }
                    else
                    {
                        newwPair.Buy = splittedOperation;
                    }

                    instrumentPairs.Add(newwPair);

                    return;
                }

                var splitOp = operation.Split(activePair.Quantity);

                if (isBuy)
                {
                    activePair.Buy = splitOp;
                }
                else
                {
                    activePair.Sell = splitOp;
                }
            }

            if (operation.Quantity == 0)
            {
                return;
            }

            var newPair = new GooOperationPair();

            if (isBuy)
            {
                newPair.Buy = operation;
            }
            else
            {
                newPair.Sell = operation;
            }

            instrumentPairs.Add(newPair);
        }
示例#2
0
 public IncompleteDealItem(GooOperationPair pair) : base(pair)
 {
 }