Ejemplo n.º 1
0
        public static IBSocket SendCombo(this IBSocket socket, WeightedIndexSecurity security, IBOrderCondition condition = null)
        {
            if (security == null)
            {
                throw new ArgumentNullException(nameof(security));
            }

            var innerSecurities = security.InnerSecurities.ToArray();

            socket.Send(innerSecurities.Length);

            foreach (var innerSecurity in innerSecurities)
            {
                var weight = security.Weights[innerSecurity];

                socket
                .SendContractId(innerSecurity.ToSecurityId())
                .Send((int)weight.Abs())
                .SendSide(weight >= 0 ? Sides.Buy : Sides.Sell)
                .SendBoardCode(innerSecurity.Board.Code);

                if (condition == null)
                {
                    continue;
                }

                var shortSale = condition.Combo.ShortSales[innerSecurity.ToSecurityId()];

                socket
                .Send(shortSale.IsOpenOrClose)
                .SendShortSale(shortSale, true);
            }

            return(socket);
        }