예제 #1
0
        void CreateAutoSpreader(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.Instrument != null && e.Error == null)
            {
                // Instrument was found
                Console.WriteLine("Found: {0}", e.Instrument.Name);

                InstrumentDictionary.Add(e.Instrument.Key, e.Instrument);

                // Update the dictionary to indicate that the instrument was found.
                InstrumentLookupSubscription instrLookupSub = sender as InstrumentLookupSubscription;

                if (SpreadLegKeys.ContainsKey((int)instrLookupSub.Tag))
                {
                    SpreadLegKeys[(int)instrLookupSub.Tag] = e.Instrument;
                }
            }
            else if (e.IsFinal)
            {
                // Instrument was not found and TT API has given up looking for it
                Console.WriteLine("Cannot find instrument: {0}", e.Error.Message);
                Subs.Dispose();
            }

            // If we have found all of the leg instruments, proceed with the creation of the spread.
            if (HaveWeFoundAllLegs())
            {
                Console.WriteLine("All leg instruments have been found.  Creating the spread...");

                // SpreadDetails related properties
                SpreadDetails spreadDetails = new SpreadDetails();
                spreadDetails.Name = AutoSpreaderName;

                for (int i = 0; i < DbTickerList.Count; i++)
                {
                    Instrument instrument = SpreadLegKeys[i + 1];

                    var ValidOrderFeeds = instrument.GetValidOrderFeeds();

                    while (ValidOrderFeeds.Count == 0)
                    {
                        ValidOrderFeeds = instrument.GetValidOrderFeeds();
                        Console.WriteLine("Attempting to get valid forder feed for: " + DbTickerList[i]);
                    }

                    SpreadLegDetails spreadlegDetails = new SpreadLegDetails(instrument, ValidOrderFeeds[0].ConnectionKey);
                    spreadlegDetails.SpreadRatio     = (int)RatioAndMultiplier["Ratio"][i];
                    spreadlegDetails.PriceMultiplier = RatioAndMultiplier["Multiplier"][i];
                    spreadlegDetails.CustomerName    = "<DEFAULT>";
                    spreadlegDetails.PayupTicks      = PayUpTicks;
                    spreadDetails.Legs.Append(spreadlegDetails);
                }

                // Create an AutospreaderInstrument corresponding to the synthetic spread
                Air            = new CreateAutospreaderInstrumentRequest(m_apiInstance.Session, Dispatcher.Current, spreadDetails);
                Air.Completed += new EventHandler <CreateAutospreaderInstrumentRequestEventArgs>(m_casReq_Completed);
                Air.Submit();
            }
        }
예제 #2
0
        /// <summary>
        /// Event notification for instrument lookup
        /// </summary>
        void m_req_Update(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.Instrument != null && e.Error == null)
            {
                // Instrument was found
                Console.WriteLine("Found: {0}", e.Instrument.Name);

                // Update the dictionary to indicate that the instrument was found.
                InstrumentLookupSubscription instrLookupSub = sender as InstrumentLookupSubscription;

                if (m_spreadLegKeys.ContainsKey((int)instrLookupSub.Tag))
                {
                    m_spreadLegKeys[(int)instrLookupSub.Tag] = e.Instrument;
                }
            }
            else if (e.IsFinal)
            {
                // Instrument was not found and TT API has given up looking for it
                Console.WriteLine("Cannot find instrument: {0}", e.Error.Message);
                Dispose();
            }

            // If we have found all of the leg instruments, proceed with the creation of the spread.
            if (HaveWeFoundAllLegs())
            {
                Console.WriteLine("All leg instruments have been found.  Creating the spread...");

                // SpreadDetails related properties
                SpreadDetails spreadDetails = new SpreadDetails();
                spreadDetails.Name = "My Spread";

                int i = 0;
                // Add the legs to the SpreadDetails
                foreach (Instrument instrument in m_spreadLegKeys.Values)
                {
                    // In this example, the order is routed to the first order feed in the list of valid order feeds.
                    // You should use the order feed that is appropriate for your purposes.
                    SpreadLegDetails spreadlegDetails = new SpreadLegDetails(instrument, instrument.GetValidOrderFeeds()[0].ConnectionKey);
                    spreadlegDetails.SpreadRatio     = (i % 2 == 0) ? 1 : -1;
                    spreadlegDetails.PriceMultiplier = (i % 2 == 0) ? 1 : -1;
                    spreadlegDetails.CustomerName    = "<Default>";

                    spreadDetails.Legs.Append(spreadlegDetails);
                    i++;
                }

                // Create an AutospreaderInstrument corresponding to the synthetic spread
                m_casReq            = new CreateAutospreaderInstrumentRequest(m_apiInstance.Session, Dispatcher.Current, spreadDetails);
                m_casReq.Completed += new EventHandler <CreateAutospreaderInstrumentRequestEventArgs>(m_casReq_Completed);
                m_casReq.Submit();
            }
        }
