public void When_YSQ_Can_Not_Find_Quote_Then_Service_Discards_Quote() { // setup dynamic googQuote = new ExpandoObject(); googQuote.Symbol = "\"GOOG\""; googQuote.LatestTradePrice = "657.73"; dynamic bjtQuote = new ExpandoObject(); bjtQuote.Symbol = "\"BJT\""; bjtQuote.LatestTradePrice = "N/A"; _ysqMock.Setup(m => m.Quote(It.IsAny <string[]>())).Returns(_ysqfMock.Object); _ysqfMock.Setup(m => m.Return(It.IsAny <QuoteReturnParameter[]>())).Returns(new[] { googQuote, bjtQuote }); // execute var service = new YahooStockService(_qsfMock.Object); var quotes = service.GetQuotes(new[] { new Security { Symbol = "GOOG" }, new Security { Symbol = "BJT" } }); // verify Assert.That(quotes.Count, Is.EqualTo(1)); var verify = quotes.Single(); Assert.That(verify.Key, Is.EqualTo("GOOG")); Assert.That(verify.Value, Is.EqualTo(657.73M)); }
public void Test() { var portfolio = new Portfolio { Name = "Test Portfolio" }; using (var tokenManager = new QuestradeApiTokenManager(new Configuration())) { var api = new QuestradeService(tokenManager, new InMemorySecurityRepository(), new InMemoryCategoryRepository()); portfolio.Accounts = api.GetAccounts(); foreach (var account in portfolio.Accounts) { account.Positions = api.GetPositions(account); account.Transactions = api.GetTransactions(account, new DateTime(2008, 1, 1), DateTime.Now); } } var quoter = new YahooStockService(new YahooServiceFactory()); var reporter = new StringValueReporter(quoter); var report = reporter.GetReport(portfolio); Console.Out.Write(report); }
private static ErrorCode QuestradeMonthReportOperation(string portfolioName) { var portfolio = new Portfolio { Name = portfolioName }; using (var tokenManager = new QuestradeApiTokenManager(Configuration)) { var api = new QuestradeService(tokenManager, new InMemorySecurityRepository(), new InMemoryCategoryRepository()); portfolio.Accounts = api.GetAccounts(); foreach (var account in portfolio.Accounts) { account.Positions = api.GetPositions(account); } var service = new YahooStockService(new YahooServiceFactory()); var reporter = new StringHistoricalReporter(service); var startDate = GetStartOfMarketWeek(DateTime.Now); var report = reporter.GetReport(portfolio, startDate.AddMonths(-1), startDate, Period.Weekly); Console.Write(report); } return(ErrorCode.NoError); }
private static ErrorCode QuickFundbotValueReportOperation(string portfolioName) { var dataDir = Path.GetFullPath(Environment.ExpandEnvironmentVariables(Configuration.DataDirectoryPath)); if (!Directory.Exists(dataDir)) { Console.Error.WriteLine("Data directory at {0} does not exist.", dataDir); return(ErrorCode.DirectoryMissing); } var fundbotBuysFile = Path.Combine(dataDir, "buys.csv"); if (!File.Exists(fundbotBuysFile)) { Console.Error.WriteLine("Fundbot file at {0} does not exist.", fundbotBuysFile); return(ErrorCode.FileMissing); } var factory = new DataImporterFactory(); var fundBotImporter = factory.GetFundbotTransactions(fundbotBuysFile); var transactions = fundBotImporter.GetTransactions(); var account = new Account { Name = portfolioName }; var portfolio = new Portfolio { Name = portfolioName, Accounts = new List <Account> { account } }; account.Portfolio = portfolio; foreach (var transaction in transactions) { transaction.Account = account; } var portfolioService = new PortfolioService(portfolio); portfolioService.UpdateWith(transactions); var quoter = new YahooStockService(new YahooServiceFactory()); var reporter = new StringValueReporter(quoter); var report = reporter.GetReport(portfolio); Console.Write(report); return(ErrorCode.NoError); }
private static ErrorCode DefaultOperation() { var dataDir = Path.GetFullPath(Environment.ExpandEnvironmentVariables(Configuration.DataDirectoryPath)); if (!Directory.Exists(dataDir)) { Console.Error.WriteLine("Data directory at {0} does not exist.", dataDir); return(ErrorCode.DirectoryMissing); } var portfolioFile = Path.Combine(dataDir, "portfolio.js"); if (!File.Exists(portfolioFile)) { Console.Error.WriteLine("Portfolio file at {0} does not exist.", portfolioFile); return(ErrorCode.FileMissing); } var portfolioFileContents = File.ReadAllText(portfolioFile, Encoding.UTF8); var portfolio = JsonConvert.DeserializeObject <Portfolio>(portfolioFileContents); var categoriesFile = Path.Combine(dataDir, "categories.js"); if (!File.Exists(categoriesFile)) { Console.Error.WriteLine("Categories file at {0} does not exist.", categoriesFile); return(ErrorCode.FileMissing); } var categoryFileContents = File.ReadAllText(categoriesFile, Encoding.UTF8); var categories = JsonConvert.DeserializeObject <IEnumerable <Category> >(categoryFileContents); var quoter = new YahooStockService(new YahooServiceFactory()); var reporter = new StringValueReporter(quoter); var report = reporter.GetReport(portfolio); Console.Write(report); return(ErrorCode.NoError); }