Skip to content

Commit

Permalink
feat: подключаться к tradingview без логина
Browse files Browse the repository at this point in the history
  • Loading branch information
stupenkov committed Jul 11, 2023
1 parent 11e0587 commit 5679b88
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
3 changes: 2 additions & 1 deletion Stupesoft.LazyScalp.ConsoleUI/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
}
},
"Scaner": {
"ReloadDelayTimeSecond": 10
"ReloadDelayTimeSecond": 10,
"ChromeProfile": "Profile 3"
}
}
4 changes: 3 additions & 1 deletion Stupesoft.LazyScalp.ConsoleUI/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 14 additions & 8 deletions Stupesoft.LazyScalp.TradingView/Services/ChartPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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();
}
});
}

Expand Down
32 changes: 21 additions & 11 deletions Stupesoft.LazyScalp.TradingView/Services/WebDriverFactory.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
using OpenQA.Selenium;
using Microsoft.Extensions.Options;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using Stupesoft.LazyScalp.TradingView.Abstractions;

namespace Stupesoft.LazyScalp.TradingView.Services;

internal class WebDriverFactory : IWebDriverFactory, IDisposable
{
private readonly IOptions<ScanerOptions> _scanerOptions;
private HashSet<IWebDriver> _webDrivers = new();

public IWebDriver Create()
public WebDriverFactory(IOptions<ScanerOptions> 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);
Expand Down
2 changes: 2 additions & 0 deletions Stupesoft.LazyScalp.TradingView/TradingViewOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5679b88

Please sign in to comment.