示例#1
0
 void m_messageUtilities_OnQuote(object sender, QuoteEventArgs e)
 {
     try
     {
         DataSet1.StockQuotesRow row = e.ClientObject as DataSet1.StockQuotesRow;
         OnQuote(e.Quote, row);
     }
     catch (Exception ex)
     {
         OnError("Error reading QuoteEventArgs", ex);
     }
 }
示例#2
0
        private void buttonAddIndex_Click(object sender, EventArgs e)
        {
            DataSet1.StockQuotesRow row = dataSet1.StockQuotes.NewStockQuotesRow();
            row.Symbol = textBoxIndex.Text;
            dataSet1.StockQuotes.AddStockQuotesRow(row);

            IndexSubscriptionId subscription = new IndexSubscriptionId(row.Symbol, (object)row);

            m_subscriptions.Add(subscription);

            if (m_nativeUtilities.IsConnected)
            {
                m_nativeUtilities.Subscribe(new IndexSubscriptionId[] { subscription });
            }
            else if (m_messageUtilities.IsSubscriberStarted)
            {
                m_messageUtilities.Subscribe(subscription.Symbol, QuoteType.Index, subscription.QuoteObject);
            }
        }
示例#3
0
        private void OnQuote(QuoteMessage quote, DataSet1.StockQuotesRow row)
        {
            Action a = delegate
            {
                try
                {
                    if (checkBoxLog.Checked)
                    {
                        m_log.Info(quote.ToXml());
                    }

                    bool bUpdated = false;
                    row.Subscribed = (quote.SubscriptionStatus == SubscriptionStatus.Subscribed);

                    if (quote.HasOpen)
                    {
                        row.Open = quote.Open;
                        bUpdated = true;
                    }

                    if (quote.HasPrevClose)
                    {
                        row.PrevClose = quote.PrevClose;
                        bUpdated      = true;
                    }

                    if (quote.HasLast)
                    {
                        if (!row.Closed)
                        {
                            row.LastPrice = quote.Last;
                            bUpdated      = true;
                        }
                    }

                    if (quote.HasBid)
                    {
                        if (!row.Closed)
                        {
                            row.Bid  = quote.Bid;
                            bUpdated = true;
                        }
                    }
                    if (quote.HasAsk)
                    {
                        if (!row.Closed)
                        {
                            row.Ask  = quote.Ask;
                            bUpdated = true;
                        }
                    }
                    if (quote.HasDelta)
                    {
                        if (!row.Closed)
                        {
                            row.Delta = quote.Delta;
                            bUpdated  = true;
                        }
                    }
                    if (quote.HasGamma)
                    {
                        if (!row.Closed)
                        {
                            row.Gamma = quote.Gamma;
                            bUpdated  = true;
                        }
                    }
                    if (quote.HasTheta)
                    {
                        if (!row.Closed)
                        {
                            row.Theta = quote.Theta;
                            bUpdated  = true;
                        }
                    }
                    if (quote.HasVega)
                    {
                        if (!row.Closed)
                        {
                            row.Vega = quote.Vega;
                            bUpdated = true;
                        }
                    }
                    if (quote.HasImpliedVol)
                    {
                        if (!row.Closed)
                        {
                            row.ImpliedVol = quote.ImpliedVol;
                            bUpdated       = true;
                        }
                    }

                    if (quote.HasClose)
                    {
                        row.ClosingPrice = quote.Close;
                        bUpdated         = true;
                    }

                    if (quote.OpenStatus == OpenStatus.Closed)
                    {
                        row.Closed = true;
                        bUpdated   = true;
                    }

                    if (quote.OpenStatus == OpenStatus.Open)
                    {
                        row.Closed = false;
                        bUpdated   = true;
                    }

                    if (bUpdated)
                    {
                        row.Time = DateTime.Now - DateTime.Today;
                    }
                }
                catch (Exception ex)
                {
                    OnError("Error in quote handler", ex);
                }
            };

            if (InvokeRequired)
            {
                BeginInvoke(a);
            }
            else
            {
                a.Invoke();
            }
        }
