Esempio n. 1
0
        internal TickOptionComputation(ResponseComposer c)
        {
            var version = c.GetVersion();

            RequestId         = c.ReadInt();
            TickType          = c.ReadEnum <TickType>();
            ImpliedVolatility = c.ReadDoubleNullable();
            if (ImpliedVolatility == -1)
            {
                ImpliedVolatility = null;
            }

            Delta = c.ReadDoubleNullable();
            if (Delta == -2)
            {
                Delta = null;
            }

            if (version >= 6 || TickType == TickType.ModelOptionComputation || TickType == TickType.DelayedModelOption)
            {
                OptPrice = c.ReadDoubleNullable();
                if (OptPrice == -1)
                {
                    OptPrice = null;
                }
                PvDividend = c.ReadDoubleNullable();
                if (PvDividend == -1)
                {
                    PvDividend = null;
                }
            }
            if (version >= 6)
            {
                Gamma = c.ReadDoubleNullable();
                if (Gamma == -2)
                {
                    Gamma = null;
                }
                Vega = c.ReadDoubleNullable();
                if (Vega == -2)
                {
                    Vega = null;
                }
                Theta = c.ReadDoubleNullable();
                if (Theta == -2)
                {
                    Theta = null;
                }
                UndPrice = c.ReadDoubleNullable();
                if (UndPrice == -1)
                {
                    UndPrice = null;
                }
            }
        }
