public async Task Scrape(TosMarketDto dto) { using (var driver = new ChromeDriver()) { driver.Manage().Timeouts().PageLoad = new TimeSpan(0, 0, 60); driver.Manage().Timeouts().AsynchronousJavaScript = new TimeSpan(0, 0, 60); driver.Navigate().GoToUrl($"https://institute.cmegroup.com/products/{dto.Symbol}"); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(driver.PageSource); //dollar-value-of-one-tick HtmlNode dollarValueOfOneTickPreviousNode = doc.DocumentNode.QuerySelector(".dollar-value-of-one-tick"); if (dollarValueOfOneTickPreviousNode != null) { dto.TickValue = Decimal.Parse(dollarValueOfOneTickPreviousNode.NextSibling.InnerText, System.Globalization.NumberStyles.Any); } //initial-margin-rate HtmlNode initialMarginRateNode = doc.DocumentNode.QuerySelector(".initial-margin-rate"); if (initialMarginRateNode != null) { dto.InitialMargin = Decimal.Parse(initialMarginRateNode.InnerText, System.Globalization.NumberStyles.Any); } } }
public void Save(TosMarketDto dto) { try { if (dto.IsNew) { Market market = dto.MapTo <Market>(); this._repository.Insert(market); } else { Market market = this._repository.Get(dto.Id); dto.MapTo(market); } } catch (Exception ex) { } }