private void Search()
        {
            Instruments.Clear();
            var contract = new Contract
            {
                Symbol         = SymbolTextBox.Text,
                SecurityType   = TWSUtils.SecurityTypeConverter((InstrumentType)InstrumentTypeBox.SelectedItem),
                Exchange       = ExchangeBox.Text == "All" ? "" : ExchangeBox.Text,
                IncludeExpired =
                    IncludeExpiredCheckBox.IsChecked != null && (bool)IncludeExpiredCheckBox.IsChecked
            };

            if (Expirationpicker.SelectedDate.HasValue)
            {
                contract.Expiry = Expirationpicker.SelectedDate.Value.ToString("yyyyMM");
            }

            if (StrikeTextBox.Text != "")
            {
                double strike;
                bool   success = double.TryParse(StrikeTextBox.Text, out strike);
                if (success)
                {
                    contract.Strike = strike;
                }
            }

            _client.RequestContractDetails(_nextRequestID, contract);
        }
Exemple #2
0
        private void SendContractDetailsRequest(string conctactSymbol)
        {
            var contract = new Contract
            {
                Symbol       = conctactSymbol,
                SecurityType = TwsUtils.SecurityTypeConverter(SelectedType),
                Exchange     = SelectedExchange == "All"
                                              ? ""
                                              : SelectedExchange,
                IncludeExpired = IncludeExpired,
                Currency       = Currency
            };

            if (ExpirationDate.HasValue)
            {
                contract.Expiry = ExpirationDate.Value.ToString("yyyyMM");
            }

            if (Strike.HasValue)
            {
                contract.Strike = Strike.Value;
            }

            SearchUnderway = true; //disables the search commands
            client.RequestContractDetails(nextRequestId, contract);
        }
Exemple #3
0
        public ContData RequestDetails(string symbol, string exchange, string primary_exchange, SecurityType type, string currency, bool cache_ok)
        {
            // make sure we are connected
            if (!Connect)
            {
                Connect = true;
                if (!Connect)
                {
                    return(null);
                }
            }

            // check cache
            string cache_key = symbol + "," + exchange + "," + primary_exchange + "," + type.ToString() + "," + currency;

            if (cont_cache.ContainsKey(cache_key) && cache_ok)
            {
                ContData c_cache = cont_cache[cache_key];
                if (c_cache.contracts.Count > 0 &&
                    c_cache.timestamp.Date == DateTime.Now.Date)
                {
                    return(c_cache);
                }
            }

            // get id from id queue
            if (id_queue.Count == 0)
            {
                return(null);
            }
            int id = id_queue.Dequeue();

            // get tick object
            if (!cont_list.ContainsKey(id))
            {
                cont_list[id] = new ContData(id);
            }
            ContData c = cont_list[id];

            c.timestamp = DateTime.Now;

            // request underlying contract
            Contract contract = new Contract(symbol, exchange, type, currency);

            contract.PrimaryExchange = primary_exchange;
            tws.RequestContractDetails(id, contract);

            // wait for result
            c.ready_event.WaitOne(new TimeSpan(0, 0, tws_quote_timeout * 2), false);

            // remove tick from list
            cont_list.Remove(id);

            // return id to id queue
            id_queue.Enqueue(id);

            // keep in cache
            if (cont_cache.ContainsKey(cache_key))
            {
                cont_cache[cache_key] = c;
            }
            else
            {
                if (cont_cache.Count >= MAX_CACHE_SIZE)
                {
                    cont_cache.Remove(cont_cache.Keys.GetEnumerator().Current);
                }

                cont_cache.Add(cache_key, c);
            }

            return(c);
        }