Example #1
0
        /// <summary>
        /// To download detailed information about the instrument.
        /// </summary>
        /// <param name="product">Security.</param>
        /// <returns>Details.</returns>
        public ProductDescripton DownloadDescription(Product product)
        {
            if (product == null)
            {
                throw new ArgumentNullException("product");
            }

            var url = "http://www1.interactivebrokers.ch/contract_info/v3.8/index.php?action=Details&site=GEN&conid="
                      + product.ContractId;

            var restxt = MakeRequest(url);

            // если картинка типа каптча ))
            if (restxt.ContainsIgnoreCase("To continue please enter the text from the image below"))
            {
                var captha = restxt.Substrings("image.php?str=", "\"")[0];
                url = "http://www1.interactivebrokers.ch/contract_info/v3.8/index.php?filter=" + captha
                      + "&action=Conid+Info&lang=en&wlId=GEN&conid=" + product.ContractId;
                restxt = MakeRequest(url);
            }

            restxt = restxt.Replace("\n", string.Empty);

            return(CultureInfo.InvariantCulture.DoInCulture(() =>
            {
                var description = new ProductDescripton
                {
                    ClosingPrice = restxt.Substrings("Closing Price</td><td>", "<")[0].To <decimal>(),
                    Name = restxt.Substrings("Description/Name</td><td>", "</td>")[1],
                    Symbol = restxt.Substrings("class=\"rowhead\">Symbol</td><td>", "</td>")[0],
                    Type = ToSecurityType(restxt.Substrings("class=\"white\"><td class=\"rowhead\">Contract Type</td><td>", "</td>")[0]),
                    Country = restxt.Substrings("Country/Region</td>", "/td></tr>")[0].Substrings("\">", "<")[0],
                    Currency = restxt.Substrings("Currency</td><td>", "<")[0],
                    AssetId = restxt.Substrings("ASSETID</td><td>", "</td>")[0],
                    StockType = restxt.Substrings("Stock Type</td><td>", "</td>")[0],
                    InitialMargin = restxt.Substrings("Initial Margin</td><td>", "</td>")[0],
                    MaintenanceMargin = restxt.Substrings("Maintenance Margin</td><td>", "</td>")[0],
                    ShortMargin = restxt.Substrings("Short Margin</td><td>", "</td>")[0]
                };

                return description;
            }));
        }
Example #2
0
		/// <summary>
		/// To download detailed information about the instrument.
		/// </summary>
		/// <param name="product">Security.</param>
		/// <returns>Details.</returns>
		public ProductDescripton DownloadDescription(Product product)
		{
			if (product == null)
				throw new ArgumentNullException(nameof(product));

			var url = "http://www1.interactivebrokers.ch/contract_info/v3.8/index.php?action=Details&site=GEN&conid="
				+ product.ContractId;

			var restxt = MakeRequest(url);

			// если картинка типа каптча ))
			if (restxt.ContainsIgnoreCase("To continue please enter the text from the image below"))
			{
				var captha = restxt.Substrings("image.php?str=", "\"")[0];
				url = "http://www1.interactivebrokers.ch/contract_info/v3.8/index.php?filter=" + captha
					+ "&action=Conid+Info&lang=en&wlId=GEN&conid=" + product.ContractId;
				restxt = MakeRequest(url);
			}

			restxt = restxt.Replace("\n", string.Empty);

			return CultureInfo.InvariantCulture.DoInCulture(() =>
			{
				var description = new ProductDescripton
				{
					ClosingPrice = restxt.Substrings("Closing Price</td><td>", "<")[0].To<decimal>(),
					Name = restxt.Substrings("Description/Name</td><td>", "</td>")[1],
					Symbol = restxt.Substrings("class=\"rowhead\">Symbol</td><td>", "</td>")[0],
					Type = ToSecurityType(restxt.Substrings("class=\"white\"><td class=\"rowhead\">Contract Type</td><td>", "</td>")[0]),
					Country = restxt.Substrings("Country/Region</td>", "/td></tr>")[0].Substrings("\">", "<")[0],
					Currency = restxt.Substrings("Currency</td><td>", "<")[0],
					AssetId = restxt.Substrings("ASSETID</td><td>", "</td>")[0],
					StockType = restxt.Substrings("Stock Type</td><td>", "</td>")[0],
					InitialMargin = restxt.Substrings("Initial Margin</td><td>", "</td>")[0],
					MaintenanceMargin = restxt.Substrings("Maintenance Margin</td><td>", "</td>")[0],
					ShortMargin = restxt.Substrings("Short Margin</td><td>", "</td>")[0]
				};

				return description;
			});
		}