Esempio n. 1
0
 internal PortfolioValue(ResponseComposer c)
 {
     c.RequireVersion(8);
     Contract = new Contract
     {
         ContractId   = c.ReadInt(),
         Symbol       = c.ReadString(),
         SecurityType = c.ReadStringEnum <SecurityType>(),
         LastTradeDateOrContractMonth = c.ReadString(),
         Strike          = c.ReadDouble(),
         Right           = c.ReadStringEnum <RightType>(),
         Multiplier      = c.ReadString(),
         PrimaryExchange = c.ReadString(),
         Currency        = c.ReadString(),
         LocalSymbol     = c.ReadString(),
         TradingClass    = c.ReadString()
     };
     Position      = c.ReadDouble();
     MarketPrice   = c.ReadDouble();
     MarketValue   = c.ReadDouble();
     AverageCost   = c.ReadDouble();
     UnrealizedPnl = c.ReadDouble();
     RealizedPnl   = c.ReadDouble();
     Account       = c.ReadString();
 }
Esempio n. 2
0
        internal Execution(ResponseComposer c)
        {
            if (!c.Config.SupportsServerVersion(ServerVersion.LastLiqidity))
            {
                c.RequireVersion(10);
            }
            var requestId = c.ReadInt();
            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   = c.ReadString(),
                Exchange     = c.ReadString(),
                Currency     = c.ReadString(),
                LocalSymbol  = c.ReadString(),
                TradingClass = c.ReadString()
            };
            RequestId               = requestId;
            OrderId                 = orderId;
            ExecutionId             = c.ReadString();
            Time                    = c.ReadString();
            Account                 = c.ReadString();
            Exchange                = c.ReadString();
            Side                    = c.ReadStringEnum <ExecutionSide>();
            Shares                  = c.ReadDouble();
            Price                   = c.ReadDouble();
            PermanentId             = c.ReadInt();
            ClientId                = c.ReadInt();
            Liquidation             = c.ReadInt();
            CumulativeQuantity      = c.ReadDouble();
            AveragePrice            = c.ReadDouble();
            OrderReference          = c.ReadString();
            EconomicValueRule       = c.ReadString();
            EconomicValueMultiplier = c.ReadDouble();
            if (c.Config.SupportsServerVersion(ServerVersion.ModelsSupport))
            {
                ModelCode = c.ReadString();
            }
            if (c.Config.SupportsServerVersion(ServerVersion.LastLiqidity))
            {
                LastLiquidity = c.ReadEnum <Liquidity>();
            }
            Executions[ExecutionId] = this;
        }
        internal OrderStatusReport(ResponseComposer c)
        {
            var serverVersion = c.Config.ServerVersionCurrent;
            var version       = serverVersion >= ServerVersion.MarketCapPrice ? int.MaxValue : c.ReadInt();

            OrderId          = c.ReadInt();
            Status           = c.ReadStringEnum <OrderStatus>();
            Filled           = c.ReadDouble();
            Remaining        = c.ReadDouble();
            AverageFillPrice = c.ReadDouble();
            if (version >= 2)
            {
                PermanentId = c.ReadInt();
            }
            if (version >= 3)
            {
                ParentId = c.ReadInt();
            }
            if (version >= 4)
            {
                LastFillPrice = c.ReadDouble();
            }
            if (version >= 5)
            {
                ClientId = c.ReadInt();
            }
            if (version >= 6)
            {
                WhyHeld = c.ReadString();
            }
            if (serverVersion >= ServerVersion.MarketCapPrice)
            {
                MktCapPrice = c.ReadDouble();
            }
        }
Esempio n. 4
0
 internal ContractComboLeg(ResponseComposer c)
 {
     ContractId         = c.ReadInt();
     Ratio              = c.ReadInt();
     TradeAction        = c.ReadStringEnum <TradeAction>();
     Exchange           = c.ReadString();
     OpenClose          = c.ReadEnum <ComboOpenClose>();
     ComboShortSaleSlot = c.ReadEnum <ComboShortSaleSlot>();
     DesignatedLocation = c.ReadString();
     ExemptCode         = c.ReadInt();
 }
Esempio n. 5
0
 internal AccountPosition(ResponseComposer c)
 {
     c.RequireVersion(3);
     Account  = c.ReadString();
     Contract = new Contract
     {
         ContractId   = c.ReadInt(),
         Symbol       = c.ReadString(),
         SecurityType = c.ReadStringEnum <SecurityType>(),
         LastTradeDateOrContractMonth = c.ReadString(),
         Strike       = c.ReadDouble(),
         Right        = c.ReadStringEnum <RightType>(),
         Multiplier   = c.ReadString(),
         Exchange     = c.ReadString(),
         Currency     = c.ReadString(),
         LocalSymbol  = c.ReadString(),
         TradingClass = c.ReadString()
     };
     Position    = c.ReadDouble(); // may be an int
     AverageCost = c.ReadDouble();
 }
 internal ContractDescription(ResponseComposer c)
 {
     Contract = new Contract
     {
         ContractId      = c.ReadInt(),
         Symbol          = c.ReadString(),
         SecurityType    = c.ReadStringEnum <SecurityType>(),
         PrimaryExchange = c.ReadString(),
         Currency        = c.ReadString()
     };
     c.AddStringsToList(DerivativeSecTypes);
 }
 internal AccountPositionMulti(ResponseComposer c)
 {
     c.IgnoreVersion();
     RequestId = c.ReadInt();
     Account   = c.ReadString();
     Contract  = new Contract
     {
         ContractId   = c.ReadInt(),
         Symbol       = c.ReadString(),
         SecurityType = c.ReadStringEnum <SecurityType>(),
         LastTradeDateOrContractMonth = c.ReadString(),
         Strike       = c.ReadDouble(),
         Right        = c.ReadStringEnum <RightType>(),
         Multiplier   = c.ReadString(),
         Exchange     = c.ReadString(),
         Currency     = c.ReadString(),
         LocalSymbol  = c.ReadString(),
         TradingClass = c.ReadString()
     };
     Pos       = c.ReadDouble();
     AvgCost   = c.ReadDouble();
     ModelCode = c.ReadString();
 }