예제 #3
0
        Instrument CreateSpread()
        {
            string aseName = "ASE.Test." + DateTime.Now.ToString("yyyyMMddhhmmss");

            Console.WriteLine("Create a new SPREAD " + aseName);
            var spreadReq = new SpreadDetails(aseName)
            {
                Color        = Color.GreenYellow,
                PricingModel = PricingModel.NetChange
            };

            // first leg
            var inst1 = FindInstrument(m_product, m_alias1);
            var leg1  = new SpreadLegDetails(inst1, 5, 8.5M)
            {
                ActiveQuoting    = true,
                IsLeanIndicative = false,
                MinLeanQty       = "ThisLeg.DisclosedRemainingQuantity"
            };

            spreadReq.AppendLeg(leg1);

            // second leg
            var inst2 = FindInstrument(m_product, m_alias2);
            var leg2  = new SpreadLegDetails(inst2, -1, -2)
            {
                ActiveQuoting    = true,
                IsLeanIndicative = true,
                MinLeanQty       = "ThisLeg.DisclosedRemainingQuantity"
            };

            spreadReq.AppendLeg(leg2);

            // Add a spread to the spread manager and Save the ASE instrument in TT system.
            //  Parameter spreadReq: SpreadDetails object representing the spread to add
            //  Parameter rtnCode: ASReturnCodes enum indicating the status of the request
            ASReturnCodes rtnCode;
            Instrument    newInst = AutospreaderManager.AddSpreadDetails(spreadReq, out rtnCode);

            System.Diagnostics.Debug.Assert(rtnCode == ASReturnCodes.Success);
            Console.WriteLine($"   New ASE instrument is created {newInst.InstrumentDetails.Name}: {newInst.InstrumentDetails.Id}/{newInst.InstrumentDetails.Version}");
            return(newInst);
        }
