Ejemplo n.º 1
0
        // method is called when there are new data to update
        public Array RefreshData(ref int topicCount)
        {

            object[,] data = null;

            try
            {
                TwsRtdServerConnection connection = null;
                TwsRtdServerMktDataRequest mktDataRequest = null;
                TwsRtdServerTopic topic = null;

                // in loop - update all topics from updatedTopicIds array
                int[] updatedTopicIds;
                lock (m_updatedTopicIds)
                {
                    updatedTopicIds = m_updatedTopicIds.ToArray();
                    m_updatedTopicIds.Clear();
                }

                topicCount = updatedTopicIds.Length;
                data = new object[2, topicCount];

                int n = 0;
                foreach(var topicId in updatedTopicIds)
                {
                    TwsRtdServerTopicIdMap twsRtdServerTopicIdMap = null;
                    if (m_topicIdMap.TryGetValue(topicId, out twsRtdServerTopicIdMap))
                    {
                        // get appropriate connection
                        if (m_connections.TryGetValue(twsRtdServerTopicIdMap.ConnectionStr(), out connection))
                        {
                            // get appropriate mktDataRequest
                            mktDataRequest = connection.GetMktDataRequest(twsRtdServerTopicIdMap.TwsReqId());
                            if (mktDataRequest != null)
                            {
                                // get appropriate topic
                                topic = mktDataRequest.GetTopic(twsRtdServerTopicIdMap.TopicStr());
                            }
                            if (topic != null)
                            {
                                // update data array with topic.Id and topic.Value
                                data[0, n] = topic.TopicId();
                                data[1, n] = topic.TopicValue();
                                n++;
                            }
                        }
                    }
                }
            }
            catch //(COMException comException)
            {
                // comException.Message = "The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))"
                // Console.WriteLine(comException.Message);
            }

            return data;
        }
Ejemplo n.º 2
0
        void GetTopicAndAddUpdate(string topicStr, TwsRtdServerMktDataRequest mktDataRequest, object value)
        {
            TwsRtdServerTopic topic = mktDataRequest.GetTopic(topicStr);

            if (topic != null)
            {
                // set topic's new value
                topic.TopicValue(value);

                m_server.AddUpdatedTopicId(topic.TopicId());  // add topic to updatedTopicIds array
            }

            // save latest value
            mktDataRequest.SetMktDataTickValue(topicStr, value);
        }