예제 #1
0
        public List <int> SetAllLiveTopicsValues(string value)
        {
            // set all live topic values to value (e.g. in case of error) and return list of updated topic ids
            List <int> m_updatedTopicIds = new List <int>();

            foreach (TwsRtdServerTopic topic in m_topics.Values)
            {
                if (Array.IndexOf(TwsRtdServerData.DelayedTopics(), topic.TopicStr()) < 0)
                {
                    topic.TopicValue(value);
                    m_updatedTopicIds.Add(topic.TopicId());
                }
            }

            return(m_updatedTopicIds);
        }
예제 #2
0
        // this method is called when new topic is requested
        public object ConnectData(int topicId, ref Array strings, ref bool newValues)
        {
            string connectionStr, mktDataRequestStr, topicStr;

            newValues = true;

            try
            {
                // parse input strings (connection, marketDataRequest and topic)
                connectionStr     = TwsRtdServerConnection.ParseConnectionStrings(strings);
                mktDataRequestStr = TwsRtdServerMktDataRequest.ParseMktDataRequestStrings(strings);
                topicStr          = TwsRtdServerTopic.ParseTopicStrings(strings);

                // check that connectioStr, mktDataRequestStr and topicStr is not null
                if (connectionStr == null)
                {
                    return("TwsRtdServer: Cannot parse connection strings");
                }
                if (mktDataRequestStr == null)
                {
                    return("TwsRtdServer: Cannot parse mktDataRequest strings");
                }
                if (topicStr == null)
                {
                    return("TwsRtdServer: Cannot parse topic strings");
                }

                TwsRtdServerConnection connection = null;
                // find connection from RTD server to TWS (to reuse existing connection and not to create new one)
                if (!m_connections.TryGetValue(connectionStr, out connection))
                {
                    // if connection is not found, then create new one and add it to collection
                    connection = new TwsRtdServerConnection(this, connectionStr);

                    // save connection
                    m_connections.Add(connectionStr, connection);
                }

                if (connection != null && connection.GetErrorCode() != -1)
                {
                    // error connecting to TWS
                    return("TwsRtdServer error: " + connection.GetErrorText());
                }

                TwsRtdServerMktDataRequest mktDataRequest = connection.GetOrAddMktDataRequest(mktDataRequestStr);
                string errorStr = null;

                if (mktDataRequest != null)
                {
                    // save topicId -> connection/mktDataRequest/topicStr map
                    m_topicIdMap.Add(topicId, new TwsRtdServerTopicIdMap(connectionStr, mktDataRequest.TwsReqId(), topicStr));
                    if (mktDataRequest.GetErrorCode() != -1 &&
                        mktDataRequest.GetErrorCode() != TwsRtdServerErrors.REQUESTED_MARKET_DATA_NOT_SUBSCRIBED)
                    {
                        // error creating market data request
                        return(errorStr = "TwsRtdServer error: " + mktDataRequest.GetErrorText());
                    }
                }
                else
                {
                    // error creating market data request
                    return(errorStr = "TwsRtdServer error: market data request creation error");
                }

                TwsRtdServerTopic topic = mktDataRequest.GetOrAddTopic(topicStr, topicId);
                if (topic == null)
                {
                    // error creating topic
                    return(errorStr = "TwsRtdServer error: topic creation error");
                }

                // check if topic is delayed type
                if (topic != null && Array.IndexOf(TwsRtdServerData.DelayedTopics(), topic.TopicStr()) < 0 &&
                    mktDataRequest.GetErrorCode() == TwsRtdServerErrors.REQUESTED_MARKET_DATA_NOT_SUBSCRIBED)
                {
                    errorStr = "TwsRtdServer error: " + mktDataRequest.GetErrorText();
                }

                return((topic != null && errorStr == null) ? topic.TopicValue() : errorStr);
            }
            catch
            {
                return("RTDServer: Error connecting data");
            }
        }