Exemplo n.º 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();
            }
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Shuts down the TT API
        /// </summary>
        public void Dispose()
        {
            lock (m_lock)
            {
                if (!m_disposed)
                {
                    // Unattached callbacks and dispose of all subscriptions
                    if (m_req1 != null)
                    {
                        m_req1.Update -= m_req_Update;
                        m_req1.Dispose();
                        m_req1 = null;
                    }
                    if (m_req2 != null)
                    {
                        m_req2.Update -= m_req_Update;
                        m_req2.Dispose();
                        m_req2 = null;
                    }
                    if (m_ps != null)
                    {
                        m_ps.FieldsUpdated -= m_ps_FieldsUpdated;
                        m_ps.Dispose();
                        m_ps = null;
                    }
                    if (m_ts != null)
                    {
                        m_ts.OrderAdded    -= m_ts_OrderAdded;
                        m_ts.OrderDeleted  -= m_ts_OrderDeleted;
                        m_ts.OrderFilled   -= m_ts_OrderFilled;
                        m_ts.OrderRejected -= m_ts_OrderRejected;
                        m_ts.OrderUpdated  -= m_ts_OrderUpdated;
                        m_ts.Dispose();
                        m_ts = null;
                    }
                    if (m_casReq != null)
                    {
                        m_casReq.Completed -= m_casReq_Completed;
                        m_casReq.Dispose();
                        m_casReq = null;
                    }

                    // Begin shutdown the TT API
                    TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted);
                    TTAPI.Shutdown();

                    m_disposed = true;
                }
            }
        }
Exemplo n.º 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
                }
                // This needs to be fixed due to the newer API 7.17
                //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>
        /// Shuts down the TT API
        /// </summary>
        public void Dispose()
        {
            lock (m_lock)
            {
                if (!m_disposed)
                {
                    // Unattached callbacks and dispose of all subscriptions
                    if (m_req1 != null)
                    {
                        m_req1.Update -= m_req_Update;
                        m_req1.Dispose();
                        m_req1 = null;
                    }
                    if (m_req2 != null)
                    {
                        m_req2.Update -= m_req_Update;
                        m_req2.Dispose();
                        m_req2 = null;
                    }
                    if (m_ps != null)
                    {
                        m_ps.FieldsUpdated -= m_ps_FieldsUpdated;
                        m_ps.Dispose();
                        m_ps = null;
                    }
                    if (m_ts != null)
                    {
                        m_ts.OrderAdded -= m_ts_OrderAdded;
                        m_ts.OrderDeleted -= m_ts_OrderDeleted;
                        m_ts.OrderFilled -= m_ts_OrderFilled;
                        m_ts.OrderRejected -= m_ts_OrderRejected;
                        m_ts.OrderUpdated -= m_ts_OrderUpdated;
                        m_ts.Dispose();
                        m_ts = null;
                    }
                    if (m_casReq != null)
                    {
                        m_casReq.Completed -= m_casReq_Completed;
                        m_casReq.Dispose();
                        m_casReq = null;
                    }

                    // Begin shutdown the TT API
                    TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted);
                    TTAPI.Shutdown();

                    m_disposed = true;
                }
            }
        }
        /// <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();
            }
        }
        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();
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {

                    // Shutdown all subscriptions
                    if (req1 != null)
                    {
                        req1.Dispose();
                        req1 = null;
                    }
                    if (req2 != null)
                    {
                        req2.Dispose();
                        req2 = null;
                    }
                    if (casReq != null)
                    {
                        casReq.Dispose();
                        casReq = null;
                    }
                    if (ts != null)
                    {
                        ts.Dispose();
                        ts = null;
                    }

                    // Shutdown the Dispatcher
                    if (disp != null)
                    {
                        disp.BeginInvokeShutdown();
                        disp = null;
                    }

                    // Shutdown the TT API
                    if (apiInstance != null)
                    {
                        apiInstance.Shutdown();
                        apiInstance = null;
                    }
                }
            }

            disposed = true;
        }
Exemplo n.º 9
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();
            }
        }