Beispiel #1
0
        public void ParseExecutionCondition()
        {
            ExecutionCondition cond = ParseCondition <ExecutionCondition>("trade occurs for ANY symbol on ANY exchange for * security type");
            var examp = OrderCondition.Create(OrderConditionType.Execution) as ExecutionCondition;

            examp.Exchange = "ANY";
            examp.Symbol   = "ANY";
            examp.SecType  = "*";

            Assert.IsNotNull(cond);
            Assert.AreEqual(cond.Exchange, "any", true);
            Assert.IsFalse(cond.IsConjunctionConnection);
            Assert.AreEqual(cond.SecType, "*");
            Assert.AreEqual(cond.Symbol, "any", true);
            Assert.AreEqual(cond, examp);
        }
Beispiel #2
0
 internal void ReadConditions()
 {
     if (R.Builder.SupportsServerVersion(ServerVersion.PEGGED_TO_BENCHMARK))
     {
         int n = R.ReadInt();
         if (n > 0)
         {
             for (int i = 0; i < n; i++)
             {
                 var            orderConditionType = R.ReadEnum <OrderConditionType>();
                 OrderCondition condition          = OrderCondition.Create(orderConditionType);
                 condition.Deserialize(R);
                 Order.Conditions.Add(condition);
             }
             Order.ConditionsIgnoreRegularTradingHours = R.ReadBool();
             Order.ConditionsCancelOrder = R.ReadBool();
         }
     }
 }
        private void apply_Click(object sender, EventArgs e)
        {
            var type = radioMap[radioButtons.FirstOrDefault(rb => rb.Checked)].Item2;

            if (type != Condition.Type)
            {
                Condition = OrderCondition.Create(type);
            }

            switch (type)
            {
            case OrderConditionType.Execution:
                fillCondition(Condition as ExecutionCondition);
                break;

            case OrderConditionType.Margin:
                fillCondition(Condition as MarginCondition);
                break;

            case OrderConditionType.PercentCange:
                fillCondition(Condition as PercentChangeCondition);
                break;

            case OrderConditionType.Price:
                fillCondition(Condition as PriceCondition);
                break;

            case OrderConditionType.Time:
                fillCondition(Condition as TimeCondition);
                break;

            case OrderConditionType.Volume:
                fillCondition(Condition as VolumeCondition);
                break;
            }

            DialogResult = DialogResult.OK;

            Close();
        }
        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();
            }
        }
        public ConditionDialog(OrderCondition condition, IBClient ibClient)
        {
            InitializeComponent();

            radioMap[priceRb]   = Tuple.Create(pricePanel, OrderConditionType.Price);
            radioMap[marginRb]  = Tuple.Create(marginPanel, OrderConditionType.Margin);
            radioMap[tradeRb]   = Tuple.Create(tradePanel, OrderConditionType.Execution);
            radioMap[timeRb]    = Tuple.Create(timePanel, OrderConditionType.Time);
            radioMap[volumeRb]  = Tuple.Create(volumePanel, OrderConditionType.Volume);
            radioMap[percentRb] = Tuple.Create(percentPanel, OrderConditionType.PercentCange);

            radioButtons = conditionTypePage.Controls.OfType <RadioButton>().ToArray();
            Condition    = condition != null ? condition : OrderCondition.Create(OrderConditionType.Price);

            priceMethod.Items.AddRange(CTriggerMethod.friendlyNames.Where(n => !string.IsNullOrWhiteSpace(n)).ToArray());

            foreach (var tab in tabControl1.TabPages.OfType <TabPage>().ToList())
            {
                foreach (var panel in tab.Controls.OfType <Panel>().ToList())
                {
                    var cscs = panel.Controls.OfType <ContractSearchControl>().ToList();

                    cscs.ForEach(csc =>
                                 csc.IBClient = ibClient);
                }
            }

            tabControl1.TabPages.OfType <TabPage>().Skip(2).ToList().ForEach(page => tabControl1.TabPages.Remove(page));

            switch (Condition.Type)
            {
            case OrderConditionType.Execution:
                fillFromCondition(Condition as ExecutionCondition);
                break;

            case OrderConditionType.Margin:
                fillFromCondition(Condition as MarginCondition);
                break;

            case OrderConditionType.PercentCange:
                fillFromCondition(Condition as PercentChangeCondition);
                break;

            case OrderConditionType.Price:
                fillFromCondition(Condition as PriceCondition);
                break;

            case OrderConditionType.Time:
                fillFromCondition(Condition as TimeCondition);
                break;

            case OrderConditionType.Volume:
                fillFromCondition(Condition as VolumeCondition);
                break;
            }

            if (condition != null)
            {
                tabControl1.TabPages.RemoveAt(0);

                back.Visible            = false;
                tabControl1.SelectedTab = conditionPage;

                tabControl1_SelectedIndexChanged(this, EventArgs.Empty);
            }
        }