From 5679b880796d9b7e3a540b20bcfec189f0dfe5bf Mon Sep 17 00:00:00 2001 From: stupenkov Date: Tue, 11 Jul 2023 09:52:48 +0600 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E?= =?UTF-8?q?=D1=87=D0=B0=D1=82=D1=8C=D1=81=D1=8F=20=D0=BA=20tradingview=20?= =?UTF-8?q?=D0=B1=D0=B5=D0=B7=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../appsettings.Development.json | 3 +- .../appsettings.json | 4 ++- .../Services/ChartPage.cs | 22 ++++++++----- .../Services/WebDriverFactory.cs | 32 ++++++++++++------- .../TradingViewOptions.cs | 2 ++ 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/Stupesoft.LazyScalp.ConsoleUI/appsettings.Development.json b/Stupesoft.LazyScalp.ConsoleUI/appsettings.Development.json index 8a1b901..ab8406f 100644 --- a/Stupesoft.LazyScalp.ConsoleUI/appsettings.Development.json +++ b/Stupesoft.LazyScalp.ConsoleUI/appsettings.Development.json @@ -31,6 +31,7 @@ } }, "Scaner": { - "ReloadDelayTimeSecond": 10 + "ReloadDelayTimeSecond": 10, + "ChromeProfile": "Profile 3" } } diff --git a/Stupesoft.LazyScalp.ConsoleUI/appsettings.json b/Stupesoft.LazyScalp.ConsoleUI/appsettings.json index b2fc874..c673b4d 100644 --- a/Stupesoft.LazyScalp.ConsoleUI/appsettings.json +++ b/Stupesoft.LazyScalp.ConsoleUI/appsettings.json @@ -55,7 +55,9 @@ "closeToastButton": "/html/body/div[5]/div/div/div/article/button", "tickerInput": "//*[@id=\"bottom-area\"]/div[4]/div[3]/table/thead/tr/th[1]/div/div/div[3]/input" }, - "ReloadDelayTimeSecond": 60 + "ReloadDelayTimeSecond": 60, + "SkipAuth": true, + "ChromeProfile": "Default" }, "ScalpStation": { "url": "https://scalpstation.com/kapi/binance/futures/kdata", diff --git a/Stupesoft.LazyScalp.TradingView/Services/ChartPage.cs b/Stupesoft.LazyScalp.TradingView/Services/ChartPage.cs index 9fc2cc8..1390bd0 100644 --- a/Stupesoft.LazyScalp.TradingView/Services/ChartPage.cs +++ b/Stupesoft.LazyScalp.TradingView/Services/ChartPage.cs @@ -59,12 +59,15 @@ public ChartPage(IWebDriverFactory webDriverFactory, IFinInstrumentTVManager fin public async Task LoginAsync(string login, string password) { _webDriver.Navigate().GoToUrl(_pageUrl); - _wait.Until(ExpectedConditions.ElementToBeClickable(_humburgerButton())).Click(); - _wait.Until(ExpectedConditions.ElementToBeClickable(_enterItem())).Click(); - _wait.Until(ExpectedConditions.ElementToBeClickable(_emailLoginButton())).Click(); - _emailInput().SendKeys(login); - _passwordInput().SendKeys(password); - _loginSubmitButton().Click(); + if (!_scanerOptions.Value.SkipAuth) + { + _wait.Until(ExpectedConditions.ElementToBeClickable(_humburgerButton())).Click(); + _wait.Until(ExpectedConditions.ElementToBeClickable(_enterItem())).Click(); + _wait.Until(ExpectedConditions.ElementToBeClickable(_emailLoginButton())).Click(); + _emailInput().SendKeys(login); + _passwordInput().SendKeys(password); + _loginSubmitButton().Click(); + } await Task.Delay(1000); } @@ -73,8 +76,11 @@ public async Task SetChartTemplateAsync() { await WaitAndRefreshAsync(() => { - _wait.Until(ExpectedConditions.ElementToBeClickable(_chartControlButton())).Click(); - _wait.Until(ExpectedConditions.ElementToBeClickable(_firstChartTemplateItem())).Click(); + if (!_scanerOptions.Value.SkipAuth) + { + _wait.Until(ExpectedConditions.ElementToBeClickable(_chartControlButton())).Click(); + _wait.Until(ExpectedConditions.ElementToBeClickable(_firstChartTemplateItem())).Click(); + } }); } diff --git a/Stupesoft.LazyScalp.TradingView/Services/WebDriverFactory.cs b/Stupesoft.LazyScalp.TradingView/Services/WebDriverFactory.cs index f24563d..44d591c 100644 --- a/Stupesoft.LazyScalp.TradingView/Services/WebDriverFactory.cs +++ b/Stupesoft.LazyScalp.TradingView/Services/WebDriverFactory.cs @@ -1,4 +1,5 @@ -using OpenQA.Selenium; +using Microsoft.Extensions.Options; +using OpenQA.Selenium; using OpenQA.Selenium.Chrome; using Stupesoft.LazyScalp.TradingView.Abstractions; @@ -6,29 +7,38 @@ namespace Stupesoft.LazyScalp.TradingView.Services; internal class WebDriverFactory : IWebDriverFactory, IDisposable { + private readonly IOptions _scanerOptions; private HashSet _webDrivers = new(); - public IWebDriver Create() + public WebDriverFactory(IOptions scanerOptions) { - //new DriverManager().SetUpDriver(new ChromeConfig()); - - var service = ChromeDriverService.CreateDefaultService(); - service.HideCommandPromptWindow = true; - service.SuppressInitialDiagnosticInformation = true; + _scanerOptions = scanerOptions; + } + public IWebDriver Create() + { var options = new ChromeOptions(); options.AddArgument("--lang=en-us"); options.AddExcludedArgument("enable-automation"); options.AddArgument("--disable-web-security"); options.AddArgument("--allow-running-insecure-content"); - //options.AddArgument("--start-maximized"); options.AddArgument("--no-sandbox"); options.AddArgument("--disable-dev-shm-usage"); options.AddArgument("--force-color-profile=srgb"); - options.AddUserProfilePreference("credentials_enable_service", false); - options.AddUserProfilePreference("rofile.password_manager_enabled", false); + options.AddArgument("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"); - var webDriver = new ChromeDriver(service, options); + if (_scanerOptions.Value.SkipAuth) + { + options.AddArgument(@"--user-data-dir=C:\Users\Anton\AppData\Local\Google\Chrome\User Data\"); + options.AddArgument(@$"--profile-directory={_scanerOptions.Value.ChromeProfile}"); + } + else + { + options.AddUserProfilePreference("credentials_enable_service", false); + options.AddUserProfilePreference("rofile.password_manager_enabled", false); + } + + var webDriver = new ChromeDriver(options); webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30); webDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(30); webDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(30); diff --git a/Stupesoft.LazyScalp.TradingView/TradingViewOptions.cs b/Stupesoft.LazyScalp.TradingView/TradingViewOptions.cs index 718b97e..fcbaa12 100644 --- a/Stupesoft.LazyScalp.TradingView/TradingViewOptions.cs +++ b/Stupesoft.LazyScalp.TradingView/TradingViewOptions.cs @@ -12,6 +12,8 @@ public class ScanerOptions public const string SectionName = "Scaner"; public SelectorsOptions? Selectors { get; set; } public int ReloadDelayTimeSecond { get; set; } + public bool SkipAuth { get; set; } + public string? ChromeProfile { get; set; } } public class SelectorsOptions