Esempio n. 2
0
        internal OpenOrder(ResponseComposer c) // the monster
        {
            var serverVersion  = c.Config.ServerVersionCurrent;
            var messageVersion = serverVersion < ServerVersion.OrderContainer ? c.RequireVersion(17) : (int)serverVersion;
            var orderId        = c.ReadInt();

            Contract = new Contract
            {
                ContractId   = c.ReadInt(),
                Symbol       = c.ReadString(),
                SecurityType = c.ReadStringEnum <SecurityType>(),
                LastTradeDateOrContractMonth = c.ReadString(),
                Strike       = c.ReadDouble(),
                Right        = c.ReadStringEnum <RightType>(),
                Multiplier   = messageVersion >= 32 ? c.ReadString() : string.Empty,
                Exchange     = c.ReadString(),
                Currency     = c.ReadString(),
                LocalSymbol  = c.ReadString(),
                TradingClass = messageVersion >= 32 ? c.ReadString() : string.Empty
            };
            Order = new Order
            {
                OrderId       = orderId,
                TradeAction   = c.ReadStringEnum <TradeAction>(),
                TotalQuantity = c.ReadDouble(),
                OrderType     = c.ReadStringEnum <OrderType>(),
                LimitPrice    = messageVersion < 29 ? c.ReadDouble() : c.ReadDoubleNullable(),
                AuxPrice      = messageVersion < 30 ? c.ReadDouble() : c.ReadDoubleNullable(),
                TimeInForce   = c.ReadStringEnum <TimeInForce>(),
                OcaGroup      = c.ReadString(),
                Account       = c.ReadString(),
                OpenClose     = c.ReadStringEnum <OrderOpenClose>(),
                Origin        = c.ReadEnum <OrderOrigin>(),
                OrderRef      = c.ReadString(),
                ClientId      = c.ReadInt(),
                PermanentId   = c.ReadInt(),
                OutsideRegularTradingHours = c.ReadBool(),
                Hidden = c.ReadBool(),
                DiscretionaryAmount = c.ReadDouble(),
                GoodAfterTime       = c.ReadString()
            };

            OrderId = Order.OrderId;

            c.ReadString(); // skip deprecated sharesAllocation field

            Order.FinancialAdvisorGroup      = c.ReadString();
            Order.FinancialAdvisorMethod     = c.ReadStringEnum <FinancialAdvisorAllocationMethod>();
            Order.FinancialAdvisorPercentage = c.ReadString();
            Order.FinancialAdvisorProfile    = c.ReadString();

            if (c.Config.SupportsServerVersion(ServerVersion.ModelsSupport))
            {
                Order.ModelCode = c.ReadString();
            }

            Order.GoodUntilDate       = c.ReadString();
            Order.Rule80A             = c.ReadStringEnum <AgentDescription>();
            Order.PercentOffset       = c.ReadDoubleNullable();
            Order.SettlingFirm        = c.ReadString();
            Order.ShortSaleSlot       = c.ReadEnum <ShortSaleSlot>();
            Order.DesignatedLocation  = c.ReadString();
            Order.ExemptCode          = c.ReadInt();
            Order.AuctionStrategy     = c.ReadEnum <AuctionStrategy>();
            Order.StartingPrice       = c.ReadDoubleNullable();
            Order.StockReferencePrice = c.ReadDoubleNullable();
            Order.Delta           = c.ReadDoubleNullable();
            Order.StockRangeLower = c.ReadDoubleNullable();
            Order.StockRangeUpper = c.ReadDoubleNullable();
            Order.DisplaySize     = c.ReadInt();

            Order.BlockOrder          = c.ReadBool();
            Order.SweepToFill         = c.ReadBool();
            Order.AllOrNone           = c.ReadBool();
            Order.MinimumQuantity     = c.ReadIntNullable();
            Order.OcaType             = c.ReadEnum <OcaType>();
            Order.ElectronicTradeOnly = c.ReadBool();
            Order.FirmQuoteOnly       = c.ReadBool();
            Order.NbboPriceCap        = c.ReadDoubleNullable();

            Order.ParentId      = c.ReadInt();
            Order.TriggerMethod = c.ReadEnum <TriggerMethod>();

            Order.Volatility     = c.ReadDoubleNullable();
            Order.VolatilityType = c.ReadEnum <VolatilityType>();

            Order.DeltaNeutralOrderType = c.ReadString();
            Order.DeltaNeutralAuxPrice  = c.ReadDoubleNullable();

            if (!string.IsNullOrEmpty(Order.DeltaNeutralOrderType))
            {
                if (messageVersion >= 27)
                {
                    Order.DeltaNeutralContractId      = c.ReadInt();
                    Order.DeltaNeutralSettlingFirm    = c.ReadString();
                    Order.DeltaNeutralClearingAccount = c.ReadString();
                    Order.DeltaNeutralClearingIntent  = c.ReadString();
                }
                if (messageVersion >= 31)
                {
                    Order.DeltaNeutralOpenClose          = c.ReadString();
                    Order.DeltaNeutralShortSale          = c.ReadBool();
                    Order.DeltaNeutralShortSaleSlot      = c.ReadInt();
                    Order.DeltaNeutralDesignatedLocation = c.ReadString();
                }
            }

            Order.ContinuousUpdate   = c.ReadInt();
            Order.ReferencePriceType = c.ReadEnum <ReferencePriceType>();

            Order.TrailingStopPrice = c.ReadDoubleNullable();
            if (messageVersion >= 30)
            {
                Order.TrailingStopPercent = c.ReadDoubleNullable();
            }

            Order.BasisPoints             = c.ReadDoubleNullable();
            Order.BasisPointsType         = c.ReadIntNullable();
            Contract.ComboLegsDescription = c.ReadString();

            if (messageVersion >= 29)
            {
                var n = c.ReadInt();
                for (var i = 0; i < n; i++)
                {
                    Contract.ComboLegs.Add(new ContractComboLeg(c));
                }

                n = c.ReadInt();
                for (var i = 0; i < n; i++)
                {
                    Order.ComboLegs.Add(new OrderComboLeg(c.ReadDoubleNullable()));
                }
            }

            if (messageVersion >= 26)
            {
                c.AddTagsToList(Order.SmartComboRoutingParams);
            }

            if (messageVersion >= 15)
            {
                if (messageVersion >= 20)
                {
                    Order.ScaleInitLevelSize = c.ReadIntNullable();
                    Order.ScaleSubsLevelSize = c.ReadIntNullable();
                }
                else
                {
                    c.ReadString();
                    Order.ScaleInitLevelSize = c.ReadIntNullable();
                }
                Order.ScalePriceIncrement = c.ReadDoubleNullable();
            }

            if (messageVersion >= 28 && Order.ScalePriceIncrement > 0)
            {
                Order.ScalePriceAdjustValue    = c.ReadDoubleNullable();
                Order.ScalePriceAdjustInterval = c.ReadIntNullable();
                Order.ScaleProfitOffset        = c.ReadDoubleNullable();
                Order.ScaleAutoReset           = c.ReadBool();
                Order.ScaleInitPosition        = c.ReadIntNullable();
                Order.ScaleInitFillQty         = c.ReadIntNullable();
                Order.ScaleRandomPercent       = c.ReadBool();
            }

            if (messageVersion >= 24)
            {
                Order.HedgeType = c.ReadStringEnum <HedgeType>();
                if (Order.HedgeType != HedgeType.Undefined)
                {
                    Order.HedgeParam = c.ReadString();
                }
            }

            if (messageVersion >= 25)
            {
                Order.OptOutSmartRouting = c.ReadBool();
            }

            if (messageVersion >= 19)
            {
                Order.ClearingAccount = c.ReadString();
                Order.ClearingIntent  = c.ReadStringEnum <ClearingIntent>();
            }

            if (messageVersion >= 22)
            {
                Order.NotHeld = c.ReadBool();
            }

            if (messageVersion >= 20 && c.ReadBool())
            {
                Contract.DeltaNeutralContract = new DeltaNeutralContract(c, false);
            }

            if (messageVersion >= 21)
            {
                Order.AlgoStrategy = c.ReadString();
                if (!string.IsNullOrEmpty(Order.AlgoStrategy))
                {
                    c.AddTagsToList(Order.AlgoParams);
                }
            }

            if (messageVersion >= 33)
            {
                Order.Solicited = c.ReadBool();
            }

            Order.WhatIf = c.ReadBool();
            Status       = c.ReadStringEnum <OrderStatus>();

            if (serverVersion >= ServerVersion.WhatIfExtFields)
            {
                InitialMarginBefore     = c.ReadString();
                MaintenanceMarginBefore = c.ReadString();
                EquityWithLoanBefore    = c.ReadString();
                InitMarginChange        = c.ReadString();
                MaintMarginChange       = c.ReadString();
                EquityWithLoanChange    = c.ReadString();
            }
            InitMarginAfter      = c.ReadString();
            MaintMarginAfter     = c.ReadString();
            EquityWithLoanBefore = c.ReadString();
            Commission           = c.ReadDoubleNullable();
            MinimumCommission    = c.ReadDoubleNullable();
            MaximumCommission    = c.ReadDoubleNullable();
            CommissionCurrency   = c.ReadString();
            WarningText          = c.ReadString();

            if (messageVersion >= 34)
            {
                Order.RandomizeSize  = c.ReadBool();
                Order.RandomizePrice = c.ReadBool();
            }

            if (c.Config.SupportsServerVersion(ServerVersion.PeggedToBenchmark))
            {
                if (Order.OrderType == OrderType.PeggedToBenchmark)
                {
                    Order.ReferenceContractId          = c.ReadInt();
                    Order.IsPeggedChangeAmountDecrease = c.ReadBool();
                    Order.PeggedChangeAmount           = c.ReadDoubleNullable();
                    Order.ReferenceChangeAmount        = c.ReadDoubleNullable();
                    Order.ReferenceExchange            = c.ReadString();
                }

                var n = c.ReadInt();
                if (n > 0)
                {
                    for (var i = 0; i < n; i++)
                    {
                        var orderConditionType = c.ReadEnum <OrderConditionType>();
                        var condition          = OrderCondition.Create(orderConditionType);
                        condition.Deserialize(c);
                        Order.Conditions.Add(condition);
                    }
                    Order.ConditionsIgnoreRegularTradingHours = c.ReadBool();
                    Order.ConditionsCancelOrder = c.ReadBool();
                }

                Order.AdjustedOrderType      = c.ReadString();
                Order.TriggerPrice           = c.ReadDoubleNullable();
                Order.TrailingStopPrice      = c.ReadDoubleNullable();
                Order.LmtPriceOffset         = c.ReadDoubleNullable();
                Order.AdjustedStopPrice      = c.ReadDoubleNullable();
                Order.AdjustedStopLimitPrice = c.ReadDoubleNullable();
                Order.AdjustedTrailingAmount = c.ReadDoubleNullable();
                Order.AdjustableTrailingUnit = c.ReadInt();
            }

            if (c.Config.SupportsServerVersion(ServerVersion.SoftDollarTier))
            {
                Order.SoftDollarTier = new SoftDollarTier(c);
            }

            if (c.Config.SupportsServerVersion(ServerVersion.CashQty))
            {
                Order.CashQty = c.ReadDoubleNullable();
            }

            if (c.Config.SupportsServerVersion(ServerVersion.AutoPriceForHedge))
            {
                Order.DontUseAutoPriceForHedge = c.ReadBool();
            }

            if (c.Config.SupportsServerVersion(ServerVersion.OrderContainer))
            {
                Order.IsOmsContainer = c.ReadBool();
            }

            if (c.Config.SupportsServerVersion(ServerVersion.DPegOrders))
            {
                Order.DiscretionaryUpToLimitPrice = c.ReadBool();
            }
        }