예제 #4
0
        //
        //
        #endregion//Constructors


        #region no Properties
        // *****************************************************************
        // ****                     Properties                          ****
        // *****************************************************************
        //
        //
        #endregion//Properties


        #region Public Methods
        // *****************************************************************
        // ****                     Public Methods                      ****
        // *****************************************************************
        //
        //
        //
        public bool TryCreateAutoSpreader(List <UVSpreaderLeg> quoteLegsList)
        {
            SpreadDetails spreadDetails = new SpreadDetails();
            StringBuilder spreadName    = new StringBuilder();

            m_UVSpreaderLegs = quoteLegsList;
            foreach (UVSpreaderLeg spreadLeg in quoteLegsList)
            {
                UVInstrName instrName = spreadLeg.InstrumentDetails.InstrumentName;
                spreadName.AppendFormat("{0}x{1}.", instrName, spreadLeg.m_PriceLeg.Weight);

                InstrumentKey     instrKey;
                FeedConnectionKey feedConnectionKey;
                if (!m_InstrumentNameToTTKey.TryGetValue(instrName, out instrKey))
                {
                    return(false); // we can't find the instrumentKey
                }
                if (!m_DefaultFeedKey.TryGetValue(instrKey, out feedConnectionKey))
                {
                    return(false); // we can't find the instrumentKey
                }
                SpreadLegDetails spreadLegDetails = new SpreadLegDetails(instrKey, feedConnectionKey);
                spreadLegDetails.SpreadRatio     = (int)spreadLeg.m_PriceLeg.Weight;
                spreadLegDetails.PriceMultiplier = spreadLeg.m_PriceLeg.PriceMultiplier;
                spreadLegDetails.CustomerName    = instrName.ToString();

                spreadDetails.Legs.Append(spreadLegDetails);
            }

            spreadDetails.Name = spreadName.ToString();

            CreateAutospreaderInstrumentRequest autoSpreaderRequest = new CreateAutospreaderInstrumentRequest(m_TTService.session, Dispatcher.Current, spreadDetails);

            autoSpreaderRequest.Completed += new EventHandler <CreateAutospreaderInstrumentRequestEventArgs>(AutoSpreaderInstrumentRequest_Completed);
            autoSpreaderRequest.Submit();

            return(true);
        }
        /// <summary>
        /// Move the column information about the legs into the SpreadDetails object.
        /// </summary>
        /// <returns></returns>
        private bool moveColumnToSpreadDetails()
        {
            m_spreadDetails.Legs.Clear();
            m_spreadDetails.Name         = textBoxSpreadName.Text.ToString();
            m_spreadDetails.PricingModel = (PricingModel)System.Enum.Parse(typeof(PricingModel), comboBoxBasedOn.Text, true);
            m_spreadDetails.SlopType     = (SlopType)System.Enum.Parse(typeof(SlopType), comboBoxSlopSettings.Text, true);
            m_spreadDetails.LTPModel     = (LTPModel)System.Enum.Parse(typeof(LTPModel), comboBoxSpreadLTP.Text, true);
            m_spreadDetails.Color        = comboBoxLegColor.BackColor;

            for (int i = 1; i < dataGridViewSpreadDetails.Columns.Count; i++)
            {
                //get the instrument which is a hidden row
                InstrumentKey instrKey = (InstrumentKey)dataGridViewSpreadDetails.Rows[(int)FieldType.HiddenObject].Cells[i].Value;
                if (m_spreadLegs.ContainsKey(instrKey))
                {
                    Instrument instrument = (Instrument)m_spreadLegs[instrKey];

                    string    orderFeedName = dataGridViewSpreadDetails.Rows[(int)FieldType.OrderFeedCombo].Cells[i].Value.ToString();
                    OrderFeed of            = instrument.GetValidOrderFeeds().FirstOrDefault(f => f.ConnectionKey.GatewayKey.Name == orderFeedName);

                    if (of == null)
                    {
                        MessageBox.Show("OrderFeed must be selected!");
                        return(false);
                    }

                    if (m_isNewSpread)
                    {
                        SpreadLegDetails spreadLeg = new SpreadLegDetails(instrKey, of.ConnectionKey);
                        m_spreadDetails.Legs.Append(spreadLeg);
                    }

                    m_spreadDetails.Legs[i - 1].CustomerName       = dataGridViewSpreadDetails.Rows[(int)FieldType.CustomerAccount].Cells[i].Value.ToString();
                    m_spreadDetails.Legs[i - 1].ActiveQuoting      = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.ActiveQuoting].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].ConsiderOwnOrders  = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.ConsiderOwnOrders].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].OffsetHedgeType    = (HedgeType)System.Enum.Parse(typeof(HedgeType), dataGridViewSpreadDetails.Rows[(int)FieldType.OffsetHedge].Cells[i].Value.ToString(), true);
                    m_spreadDetails.Legs[i - 1].PayupTicks         = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.PayupTicks].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].SpreadRatio        = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.SpreadRatio].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].PriceMultiplier    = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.SpreadMultiplier].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].QuantityMultiplier = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.QuantityMultiplier].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].BaseVolumeLean     = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.BasicVolumeLean].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].UseCancelReplace   = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.UserCancelReplace].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].QueueHolderOrders  = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.QueueHolderOrders].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].InsideSmartQuote   = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.InsideSmartQuote].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].SmartQuoteLimit    = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.SmartQuoteLimit].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].ConsiderImplied    = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.ConsiderImplied].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].HedgeRound         = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.HedgeRound].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].MaxPriceMove       = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.MaxPriceMove].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].MaxOrderMove       = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.MaxOrderMove].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].UseCancelReplaceForQtyReduction = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.CancelReplaceForQuantity].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].OneOverPrice = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.OneOverPrice].Cells[i].Value);
                }
                else
                {
                    MessageBox.Show("could not find insturment in the map for instrument key" + instrKey.SeriesKey);
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// Add a leg to the spread given a SpreadLegDetails object.
        /// </summary>
        /// <param name="spreadLegParams">SpreadLegDetails</param>
        private void addLeg(SpreadLegDetails spreadLegParams)
        {
            DataGridViewColumn col = new DataGridViewColumn();

            col.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
            col.Width        = 150;

            col.HeaderText = "Leg " + Convert.ToString(dataGridViewSpreadDetails.Columns.Count);
            col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            DataGridViewTextBoxCell textCell = new DataGridViewTextBoxCell();

            textCell.Style.BackColor = Color.White;
            col.CellTemplate         = textCell;
            int retunValue = dataGridViewSpreadDetails.Columns.Add(col);
            int columnNum  = dataGridViewSpreadDetails.Columns.Count;

            DataGridViewButtonCell cell = new DataGridViewButtonCell();

            cell.ToolTipText     = "Delete this leg";
            cell.Value           = "Delete this leg";
            cell.Style.BackColor = Color.Red;
            dataGridViewSpreadDetails.Rows[(int)FieldType.DeleteButton].Cells[columnNum - 1] = cell;

            textCell       = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.Name;
            dataGridViewSpreadDetails.Rows[(int)FieldType.Contract].Cells[columnNum - 1] = textCell;

            DataGridViewComboBoxCell comboCell = new DataGridViewComboBoxCell();

            comboCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
            comboCell.Items.Add(spreadLegParams.InstrumentKey.MarketKey.Name);
            dataGridViewSpreadDetails.Rows[(int)FieldType.OrderFeedCombo].Cells[columnNum - 1] = comboCell;
            comboCell.Value = spreadLegParams.InstrumentKey.MarketKey.Name;

            comboCell = new DataGridViewComboBoxCell();
            comboCell.Items.Add(spreadLegParams.CustomerName);
            comboCell.Value = comboCell.Items[0];
            dataGridViewSpreadDetails.Rows[(int)FieldType.CustomerAccount].Cells[columnNum - 1] = comboCell;

            DataGridViewCheckBoxCell checkCell = new DataGridViewCheckBoxCell();

            checkCell.Value = spreadLegParams.ActiveQuoting;
            dataGridViewSpreadDetails.Rows[(int)FieldType.ActiveQuoting].Cells[columnNum - 1] = checkCell;

            checkCell       = new DataGridViewCheckBoxCell();
            checkCell.Value = spreadLegParams.ConsiderOwnOrders;
            dataGridViewSpreadDetails.Rows[(int)FieldType.ConsiderOwnOrders].Cells[columnNum - 1] = checkCell;

            comboCell = new DataGridViewComboBoxCell();
            comboCell.Items.Add("LimitOrder");
            comboCell.Items.Add("MarketOrder");
            comboCell.Items.Add("MLMOrder");
            comboCell.Value = spreadLegParams.OffsetHedgeType.ToString();
            dataGridViewSpreadDetails.Rows[(int)FieldType.OffsetHedge].Cells[columnNum - 1] = comboCell;

            //Payup ticks
            textCell       = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.PayupTicks;
            dataGridViewSpreadDetails.Rows[(int)FieldType.PayupTicks].Cells[columnNum - 1] = textCell;

            //spread ratio
            textCell       = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.SpreadRatio;
            dataGridViewSpreadDetails.Rows[(int)FieldType.SpreadRatio].Cells[columnNum - 1] = textCell;

            //spread Multiplier
            textCell       = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.PriceMultiplier;
            dataGridViewSpreadDetails.Rows[(int)FieldType.SpreadMultiplier].Cells[columnNum - 1] = textCell;

            //offset volume multiplier
            textCell       = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.QuantityMultiplier;
            dataGridViewSpreadDetails.Rows[(int)FieldType.QuantityMultiplier].Cells[columnNum - 1] = textCell;

            //base volume mulitplier
            textCell       = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.BaseVolumeLean;
            dataGridViewSpreadDetails.Rows[(int)FieldType.BasicVolumeLean].Cells[columnNum - 1] = textCell;

            //use cancel replace
            checkCell       = new DataGridViewCheckBoxCell();
            checkCell.Value = spreadLegParams.UseCancelReplace;
            dataGridViewSpreadDetails.Rows[(int)FieldType.UserCancelReplace].Cells[columnNum - 1] = checkCell;

            //Queue Holder orders
            textCell       = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.QueueHolderOrders;
            dataGridViewSpreadDetails.Rows[(int)FieldType.QueueHolderOrders].Cells[columnNum - 1] = textCell;

            //inside smart quote
            textCell       = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.InsideSmartQuote;
            dataGridViewSpreadDetails.Rows[(int)FieldType.InsideSmartQuote].Cells[columnNum - 1] = textCell;

            //Smart Quote Limit
            textCell       = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.SmartQuoteLimit;
            dataGridViewSpreadDetails.Rows[(int)FieldType.SmartQuoteLimit].Cells[columnNum - 1] = textCell;

            //Consider implied
            checkCell       = new DataGridViewCheckBoxCell();
            checkCell.Value = spreadLegParams.ConsiderImplied;
            dataGridViewSpreadDetails.Rows[(int)FieldType.ConsiderImplied].Cells[columnNum - 1] = checkCell;

            //Hedge round
            checkCell       = new DataGridViewCheckBoxCell();
            checkCell.Value = spreadLegParams.HedgeRound;
            dataGridViewSpreadDetails.Rows[(int)FieldType.HedgeRound].Cells[columnNum - 1] = checkCell;

            //Max Price Move
            textCell       = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.MaxPriceMove;
            dataGridViewSpreadDetails.Rows[(int)FieldType.MaxPriceMove].Cells[columnNum - 1] = textCell;

            //Max Order Move
            textCell       = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.MaxOrderMove;
            dataGridViewSpreadDetails.Rows[(int)FieldType.MaxOrderMove].Cells[columnNum - 1] = textCell;

            //Cancel replace for Quantity
            checkCell       = new DataGridViewCheckBoxCell();
            checkCell.Value = spreadLegParams.UseCancelReplaceForQtyReduction;
            dataGridViewSpreadDetails.Rows[(int)FieldType.CancelReplaceForQuantity].Cells[columnNum - 1] = checkCell;

            //1/Price
            checkCell       = new DataGridViewCheckBoxCell();
            checkCell.Value = spreadLegParams.OneOverPrice;
            dataGridViewSpreadDetails.Rows[(int)FieldType.OneOverPrice].Cells[columnNum - 1] = checkCell;

            //Hidden row has the actual object ot instrument
            textCell       = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.InstrumentKey;
            dataGridViewSpreadDetails.Rows[(int)FieldType.HiddenObject].Visible = false;
            dataGridViewSpreadDetails.Rows[(int)FieldType.HiddenObject].Cells[columnNum - 1] = textCell;

            if (m_spreadLegs.ContainsKey(spreadLegParams.InstrumentKey))
            {
                Instrument instrument = (Instrument)m_spreadLegs[spreadLegParams.InstrumentKey];
                updateInstrument(instrument);

                // Select the right order feed
                DataGridViewComboBoxCell combo = (DataGridViewComboBoxCell)dataGridViewSpreadDetails.Rows[(int)FieldType.OrderFeedCombo].Cells[columnNum - 1];
                foreach (string orderFeedName in combo.Items)
                {
                    if (orderFeedName.Equals(spreadLegParams.InstrumentKey.MarketKey.Name))
                    {
                        combo.Value = orderFeedName;
                        break;
                    }
                }
            }
            else
            {
                // Pass the Key to our subscription method
                findInstrument(spreadLegParams.InstrumentKey);
            }
        }
        /// <summary>
        /// Event notification for instrument lookup
        /// </summary>
        void m_req_Update(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.Instrument != null && e.Error == null)
            {
                // Instrument was found
                Console.WriteLine("Found: {0}", e.Instrument.Name);

                // Update the dictionary to indicate that the instrument was found.
                InstrumentLookupSubscription instrLookupSub = sender as InstrumentLookupSubscription;

                if (m_spreadLegKeys.ContainsKey((int)instrLookupSub.Tag))
                {
                    m_spreadLegKeys[(int)instrLookupSub.Tag] = e.Instrument;
                }
            }
            else if (e.IsFinal)
            {
                // Instrument was not found and TT API has given up looking for it
                Console.WriteLine("Cannot find instrument: {0}", e.Error.Message);
                Dispose();
            }

            // If we have found all of the leg instruments, proceed with the creation of the spread.
            if (HaveWeFoundAllLegs())
            {
                Console.WriteLine("All leg instruments have been found.  Creating the spread...");

                // SpreadDetails related properties
                SpreadDetails spreadDetails = new SpreadDetails();
                spreadDetails.Name = "My Spread";

                int i = 0;
                // Add the legs to the SpreadDetails
                foreach (Instrument instrument in m_spreadLegKeys.Values)
                {
                    // In this example, the order is routed to the first order feed in the list of valid order feeds.
                    // You should use the order feed that is appropriate for your purposes.
                    SpreadLegDetails spreadlegDetails = new SpreadLegDetails(instrument, instrument.GetValidOrderFeeds()[0].ConnectionKey);
                    spreadlegDetails.SpreadRatio = (i % 2 == 0) ? 1 : -1;
                    spreadlegDetails.PriceMultiplier = (i % 2 == 0) ? 1 : -1;
                    spreadlegDetails.CustomerName = "<Default>";

                    spreadDetails.Legs.Append(spreadlegDetails);
                    i++;
                }

                // Create an AutospreaderInstrument corresponding to the synthetic spread
                m_casReq = new CreateAutospreaderInstrumentRequest(m_apiInstance.Session, Dispatcher.Current, spreadDetails);
                m_casReq.Completed += new EventHandler<CreateAutospreaderInstrumentRequestEventArgs>(m_casReq_Completed);
                m_casReq.Submit();
            }
        }
        /// <summary>
        /// Move the column information about the legs into the SpreadDetails object.
        /// </summary>
        /// <returns></returns>
        private bool moveColumnToSpreadDetails()
        {
            m_spreadDetails.Legs.Clear();
            m_spreadDetails.Name = textBoxSpreadName.Text.ToString();
            m_spreadDetails.PricingModel = (PricingModel)System.Enum.Parse(typeof(PricingModel), comboBoxBasedOn.Text, true);
            m_spreadDetails.SlopType = (SlopType)System.Enum.Parse(typeof(SlopType), comboBoxSlopSettings.Text, true); 
            m_spreadDetails.LTPModel = (LTPModel)System.Enum.Parse(typeof(LTPModel), comboBoxSpreadLTP.Text, true);
            m_spreadDetails.Color = comboBoxLegColor.BackColor;

            for (int i = 1; i < dataGridViewSpreadDetails.Columns.Count; i++)
            {
                //get the instrument which is a hidden row
                InstrumentKey instrKey = (InstrumentKey)dataGridViewSpreadDetails.Rows[(int)FieldType.HiddenObject].Cells[i].Value;
                if (m_spreadLegs.ContainsKey(instrKey))
                {
                    Instrument instrument = (Instrument)m_spreadLegs[instrKey];

                    string orderFeedName = dataGridViewSpreadDetails.Rows[(int)FieldType.OrderFeedCombo].Cells[i].Value.ToString();
                    OrderFeed of = instrument.GetValidOrderFeeds().FirstOrDefault(f => f.ConnectionKey.GatewayKey.Name == orderFeedName);

                    if (of == null)
                    {
                        MessageBox.Show("OrderFeed must be selected!");
                        return false;
                    }

                    if (m_isNewSpread)
                    {
                        SpreadLegDetails spreadLeg = new SpreadLegDetails(instrKey, of.ConnectionKey);
                        m_spreadDetails.Legs.Append(spreadLeg);
                    }

                    m_spreadDetails.Legs[i - 1].CustomerName = dataGridViewSpreadDetails.Rows[(int)FieldType.CustomerAccount].Cells[i].Value.ToString();
                    m_spreadDetails.Legs[i - 1].ActiveQuoting = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.ActiveQuoting].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].ConsiderOwnOrders = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.ConsiderOwnOrders].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].OffsetHedgeType = (HedgeType)System.Enum.Parse(typeof(HedgeType), dataGridViewSpreadDetails.Rows[(int)FieldType.OffsetHedge].Cells[i].Value.ToString(), true);
                    m_spreadDetails.Legs[i - 1].PayupTicks = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.PayupTicks].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].SpreadRatio = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.SpreadRatio].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].PriceMultiplier = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.SpreadMultiplier].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].QuantityMultiplier = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.QuantityMultiplier].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].BaseVolumeLean = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.BasicVolumeLean].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].UseCancelReplace = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.UserCancelReplace].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].QueueHolderOrders = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.QueueHolderOrders].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].InsideSmartQuote = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.InsideSmartQuote].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].SmartQuoteLimit = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.SmartQuoteLimit].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].ConsiderImplied = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.ConsiderImplied].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].HedgeRound = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.HedgeRound].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].MaxPriceMove = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.MaxPriceMove].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].MaxOrderMove = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.MaxOrderMove].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].UseCancelReplaceForQtyReduction = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.CancelReplaceForQuantity].Cells[i].Value);
                    m_spreadDetails.Legs[i - 1].OneOverPrice = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.OneOverPrice].Cells[i].Value);
                }
                else
                {
                    MessageBox.Show("could not find insturment in the map for instrument key" + instrKey.SeriesKey);
                    return false;
                }
            }

            return true;
        }
        /// <summary>
        /// Add a leg to the spread given a SpreadLegDetails object.
        /// </summary>
        /// <param name="spreadLegParams">SpreadLegDetails</param>
        private void addLeg(SpreadLegDetails spreadLegParams)
        {
            DataGridViewColumn col = new DataGridViewColumn();
            col.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
            col.Width = 150;

            col.HeaderText = "Leg " + Convert.ToString(dataGridViewSpreadDetails.Columns.Count);
            col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            DataGridViewTextBoxCell textCell = new DataGridViewTextBoxCell();
            textCell.Style.BackColor = Color.White;
            col.CellTemplate = textCell;
            int retunValue = dataGridViewSpreadDetails.Columns.Add(col);
            int columnNum = dataGridViewSpreadDetails.Columns.Count;

            DataGridViewButtonCell cell = new DataGridViewButtonCell();
            cell.ToolTipText = "Delete this leg";
            cell.Value = "Delete this leg";
            cell.Style.BackColor = Color.Red;
            dataGridViewSpreadDetails.Rows[(int)FieldType.DeleteButton].Cells[columnNum - 1] = cell;

            textCell = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.Name;
            dataGridViewSpreadDetails.Rows[(int)FieldType.Contract].Cells[columnNum - 1] = textCell;

            DataGridViewComboBoxCell comboCell = new DataGridViewComboBoxCell();
            comboCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
            comboCell.Items.Add(spreadLegParams.InstrumentKey.MarketKey.Name);
            dataGridViewSpreadDetails.Rows[(int)FieldType.OrderFeedCombo].Cells[columnNum - 1] = comboCell;
            comboCell.Value = spreadLegParams.InstrumentKey.MarketKey.Name;

            comboCell = new DataGridViewComboBoxCell();
            comboCell.Items.Add(spreadLegParams.CustomerName);
            comboCell.Value = comboCell.Items[0];
            dataGridViewSpreadDetails.Rows[(int)FieldType.CustomerAccount].Cells[columnNum - 1] = comboCell;

            DataGridViewCheckBoxCell checkCell = new DataGridViewCheckBoxCell();
            checkCell.Value = spreadLegParams.ActiveQuoting;
            dataGridViewSpreadDetails.Rows[(int)FieldType.ActiveQuoting].Cells[columnNum - 1] = checkCell;

            checkCell = new DataGridViewCheckBoxCell();
            checkCell.Value = spreadLegParams.ConsiderOwnOrders;
            dataGridViewSpreadDetails.Rows[(int)FieldType.ConsiderOwnOrders].Cells[columnNum - 1] = checkCell;

            comboCell = new DataGridViewComboBoxCell();
            comboCell.Items.Add("LimitOrder");
            comboCell.Items.Add("MarketOrder");
            comboCell.Items.Add("MLMOrder");
            comboCell.Value = spreadLegParams.OffsetHedgeType.ToString();
            dataGridViewSpreadDetails.Rows[(int)FieldType.OffsetHedge].Cells[columnNum - 1] = comboCell;

            //Payup ticks
            textCell = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.PayupTicks;
            dataGridViewSpreadDetails.Rows[(int)FieldType.PayupTicks].Cells[columnNum - 1] = textCell;

            //spread ratio
            textCell = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.SpreadRatio;
            dataGridViewSpreadDetails.Rows[(int)FieldType.SpreadRatio].Cells[columnNum - 1] = textCell;

            //spread Multiplier
            textCell = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.PriceMultiplier;
            dataGridViewSpreadDetails.Rows[(int)FieldType.SpreadMultiplier].Cells[columnNum - 1] = textCell;

            //offset volume multiplier
            textCell = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.QuantityMultiplier;
            dataGridViewSpreadDetails.Rows[(int)FieldType.QuantityMultiplier].Cells[columnNum - 1] = textCell;

            //base volume mulitplier
            textCell = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.BaseVolumeLean;
            dataGridViewSpreadDetails.Rows[(int)FieldType.BasicVolumeLean].Cells[columnNum - 1] = textCell;

            //use cancel replace
            checkCell = new DataGridViewCheckBoxCell();
            checkCell.Value = spreadLegParams.UseCancelReplace; 
            dataGridViewSpreadDetails.Rows[(int)FieldType.UserCancelReplace].Cells[columnNum - 1] = checkCell;

            //Queue Holder orders
            textCell = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.QueueHolderOrders;
            dataGridViewSpreadDetails.Rows[(int)FieldType.QueueHolderOrders].Cells[columnNum - 1] = textCell;

            //inside smart quote
            textCell = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.InsideSmartQuote;
            dataGridViewSpreadDetails.Rows[(int)FieldType.InsideSmartQuote].Cells[columnNum - 1] = textCell;

            //Smart Quote Limit
            textCell = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.SmartQuoteLimit;
            dataGridViewSpreadDetails.Rows[(int)FieldType.SmartQuoteLimit].Cells[columnNum - 1] = textCell;

            //Consider implied
            checkCell = new DataGridViewCheckBoxCell();
            checkCell.Value = spreadLegParams.ConsiderImplied;
            dataGridViewSpreadDetails.Rows[(int)FieldType.ConsiderImplied].Cells[columnNum - 1] = checkCell;

            //Hedge round
            checkCell = new DataGridViewCheckBoxCell();
            checkCell.Value = spreadLegParams.HedgeRound;
            dataGridViewSpreadDetails.Rows[(int)FieldType.HedgeRound].Cells[columnNum - 1] = checkCell;

            //Max Price Move
            textCell = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.MaxPriceMove;
            dataGridViewSpreadDetails.Rows[(int)FieldType.MaxPriceMove].Cells[columnNum - 1] = textCell;

            //Max Order Move
            textCell = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.MaxOrderMove;
            dataGridViewSpreadDetails.Rows[(int)FieldType.MaxOrderMove].Cells[columnNum - 1] = textCell;

            //Cancel replace for Quantity
            checkCell = new DataGridViewCheckBoxCell();
            checkCell.Value = spreadLegParams.UseCancelReplaceForQtyReduction;
            dataGridViewSpreadDetails.Rows[(int)FieldType.CancelReplaceForQuantity].Cells[columnNum - 1] = checkCell;

            //1/Price
            checkCell = new DataGridViewCheckBoxCell();
            checkCell.Value = spreadLegParams.OneOverPrice;
            dataGridViewSpreadDetails.Rows[(int)FieldType.OneOverPrice].Cells[columnNum - 1] = checkCell;

            //Hidden row has the actual object ot instrument
            textCell = new DataGridViewTextBoxCell();
            textCell.Value = spreadLegParams.InstrumentKey;
            dataGridViewSpreadDetails.Rows[(int)FieldType.HiddenObject].Visible = false;
            dataGridViewSpreadDetails.Rows[(int)FieldType.HiddenObject].Cells[columnNum - 1] = textCell;

            if (m_spreadLegs.ContainsKey(spreadLegParams.InstrumentKey))
            {
                Instrument instrument = (Instrument)m_spreadLegs[spreadLegParams.InstrumentKey];
                updateInstrument(instrument);

                // Select the right order feed
                DataGridViewComboBoxCell combo = (DataGridViewComboBoxCell)dataGridViewSpreadDetails.Rows[(int)FieldType.OrderFeedCombo].Cells[columnNum - 1];
                foreach (string orderFeedName in combo.Items)
                {
                    if (orderFeedName.Equals(spreadLegParams.InstrumentKey.MarketKey.Name))
                    {
                        combo.Value = orderFeedName;
                        break;
                    }
                }
            }
            else
            {
                // Pass the Key to our subscription method
                findInstrument(spreadLegParams.InstrumentKey);
            }
        }
        private void CreateSpreadDetails()
        {
            Console.WriteLine("Creating the spread...");

            // SpreadDetails related properties
            SpreadDetails spreadDetails = new SpreadDetails();
            spreadDetails.Name = "My Spread";

            int i = 0;
            // Add the legs to the SpreadDetails
            foreach (Instrument instrument in spreadLegKeys.Values)
            {
                // In this example, the order is routed to the first order feed in the list of valid order feeds.
                // You should use the order feed that is appropriate for your purposes.
                SpreadLegDetails spreadlegDetails = new SpreadLegDetails(instrument.Key, instrument.GetValidOrderFeeds()[0].ConnectionKey);
                spreadlegDetails.SpreadRatio = (i % 2 == 0) ? 1 : -1;
                spreadlegDetails.PriceMultiplier = (i % 2 == 0) ? 1 : -1;
                spreadlegDetails.CustomerName = "<Default>";

                spreadDetails.Legs.Append(spreadlegDetails);
                i++;
            }

            // Create an Instrument corresponding to the synthetic spread
            casReq = new CreateAutospreaderInstrumentRequest(apiInstance.Session, Dispatcher.Current, spreadDetails);
            casReq.Completed += new EventHandler<CreateAutospreaderInstrumentRequestEventArgs>(casReq_Completed);
            casReq.Submit();
        }