Esempio n. 8
0
        internal ContractData(ResponseComposer c, ContractDataType type)
        {
            switch (type)
            {
            case ContractDataType.ContractData:
                c.RequireVersion(8);
                RequestId = c.ReadInt();

                Contract.Symbol       = c.ReadString();
                Contract.SecurityType = c.ReadStringEnum <SecurityType>();

                ReadLastTradeDate(c.ReadString(), false);

                Contract.Strike      = c.ReadDouble();
                Contract.Right       = c.ReadStringEnum <RightType>();
                Contract.Exchange    = c.ReadString();
                Contract.Currency    = c.ReadString();
                Contract.LocalSymbol = c.ReadString();

                MarketName = c.ReadString();

                Contract.TradingClass = c.ReadString();
                Contract.ContractId   = c.ReadInt();

                MinimumTick = c.ReadDouble();
                if (c.Config.SupportsServerVersion(ServerVersion.MdSizeMultiplier))
                {
                    MdSizeMultiplier = c.ReadInt();
                }

                Contract.Multiplier = c.ReadString();

                OrderTypes           = c.ReadString();
                ValidExchanges       = c.ReadString();
                PriceMagnifier       = c.ReadInt();
                UnderlyingContractId = c.ReadInt();
                LongName             = c.ReadString();

                Contract.PrimaryExchange = c.ReadString();

                ContractMonth           = c.ReadString();
                Industry                = c.ReadString();
                Category                = c.ReadString();
                Subcategory             = c.ReadString();
                TimeZoneId              = c.ReadString();
                TradingHours            = c.ReadString();
                LiquidHours             = c.ReadString();
                EconomicValueRule       = c.ReadString();
                EconomicValueMultiplier = c.ReadDouble();
                c.AddTagsToList(SecurityIds);
                if (c.Config.SupportsServerVersion(ServerVersion.AggGroup))
                {
                    AggGroup = c.ReadInt();
                }
                if (c.Config.SupportsServerVersion(ServerVersion.UnderlyingInfo))
                {
                    UnderSymbol  = c.ReadString();
                    UnderSecType = c.ReadString();
                }
                if (c.Config.SupportsServerVersion(ServerVersion.MarketRules))
                {
                    MarketRuleIds = c.ReadString();
                }
                if (c.Config.SupportsServerVersion(ServerVersion.RealExpirationDate))
                {
                    RealExpirationDate = c.ReadString();
                }
                break;

            case ContractDataType.BondContractData:
                var version = c.RequireVersion(6);
                RequestId = c.ReadInt();

                Contract.Symbol       = c.ReadString();
                Contract.SecurityType = c.ReadStringEnum <SecurityType>();

                Cusip  = c.ReadString();
                Coupon = c.ReadDouble();

                ReadLastTradeDate(c.ReadString(), true);

                IssueDate         = c.ReadString();
                CreditRatings     = c.ReadString();
                BondType          = c.ReadString();
                CouponType        = c.ReadString();
                Convertible       = c.ReadBool();
                Callable          = c.ReadBool();
                Putable           = c.ReadBool();
                DescriptionAppend = c.ReadString();

                Contract.Exchange     = c.ReadString();
                Contract.Currency     = c.ReadString();
                MarketName            = c.ReadString();
                Contract.TradingClass = c.ReadString();
                Contract.ContractId   = c.ReadInt();
                MinimumTick           = c.ReadDouble();
                if (c.Config.SupportsServerVersion(ServerVersion.MdSizeMultiplier))
                {
                    MdSizeMultiplier = c.ReadInt();
                }
                OrderTypes        = c.ReadString();
                ValidExchanges    = c.ReadString();
                NextOptionDate    = c.ReadString();
                NextOptionType    = c.ReadString();
                NextOptionPartial = c.ReadBool();
                Notes             = c.ReadString();
                LongName          = c.ReadString();
                if (version >= 6)
                {
                    EconomicValueRule       = c.ReadString();
                    EconomicValueMultiplier = c.ReadDouble();
                }
                if (version >= 5)
                {
                    c.AddTagsToList(SecurityIds);
                }
                if (c.Config.SupportsServerVersion(ServerVersion.AggGroup))
                {
                    AggGroup = c.ReadInt();
                }
                if (c.Config.SupportsServerVersion(ServerVersion.MarketRules))
                {
                    MarketRuleIds = c.ReadString();
                }
                break;

            case ContractDataType.ScannerContractData:
                Contract.ContractId   = c.ReadInt();
                Contract.Symbol       = c.ReadString();
                Contract.SecurityType = c.ReadStringEnum <SecurityType>();
                Contract.LastTradeDateOrContractMonth = c.ReadString();
                Contract.Strike       = c.ReadDouble();
                Contract.Right        = c.ReadStringEnum <RightType>();
                Contract.Exchange     = c.ReadString();
                Contract.Currency     = c.ReadString();
                Contract.LocalSymbol  = c.ReadString();
                MarketName            = c.ReadString();
                Contract.TradingClass = c.ReadString();
                break;
            }
        }
Esempio n. 9
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();
            }
        }