private void _client_ContractDetails(object sender, ContractDetailsEventArgs e)
        {
            var instrument = TWSUtils.ContractDetailsToInstrument(e.ContractDetails);
            instrument.Datasource = _thisDS;
            instrument.DatasourceID = _thisDS.ID;
            if (e.ContractDetails.Summary.Exchange != null && _exchanges.ContainsKey(e.ContractDetails.Summary.Exchange))
            {
                instrument.Exchange = _exchanges[e.ContractDetails.Summary.Exchange];
                instrument.ExchangeID = instrument.Exchange.ID;
            }
            else
            {
                Dispatcher.Invoke(() => _logger.Log(NLog.LogLevel.Error, "Could not find exchange in database: " + e.ContractDetails.Summary.Exchange));
                return;
            }

            if (e.ContractDetails.Summary.PrimaryExchange != null && _exchanges.ContainsKey(e.ContractDetails.Summary.PrimaryExchange))
            {
                instrument.PrimaryExchange = _exchanges[e.ContractDetails.Summary.PrimaryExchange];
                instrument.PrimaryExchangeID = instrument.PrimaryExchange.ID;
            }
            else if (!string.IsNullOrEmpty(e.ContractDetails.Summary.PrimaryExchange))
            {
                Dispatcher.Invoke(() => _logger.Log(NLog.LogLevel.Error, "Could not find exchange in database: " + e.ContractDetails.Summary.PrimaryExchange));
                return;
            }

            Dispatcher.Invoke(() => Instruments.Add(instrument));
        }
 private void _client_BatchContractDetail(object sender, ContractDetailsEventArgs e)
 {
     Status = string.Format("{0}/{1} symbols received", _totalSymbols - _queuedSymbols.Count, _totalSymbols);
     _tmpContractDetails.Add(e);
 }
        private void _client_ContractDetails(object sender, ContractDetailsEventArgs e)
        {
            Instrument instrument = ContractToInstrument(e);
            if (instrument == null) return;

            Application.Current.Dispatcher.Invoke(() => Instruments.Add(instrument));
        }
        private Instrument ContractToInstrument(ContractDetailsEventArgs e)
        {
            var instrument = TWSUtils.ContractDetailsToInstrument(e.ContractDetails);
            instrument.Datasource = _thisDS;
            instrument.DatasourceID = _thisDS.ID;
            if (e.ContractDetails.Summary.Exchange != null && _exchanges.ContainsKey(e.ContractDetails.Summary.Exchange))
            {
                instrument.Exchange = _exchanges[e.ContractDetails.Summary.Exchange];
                instrument.ExchangeID = instrument.Exchange.ID;
            }
            else
            {
                Application.Current.Dispatcher.Invoke(() =>
                    _logger.Log(NLog.LogLevel.Error,
                        "Could not find exchange in database: " + e.ContractDetails.Summary.Exchange));
                return null;
            }

            if (e.ContractDetails.Summary.PrimaryExchange != null &&
                _exchanges.ContainsKey(e.ContractDetails.Summary.PrimaryExchange))
            {
                instrument.PrimaryExchange = _exchanges[e.ContractDetails.Summary.PrimaryExchange];
                instrument.PrimaryExchangeID = instrument.PrimaryExchange.ID;
            }
            else if (!string.IsNullOrEmpty(e.ContractDetails.Summary.PrimaryExchange))
            {
                Application.Current.Dispatcher.Invoke(() =>
                    _logger.Log(NLog.LogLevel.Error,
                        "Could not find exchange in database: " + e.ContractDetails.Summary.PrimaryExchange));
                return null;
            }
            return instrument;
        }
        private Instrument ContractToInstrument(ContractDetailsEventArgs e)
        {
            var instrument = TWSUtils.ContractDetailsToInstrument(e.ContractDetails);
            instrument.Datasource = _thisDS;
            instrument.DatasourceID = _thisDS.ID;
            if (e.ContractDetails.Summary.Exchange != null && _exchanges.ContainsKey(e.ContractDetails.Summary.Exchange))
            {
                instrument.Exchange = _exchanges[e.ContractDetails.Summary.Exchange];
                instrument.ExchangeID = instrument.Exchange.ID;
            }
            else
            {
                _logger.Error("Could not find exchange in database: " + e.ContractDetails.Summary.Exchange);
                return null;
            }

            if (e.ContractDetails.Summary.PrimaryExchange != null &&
                _exchanges.ContainsKey(e.ContractDetails.Summary.PrimaryExchange))
            {
                instrument.PrimaryExchange = _exchanges[e.ContractDetails.Summary.PrimaryExchange];
                instrument.PrimaryExchangeID = instrument.PrimaryExchange.ID;
            }
            else if (!string.IsNullOrEmpty(e.ContractDetails.Summary.PrimaryExchange))
            {
                _logger.Error("Could not find exchange in database: " + e.ContractDetails.Summary.PrimaryExchange);
                return null;
            }
            return instrument;
        }