示例#4
0
        void m_nativeUtilities_OnMessage(object sender, EventArgs e)
        {
            Action a = delegate
            {
                try
                {
                    BloombergMessageEventArgs args         = e as BloombergMessageEventArgs;
                    ISubscriptionId           subscription = args.SubscriptionId;
                    DataSet1.StockQuotesRow   row          = subscription.QuoteObject as DataSet1.StockQuotesRow;

                    if (checkBoxLog.Checked)
                    {
                        m_log.Info(args.MessageToXml());
                    }

                    bool bUpdated = false;
                    switch (args.Message.MessageType.ToString())
                    {
                    case "SubscriptionStarted":
                        row.Subscribed = true;
                        break;

                    case "SubscriptionTerminated":
                    case "SubscriptionFailure":
                        row.Subscribed = false;
                        break;

                    case "MarketDataEvents":

                        if (args.Message.HasElement("OPEN"))
                        {
                            row.Open = (double)args.Message.GetElementAsFloat64("OPEN");
                            bUpdated = true;
                        }

                        if (args.Message.HasElement("PREV_CLOSE_VALUE_REALTIME"))
                        {
                            row.PrevClose = (double)args.Message.GetElementAsFloat64("PREV_CLOSE_VALUE_REALTIME");
                            bUpdated      = true;
                        }

                        if (args.Message.HasElement("LAST_PRICE"))
                        {
                            if (!row.Closed)
                            {
                                row.LastPrice = (double)args.Message.GetElementAsFloat64("LAST_PRICE");
                                bUpdated      = true;
                            }
                        }

                        if (args.Message.HasElement("BID"))
                        {
                            if (!row.Closed)
                            {
                                row.Bid  = (double)args.Message.GetElementAsFloat64("BID");
                                bUpdated = true;
                            }
                        }
                        if (args.Message.HasElement("ASK"))
                        {
                            if (!row.Closed)
                            {
                                row.Ask  = (double)args.Message.GetElementAsFloat64("ASK");
                                bUpdated = true;
                            }
                        }
                        if (args.Message.HasElement("MID"))
                        {
                            if (!row.Closed)
                            {
                                row.Mid  = (double)args.Message.GetElementAsFloat64("MID");
                                bUpdated = true;
                            }
                        }
                        if (args.Message.HasElement("DELTA_MID_RT"))
                        {
                            if (!row.Closed)
                            {
                                row.Delta = (double)args.Message.GetElementAsFloat64("DELTA_MID_RT");
                                bUpdated  = true;
                            }
                        }
                        if (args.Message.HasElement("GAMMA_MID_RT"))
                        {
                            if (!row.Closed)
                            {
                                row.Gamma = (double)args.Message.GetElementAsFloat64("GAMMA_MID_RT");
                                bUpdated  = true;
                            }
                        }
                        if (args.Message.HasElement("THETA_MID_RT"))
                        {
                            if (!row.Closed)
                            {
                                row.Theta = (double)args.Message.GetElementAsFloat64("THETA_MID_RT");
                                bUpdated  = true;
                            }
                        }
                        if (args.Message.HasElement("VEGA_MID_RT"))
                        {
                            if (!row.Closed)
                            {
                                row.Vega = (double)args.Message.GetElementAsFloat64("VEGA_MID_RT");
                                bUpdated = true;
                            }
                        }
                        if (args.Message.HasElement("IVOL_MID_RT"))
                        {
                            if (!row.Closed)
                            {
                                row.ImpliedVol = (double)args.Message.GetElementAsFloat64("IVOL_MID_RT");
                                bUpdated       = true;
                            }
                        }

                        if (args.Message.HasElement("OFFICIAL_CLOSE_TODAY_RT"))
                        {
                            double closingPrice = (double)args.Message.GetElementAsFloat64("OFFICIAL_CLOSE_TODAY_RT");
                            row.ClosingPrice = closingPrice;
                            bUpdated         = true;
                        }

                        if (args.Message.HasElement("RT_SIMP_SEC_STATUS"))
                        {
                            switch (args.Message.GetElementAsString("RT_SIMP_SEC_STATUS"))
                            {
                            case "CLOS":
                            case "POST":
                            case "OUT":
                                if (!row.Closed)
                                {
                                    row.Closed = true;
                                    bUpdated   = true;
                                }
                                break;

                            default:
                                if (row.Closed)
                                {
                                    row.Closed = false;
                                    bUpdated   = true;
                                }
                                break;
                            }
                        }
                        break;
                    }

                    if (bUpdated)
                    {
                        row.Time = DateTime.Now - DateTime.Today;
                    }
                }
                catch (Exception ex)
                {
                    OnError("Error in message handler", ex);
                }
            };

            if (InvokeRequired)
            {
                BeginInvoke(a);
            }
            else
            {
                a.Invoke();
            }
        }