Esempio n. 1
0
        private void OnNotifyUpdate(XTAPI.TTInstrNotify pNotify, XTAPI.TTInstrObj pInstr)
        {
            try
            {
                Array data = (Array)pInstr.get_Get("Bid#,Ask#,NetPos,PL.Z,OpenPL^");

                //get currency amount of tick
                double tickvalue = Convert.ToDouble(pInstr.get_TickPrice(0, 1, "^"));

                for (int i = 0; i < data.Length; ++i)
                {
                    if (data.GetValue(i) == null)
                    {
                        return;
                    }
                }

                Update update = new Update();

                update.Bid    = Convert.ToDouble(data.GetValue(0));
                update.Ask    = Convert.ToDouble(data.GetValue(1));
                update.NetPos = Convert.ToInt16(data.GetValue(2));
                //convert number of ticks from PL to currency
                update.PL     = tickvalue * Convert.ToDouble(data.GetValue(3));
                update.OpenPL = Convert.ToDouble(data.GetValue(4));
                update.Symbol = pInstr.Product;


                if (OnUpdate != null)
                {
                    OnUpdate(this, new UpdateEventArgs(update));
                }
            }
            catch (Exception ex)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error(ex.StackTrace);
                }
            }
        }
Esempio n. 2
0
        public void OnNotifyFound(XTAPI.TTInstrNotify pNotify, XTAPI.TTInstrObj pInstr)
        {
            try
            {
                //we use the same TTInstrNotify.OnNotifyFound event so we need to check the Product
                if (Convert.ToString(pInstr.get_Get("Product")) == instrument.Product)
                {
                    tickPrice = Convert.ToDouble(pInstr.get_TickPrice(0, 1, "#"));
                    tickIncr  = Convert.ToInt16(pInstr.get_Get("TickIncrement"));
                }


                if (OnFound != null)
                {
                    OnFound(this, new FoundEventArgs(tickPrice));
                }

                Application.DoEvents();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// This function is called when an instrument is dragged and dropped from the 
        /// Market Grid in X_TRADER.
        /// </summary>
        private void m_TTDropHandler_OnNotifyDrop()
        {
            // Update the Status Bar text.
            sbaStatus.Text = "Drag & Drop detected.  Initializing instrument...";

            try
            {
                if (m_TTInstrObj != null)
                {
                    // Detach previously attached instrument.
                    m_TTInstrNotify.DetachInstrument(m_TTInstrObj);
                    m_TTInstrObj = null;
                }

                // Obtain the TTInstrObj from the TTDropHandler object.
                m_TTInstrObj = (XTAPI.TTInstrObj)m_TTDropHandler[1];

                // Attach the TTInstrObj to the TTInstrNotify for price update events.
                m_TTInstrNotify.AttachInstrument(m_TTInstrObj);

                // Open the TTInstrObj.
                m_TTInstrObj.Open(0);	// enable Market Depth:  1 - true, 0 - false

                // Clear drop handler list.
                m_TTDropHandler.Reset();
            }
            catch (Exception ex)
            {
                // Display exception message.
                MessageBox.Show(ex.Message, "Exception");
            }
        }
        /// <summary>
        /// This function is called when one or more instruments are dragged and dropped from 
        /// the Market Grid in X_TRADER.
        /// </summary>
        private void m_TTDropHandler_OnNotifyDrop()
        {
            // Update the Status Bar text.
            sbaStatus.Text = "Drag & Drop detected.  Initializing instrument...";

            // Clear items in listbox
            lboPriceList.Items.Clear();

            try
            {
                // Test if a TTInstrObj currently exists.
                if (m_TTInstrObj != null)
                {
                    // Detach previously attached instrument.
                    m_TTInstrNotify.DetachInstrument(m_TTInstrObj);
                    m_TTInstrObj = null;
                }

                // Obtain the TTInstrObj from the TTDropHandler object.
                m_TTInstrObj = (XTAPI.TTInstrObj) m_TTDropHandler[1];

                // Attach the TTInstrObj to the TTInstrNotify for price update events.
                m_TTInstrNotify.AttachInstrument(m_TTInstrObj);

                // Set an update filter to stop receiving OnPriceListUpdate for volume
                m_TTInstrNotify.UpdateFilter = "Last,LastQty,HitTake";

                // Open the TTInstrObj.
                m_TTInstrObj.Open(0);	// enable Market Depth:  1 - true, 0 - false

                // Clear drop handler list.
                m_TTDropHandler.Reset();
            }
            catch (Exception ex)
            {
                // Display exception message.
                MessageBox.Show(ex.Message, "Exception");
            }
        }
Esempio n. 5
0
        private void initQuotes()
        {
            // Instantiate the instrument notification class.
            m_TTInstrNotify = new XTAPI.TTInstrNotifyClass();

            log("Loading Quotes config: " + realTimeLocation);

            string[] lines = System.IO.File.ReadAllLines(realTimeLocation);

            // Setup the instrument notification call back functions.
            m_TTInstrNotify.OnNotifyFound += new XTAPI._ITTInstrNotifyEvents_OnNotifyFoundEventHandler(this.m_TTInstrNotify_OnNotifyFound);
            m_TTInstrNotify.OnNotifyUpdate += new XTAPI._ITTInstrNotifyEvents_OnNotifyUpdateEventHandler(this.m_TTInstrNotify_OnNotifyUpdate);

            log("Init Depth config");
            m_TTInstrNotify.OnNotifyDepthData += new XTAPI._ITTInstrNotifyEvents_OnNotifyDepthDataEventHandler(pNotify_OnNotifyDepthData);
            m_TTInstrNotify.EnableDepthUpdates = 1;
            depths = new Hashtable(600);

            string[] conf = null;
            string raw = null;

            foreach(string line in lines) {
                try {

                    raw = line;
                    conf = line.Split(',');
                    XTAPI.TTInstrObj m_TTInstrObj = new XTAPI.TTInstrObj();
                    m_TTInstrObj.Exchange =conf[0];
                    m_TTInstrObj.Product =conf[1];
                    m_TTInstrObj.ProdType =conf[2];
                    m_TTInstrObj.Contract =conf[3];

                    m_TTInstrNotify.AttachInstrument(m_TTInstrObj);
                    // 1 authorize depth
                    //m_TTInstrObj.Open(1);
                    m_TTInstrObj.Open(0);

                    Console.WriteLine(conf[1]+" "+conf[3]+" Added");

                } catch (Exception e)
                {
                    log("Error!!! >>>"+e.Message+" "+line);
                }

            }

            log(lines.Length+" Quotes Parsed");
        }
        /// <summary>
        /// Connect to the instruments
        /// </summary>
        /// <param name="sender">Object which fires the method</param>
        /// <param name="e">Event arguments of the callback</param>
        private void connectButton_Click(object sender, System.EventArgs e)
        {
            // Update the Status Bar text.
            sbaStatus.Text = "Connecting to Instrument...";

            try
            {
                if (m_TTInstrObj != null)
                {
                    // Detach previously attached instrument.
                    m_TTInstrNotify.DetachInstrument(m_TTInstrObj);
                    m_TTInstrObj = null;
                }

                // Instantiate a new instrument object.
                m_TTInstrObj = new XTAPI.TTInstrObjClass();

                // Obtain the instrument information from the user input.
                m_TTInstrObj.Exchange = txtExchange.Text;
                m_TTInstrObj.Product = txtProduct.Text;
                m_TTInstrObj.ProdType = txtProductType.Text;
                m_TTInstrObj.Contract = txtContract.Text;

                // Attach the TTInstrObj to the TTInstrNotify for price update events.
                m_TTInstrNotify.AttachInstrument(m_TTInstrObj);

                // Open the TTInstrObj.
                m_TTInstrObj.Open(0);	// enable Market Depth:  1 - true, 0 - false
            }
            catch (Exception ex)
            {
                // Display exception message.
                MessageBox.Show(ex.Message, "Exception");
            }
        }