public static PortfolioInfo Capture() { var capture = new PortfolioInfo(); var options = new ChromeOptions(); options.AddArgument("--headless"); // creates new chromeDriver and goes to webpage var chromeDriver = new ChromeDriver(@"./", options); chromeDriver.Navigate().GoToUrl("https://login.yahoo.com/"); chromeDriver.FindElementById("login-username").Click(); chromeDriver.Keyboard.SendKeys(usernamePassword.YahooUsername()); chromeDriver.Keyboard.SendKeys(Keys.Enter); chromeDriver.FindElementById("login-passwd").Click(); chromeDriver.Keyboard.SendKeys(usernamePassword.YahooPassword()); chromeDriver.Keyboard.SendKeys(Keys.Enter); //navigate to Jbristol Portfolio chromeDriver.Navigate().GoToUrl("https://finance.yahoo.com/portfolio/p_1/view/v2"); chromeDriver.FindElement(By.Id("__dialog")).Click(); chromeDriver.Keyboard.SendKeys(Keys.Escape); getPortfolioData(chromeDriver, capture); var portfolioStockInfo = getStockData(chromeDriver); chromeDriver.Quit(); capture.StockInfo = portfolioStockInfo; return(capture); }
public async Task <IActionResult> Edit(int id, [Bind("ID,CaptureDate,PortfolioValue,DayGain,PercentDayGain,TotalGain,PercentTotalGain")] PortfolioInfo portfolioInfo) { if (id != portfolioInfo.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(portfolioInfo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PortfolioInfoExists(portfolioInfo.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(portfolioInfo)); }
/// <summary> /// /// - Default to null wehen calculating efficient frontier /// </summary> /// <param name="targetrisk"></param> /// <returns></returns> internal void setTargetRisk(double targetrisk) { // Automatically set objective this.setModelObjective(Objective.MaximizeReturn); this.portfInfo = new PortfolioInfo(targetRisk: targetrisk, riskFreerate: this.portfInfo.RiskFreeRate, nfPoints: this.portfInfo.nFrontierPoints); this.ChangedFlag = true; }
internal PortfolioSpec() { modelInfo = new ModelInfo(); solverInfo = new SolverInfo(); portfInfo = new PortfolioInfo(); // Ensure the solver's objective funtion is the same as that of the model solverInfo = new SolverInfo(opt: modelInfo.OptimizationObjective); this.ChangedFlag = true; }
internal PortfolioSpec(ModelInfo mod, SolverInfo opt, PortfolioInfo frontier) { modelInfo = mod; solverInfo = opt; portfInfo = frontier; // Ensure the solver's objective funtion is the same as that of the model solverInfo = new SolverInfo(opt: modelInfo.OptimizationObjective); this.ChangedFlag = true; }
public async Task <IActionResult> Create(PortfolioInfo info) { var snapshot = GetData.Retrieve(); if (ModelState.IsValid) { _context.Add(snapshot); await _context.SaveChangesAsync(); } return(Redirect("/stocks/Details/" + snapshot.ID)); }
public void AddNewUsersShares(PortfolioInfo args) { var PortfolioToAdd = new PortfolioEntity() { UserEntityId = args.UserId, ShareId = args.ShareId, Amount = args.Amount }; repo.AddNewUsersShares(PortfolioToAdd); repo.SaveChanges(); }
public void StartTrading() { Random random = new Random(); var seller = usersService.GetSeller(random.Next(1, userRepo.Count())); var customer = usersService.GetCustomer(random.Next(1, userRepo.Count()), seller.Id); if (seller == null || customer == null) //тут проблема что исключение обрабатывается в прокси, а сам прокси в таком случае кидает null, знаю что костыль { return; } var sellerPortfolioForTrade = seller.UsersShares.ToList()[random.Next(0, seller.UsersShares.Count())]; var amountSharesForTrade = random.Next(1, sellerPortfolioForTrade.Amount / 5); var shareForTrade = sellerPortfolioForTrade.Share; decimal CostOfTransaction = amountSharesForTrade * shareForTrade.Price; usersService.ChangeUserBalance(seller.Id, CostOfTransaction); usersService.ChangeUserBalance(customer.Id, CostOfTransaction * -1); PortfolioEntity customerPortfolio; if ((customerPortfolio = customer.UsersShares.Where(us => us.ShareId == shareForTrade.Id).FirstOrDefault()) == null) { PortfolioInfo customerPortfolioToAdd = new PortfolioInfo() { UserId = customer.Id, ShareId = shareForTrade.Id, Amount = amountSharesForTrade }; portfolioService.AddNewUsersShares(customerPortfolioToAdd); } else { portfolioService.ChangeAmountOfShares(customerPortfolio, amountSharesForTrade); } portfolioService.ChangeAmountOfShares(sellerPortfolioForTrade, amountSharesForTrade * -1); TransactionStoryInfo transactionOperation = new TransactionStoryInfo() { customerId = customer.Id, sellerId = seller.Id, shareId = shareForTrade.Id, Share = shareForTrade, AmountOfShares = amountSharesForTrade, DateTime = DateTime.Now, TransactionCost = CostOfTransaction }; transaction.AddNewTransaction(transactionOperation); }
public async Task <IActionResult> Create(PortfolioInfo portfolioInfo) { var captureScrape = GetCapture.Capture(); if (ModelState.IsValid) { _context.Add(captureScrape); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { Console.WriteLine("error with scrape"); } return(View(captureScrape)); }
public async Task <IActionResult> Create([Bind("ID,CaptureDate,PortfolioValue,DayGain,PercentDayGain,TotalGain,PercentTotalGain, StockInfo")] PortfolioInfo portfolioInfo) { var captureScrape = GetCapture.Capture(); if (ModelState.IsValid) { _context.Add(captureScrape); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { Console.WriteLine("error with scrape"); } return(View(captureScrape)); }
public void ShouldAddNewUsersShares() { var portfolioTableRepository = Substitute.For <IPortfolioTableRepository>(); PortfolioServices portfolio = new PortfolioServices(portfolioTableRepository); PortfolioInfo args = new PortfolioInfo() { UserId = 1, ShareId = 1, Amount = 50 }; portfolio.AddNewUsersShares(args); portfolioTableRepository.AddNewUsersShares(Arg.Is <PortfolioEntity>( us => us.UserEntityId == args.UserId && us.ShareId == args.ShareId && us.Amount == args.Amount)); portfolioTableRepository.Received(1).SaveChanges(); }
private static void getPortfolioData(ChromeDriver chromeDriver, PortfolioInfo capture) { var currentValue = chromeDriver .FindElementByXPath("//*[@id=\"main\"]/section/header/div/div[1]/div/div[2]/p[1]").Text; var dayGain = chromeDriver .FindElementByXPath("//*[@id=\"main\"]/section/header/div/div[1]/div/div[2]/p[2]/span").Text.Split(' '); var totalGain = chromeDriver .FindElementByXPath("//*[@id=\"main\"]/section/header/div/div[1]/div/div[2]/p[3]/span").Text.Split(' '); var dayGainPercent = dayGain[1]; var totalGainPercent = totalGain[1]; capture.CaptureDate = DateTime.Now; capture.PortfolioValue = decimal.Parse(currentValue, NumberStyles.Currency); capture.DayGain = decimal.Parse(dayGain[0]); capture.PercentDayGain = (double.Parse(dayGainPercent.Trim(new char[] { ' ', '(', '%', ')' })) / 100); capture.TotalGain = decimal.Parse(totalGain[0]); capture.PercentTotalGain = (double.Parse(totalGainPercent.Trim(new char[] { ' ', '(', '%', ')' })) / 100); // Console.WriteLine( // "currentValue: {0}, dayGain: {1}, totalGain: {2}, dayGainPercent: {3}, totalGainPercent: {4}", // PortfolioValue, DayGain, TotalGain, PercentDayGain, PercentTotalGain); }
private void GetPortfoliosArea() { try { while (ServerStatus == ServerConnectStatus.Disconnect) { Thread.Sleep(5000); } Char separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0]; if (_portfolios == null) { _portfolios = new List <Portfolio>(); } List <TradesAccounts> accaunts = QuikLua.Class.GetTradeAccounts().Result; var clientCode = QuikLua.Class.GetClientCode().Result; while (true) { Thread.Sleep(5000); if (MainWindow.ProccesIsWorked == false) { return; } if (QuikLua == null) { continue; } for (int i = 0; i < accaunts.Count; i++) { if (String.IsNullOrWhiteSpace(accaunts[i].ClassCodes)) { continue; } Portfolio myPortfolio = _portfolios.Find(p => p.Number == accaunts[i].TrdaccId); if (myPortfolio == null) { myPortfolio = new Portfolio(); _portfolios.Add(myPortfolio); } myPortfolio.Number = accaunts[i].TrdaccId; PortfolioInfo qPortfolio = QuikLua.Trading.GetPortfolioInfo(accaunts[i].Firmid, clientCode).Result; if (qPortfolio.Assets == null || qPortfolio.Assets.ToDecimal() == 0) { PortfolioInfoEx qPortfolioEx = QuikLua.Trading.GetPortfolioInfoEx(accaunts[i].Firmid, myPortfolio.Number, 0).Result; if (qPortfolioEx != null && qPortfolioEx.StartLimitOpenPos != null) { qPortfolio.InAssets = qPortfolioEx.StartLimitOpenPos; } if (qPortfolioEx != null && qPortfolioEx.TotalLimitOpenPos != null) { qPortfolio.Assets = qPortfolioEx.TotalLimitOpenPos; } } if (qPortfolio != null && qPortfolio.InAssets != null) { var begin = qPortfolio.InAssets.Replace('.', separator); myPortfolio.ValueBegin = Convert.ToDecimal(begin.Remove(begin.Length - 4)); } if (qPortfolio != null && qPortfolio.Assets != null) { var current = qPortfolio.Assets.Replace('.', separator); myPortfolio.ValueCurrent = Convert.ToDecimal(current.Remove(current.Length - 4)); } if (qPortfolio != null && qPortfolio.TotalLockedMoney != null) { var blocked = qPortfolio.TotalLockedMoney.Replace('.', separator); myPortfolio.ValueBlocked = Convert.ToDecimal(blocked.Remove(blocked.Length - 4)); } if (qPortfolio != null && qPortfolio.ProfitLoss != null) { var profit = qPortfolio.ProfitLoss.Replace('.', separator); myPortfolio.Profit = Convert.ToDecimal(profit.Remove(profit.Length - 4)); } } if (PortfolioEvent != null) { PortfolioEvent(_portfolios); } } } catch (Exception error) { SendLogMessage(error.ToString(), LogMessageType.Error); } }
internal void setRiskFreeRate(double riskfree) { this.portfInfo = new PortfolioInfo(this.portfInfo, riskfree); this.ChangedFlag = true; }
public Response<Portfolio> AddPortfolioItem(PortfolioInfo portfolio, string itemID) { return this.AddPortfolioItem(portfolio.ID, itemID); }
public Response<Portfolio> DownloadPortfolio(PortfolioInfo portfolio, int viewIndex) { return this.DownloadPortfolio(portfolio.ID, viewIndex); }
public void AddNewUsersShares(PortfolioInfo args) { this.portfolioServices.AddNewUsersShares(args); Logger.Log.Info($"У пользователя новый тип акций {args.ShareId}"); }
public void AddPortfolioItemAsync(PortfolioInfo portfolio, string itemID, object userArgs) { this.AddPortfolioItemAsync(portfolio.ID, itemID, userArgs); }
public void DownloadPortfolioAsync(PortfolioInfo portfolio, int viewIndex, bool dlRealTime, bool dlFundamentals, object userArgs) { if (this.IsLoggedIn) { PortfolioDownload dl = new PortfolioDownload(); dl.Settings.Account = this; dl.Settings.ViewIndex = viewIndex; dl.Settings.PortfolioID = portfolio.ID; dl.Settings.DownloadFundamentalsView = dlFundamentals; dl.Settings.DownloadRealTimeView = dlRealTime; dl.AsyncDownloadCompleted += this.PortfolioDownload_DownloadCompleted; dl.DownloadAsync(userArgs); } else { throw new NotSupportedException("The user is not logged in."); } }
public void DownloadPortfolioAsync(PortfolioInfo portfolio, int viewIndex, object userArgs) { this.DownloadPortfolioAsync(portfolio, viewIndex, false, false, userArgs); }
public static PortfolioInfo Retrieve() { var snapshot = new PortfolioInfo(); FirefoxOptions options = new FirefoxOptions(); options.AddArguments("--headless"); using (var driver = new FirefoxDriver("bin/Debug/netcoreapp2.0/", options)) { var keys = new Keys(); var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); driver.Navigate().GoToUrl("https://login.yahoo.com/?.src=finance&.intl=us&.done=https%3A%2F%2Ffinance.yahoo.com%2Fportfolios&add=1"); var userNameField = driver.FindElementById("login-username"); var userName = keys.Email; userNameField.SendKeys(userName); var nextButton = driver.FindElementById("login-signin"); nextButton.Click(); var loginAvailable = wait.Until(d => d.FindElement(By.Id("login-passwd"))); var userPasswordField = driver.FindElementById("login-passwd"); var password = keys.Password; userPasswordField.SendKeys(password); var loginButton = driver.FindElementById("login-signin"); loginButton.Click(); driver.Navigate().GoToUrl("https://finance.yahoo.com/portfolio/p_0/view/v2"); wait.Until(d => d.FindElement(By.Id("__dialog"))); var closePopup = driver.FindElement(By.XPath("//dialog[@id = '__dialog']/section/button")); closePopup.Click(); var netWorth = driver.FindElement(By.XPath("//*[@id=\"main\"]/section/header/div/div[1]/div/div[2]/p[1]")).Text; string[] dayGain = driver.FindElement(By.XPath("//*[@id=\"main\"]/section/header/div/div[1]/div/div[2]/p[2]/span")).Text.Split(" "); string [] totalGain = driver.FindElement(By.XPath("//*[@id=\"main\"]/section/header/div/div[1]/div/div[2]/p[3]/span")).Text.Split(" "); snapshot.NetWorth = double.Parse(netWorth, NumberStyles.Currency); snapshot.DatePulled = DateTime.Now; snapshot.DayGain = double.Parse(dayGain[0]); snapshot.DayGainPercentage = double.Parse(dayGain[1].TrimStart(new char [] { ' ', '(' }).TrimEnd(new char [] { '%', ' ', ')' })) / 100; snapshot.TotalGain = double.Parse(totalGain[0]); snapshot.TotalGainPercentage = double.Parse(totalGain[1].TrimStart(new char [] { ' ', '(' }).TrimEnd(new char [] { '%', ' ', ')' })) / 100; List <StockInfo> stockDataList = new List <StockInfo>(); // xpath of html table var table = driver.FindElement(By.XPath("//*[@id=\"main\"]/section/section[2]/div[2]/table")); // Fetch all Rows of the table List <IWebElement> tableRows = new List <IWebElement>(table.FindElements(By.TagName("tr"))); List <string> rowDataList = new List <string>(); // Traverse each row foreach (var row in tableRows) { // Fetch the columns from a particuler row List <IWebElement> colsInRow = new List <IWebElement>(row.FindElements(By.TagName("td"))); if (colsInRow.Count > 0) { // Traverse each column and add to rowDataList foreach (var col in colsInRow) { rowDataList.Add(col.Text); } string [] colOne = rowDataList[0].ToString().Split("\n"); string [] colTwo = rowDataList[1].ToString().Split("\n"); string [] colSix = rowDataList[5].ToString().Split("\n"); string [] colSeven = rowDataList[6].ToString().Split("\n"); string [] colEight = rowDataList[7].ToString().Split(" "); stockDataList.Add(new StockInfo() { StockSymbol = colOne[0].ToString(), CurrentPrice = double.Parse(colOne[1].ToString()), PriceChange = double.Parse(colTwo[1]), PriceChangePercentage = double.Parse((colTwo[0]).TrimEnd(new char [] { '%', ' ', ')' })) / 100, Shares = double.Parse(rowDataList[2].ToString()), CostBasis = double.Parse(rowDataList[3].ToString()), MarketValue = double.Parse(rowDataList[4].ToString()), DayGain = double.Parse(colSix[1]), DayGainPercentage = double.Parse((colSix[0]).TrimEnd(new char [] { '%', ' ', ')' })) / 100, TotalGain = double.Parse(colSeven[1]), TotalGainPercentage = double.Parse((colSeven[0]).TrimEnd(new char [] { '%', ' ', ')' })) / 100, Lots = int.Parse(colEight[0]), Notes = rowDataList[8] }); rowDataList.Clear(); } } driver.Quit(); snapshot.StockInfo = stockDataList; return(snapshot); } }
internal void setNumberOfFrontierPoints(int numPoints) { this.portfInfo = new PortfolioInfo(this.portfInfo, nfPoints: numPoints); this.ChangedFlag = true; }
internal void setTargetWeights(double[] w) { this.portfInfo = new PortfolioInfo(weights: w, riskFreerate: this.portfInfo.RiskFreeRate, nfPoints: this.portfInfo.nFrontierPoints); this.ChangedFlag = true; }
public Response<Portfolio> DownloadPortfolio(PortfolioInfo portfolio) { return this.DownloadPortfolio(portfolio, 0); }
public void DownloadPortfolioAsync(PortfolioInfo portfolio, object userArgs) { this.DownloadPortfolioAsync(portfolio, 0, userArgs); }
public static PortfolioInfo Capture() { var capture = new PortfolioInfo(); // // var options = new ChromeOptions(); // options.AddArgument("--disable-gpu"); // creates new chromeDriver and goes to webpage var chromeDriver = new ChromeDriver(@"./"); chromeDriver.Navigate().GoToUrl("https://login.yahoo.com/"); // waits for page to load // chromeDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(14); // login sequence // chromeDriver.FindElementById("uh-signedin").Click(); chromeDriver.FindElementById("login-username").Click(); // chromeDriver.Keyboard.SendKeys(username); chromeDriver.Keyboard.SendKeys(usernamePassword.YahooUsername()); chromeDriver.Keyboard.SendKeys(Keys.Enter); chromeDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); chromeDriver.FindElementById("login-passwd").Click(); // chromeDriver.Keyboard.SendKeys(password1); chromeDriver.Keyboard.SendKeys(usernamePassword.YahooPassword()); chromeDriver.Keyboard.SendKeys(Keys.Enter); //navigate to portfolio with stocks // chromeDriver.Navigate().GoToUrl("https://finance.yahoo.com/portfolios?bypass=true"); // chromeDriver.FindElementById("__dialog").Click(); // chromeDriver.Keyboard.SendKeys(Keys.Escape); //navigate to Jbristol Portfolio chromeDriver.Navigate().GoToUrl("https://finance.yahoo.com/portfolio/p_1/view/v2"); chromeDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); chromeDriver.FindElement(By.Id("__dialog")).Click(); chromeDriver.Keyboard.SendKeys(Keys.Escape); // get currentValue dayGains and totalGain var currentValue = chromeDriver .FindElementByXPath("//*[@id=\"main\"]/section/header/div/div[1]/div/div[2]/p[1]").Text; var dayGain = chromeDriver .FindElementByXPath("//*[@id=\"main\"]/section/header/div/div[1]/div/div[2]/p[2]/span").Text.Split(' '); var totalGain = chromeDriver .FindElementByXPath("//*[@id=\"main\"]/section/header/div/div[1]/div/div[2]/p[3]/span").Text.Split(' '); var dayGainPercent = dayGain[1]; var totalGainPercent = totalGain[1]; capture.CaptureDate = DateTime.Now; capture.PortfolioValue = double.Parse(currentValue, NumberStyles.Currency); capture.DayGain = double.Parse(dayGain[0]); // capture.PercentDayGain = double.Parse(dayGainPercent.Remove(0, 1).Remove(dayGainPercent.Length - 2, dayGainPercent.Length - 1)); capture.PercentDayGain = (double.Parse(dayGainPercent.Trim(new char[] { ' ', '(', '%', ')' })) / 100); capture.TotalGain = double.Parse(totalGain[0]); // capture.PercentTotalGain = double.Parse(totalGainPercent.Remove(0, 1).Remove(dayGainPercent.Length - 2, dayGainPercent.Length - 1)); capture.PercentTotalGain = (double.Parse(totalGainPercent.Trim(new char[] { ' ', '(', '%', ')' })) / 100); // Console.WriteLine( // "currentValue: {0}, dayGain: {1}, totalGain: {2}, dayGainPercent: {3}, totalGainPercent: {4}", // PortfolioValue, DayGain, TotalGain, PercentDayGain, PercentTotalGain); // // scrape symbols var portfolioStockInfo = new List <StockInfo>(); // var table = chromeDriver.FindElement(By.TagName("table")); var table = chromeDriver.FindElement(By.ClassName("tJDbU")); // Console.WriteLine("Table" + table); // var tableRows = table.FindElements(By.TagName("tr")); var tableRows = table.FindElements(By.ClassName("_14MJo")); Console.WriteLine("tablerows" + tableRows.Count); var listRowData = new List <string>(); // each row in the table foreach (var row in tableRows) { var tableColumn = row.FindElements(By.TagName("td")); if (tableColumn.Count > 0) { foreach (var col in tableColumn) { listRowData.Add(col.Text); } var symbolPrice = listRowData[0].Split("\n"); var changePercentDollar = listRowData[1].Split("\n"); var dayGainPercentDollar = listRowData[5].Split("\n"); var totalGainPercentDollar = listRowData[6].Split("\n"); var numLots = listRowData[7].Split(' '); portfolioStockInfo.Add(new StockInfo() { StockSymbol = symbolPrice[0], StockCurrentPrice = symbolPrice[1], StockPriceChange = changePercentDollar[1], StockPriceChangePercent = changePercentDollar[0].Trim(new char[] { ' ', '+', '%' }), StockShares = listRowData[2], StockCostBasis = listRowData[3], StockMarketValue = listRowData[4], StockDayGain = dayGainPercentDollar[1], StockDayGainPercent = dayGainPercentDollar[0].Trim(new char[] { ' ', '+', '%' }), StockTotalGain = totalGainPercentDollar[1], StockTotalGainPercent = totalGainPercentDollar[0].Trim(new char[] { ' ', '+', '%' }), StockLots = numLots[0], StockNotes = listRowData[8] }); foreach (var info in portfolioStockInfo) { Console.WriteLine("Info: " + info); } } Console.WriteLine("going to clear"); listRowData.Clear(); } chromeDriver.Quit(); // Console.WriteLine("portfolioStockInfo: " + portfolioStockInfo); capture.StockInfo = portfolioStockInfo; return(capture); }