예제 #11
0
        void CreateAutoSpreader(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.Instrument != null && e.Error == null)
            {
                // Instrument was found
                Console.WriteLine("Found: {0}", e.Instrument.Name);

                InstrumentDictionary.Add(e.Instrument.Key, e.Instrument);

                // Update the dictionary to indicate that the instrument was found.
                InstrumentLookupSubscription instrLookupSub = sender as InstrumentLookupSubscription;

                if (SpreadLegKeys.ContainsKey((int)instrLookupSub.Tag))
                {
                    SpreadLegKeys[(int)instrLookupSub.Tag] = e.Instrument;
                }
            }
            else if (e.IsFinal)
            {
                // Instrument was not found and TT API has given up looking for it
                Console.WriteLine("Cannot find instrument: {0}", e.Error.Message);
                Subs.Dispose();
            }

            // If we have found all of the leg instruments, proceed with the creation of the spread.
            if (HaveWeFoundAllLegs())
            {
                Console.WriteLine("All leg instruments have been found.  Creating the spread...");

                // SpreadDetails related properties
                SpreadDetails spreadDetails = new SpreadDetails();
                spreadDetails.Name = AutoSpreaderName;

                for (int i = 0; i < DbTickerList.Count; i++)
                {
                    Instrument instrument = SpreadLegKeys[i + 1];
                    SpreadLegDetails spreadlegDetails = new SpreadLegDetails(instrument, instrument.GetValidOrderFeeds()[0].ConnectionKey);
                    spreadlegDetails.SpreadRatio = (int)RatioAndMultiplier["Ratio"][i];
                    spreadlegDetails.PriceMultiplier = RatioAndMultiplier["Multiplier"][i];
                    spreadlegDetails.CustomerName = "<DEFAULT>";
                    spreadlegDetails.PayupTicks = PayUpTicks;
                    spreadDetails.Legs.Append(spreadlegDetails);
                }

                // Create an AutospreaderInstrument corresponding to the synthetic spread
                Air = new CreateAutospreaderInstrumentRequest(m_apiInstance.Session, Dispatcher.Current, spreadDetails);
                Air.Completed += new EventHandler<CreateAutospreaderInstrumentRequestEventArgs>(m_casReq_Completed);
                Air.Submit();
            }
        }