public void Added_And_GetAll_AreEqual() { // fixture unique to this test var portfolioEntryRepositoryFixture = new SqlKataPortfolioEntryRepositoryFixture(); // arrange var portfolioEntry1 = new PortfolioEntry("btc", portfolioEntryRepositoryFixture.DefaultPortfolioId); var portfolioEntry2 = new PortfolioEntry("ada", portfolioEntryRepositoryFixture.DefaultPortfolioId); var portfolioEntry3 = new PortfolioEntry("ltc", portfolioEntryRepositoryFixture.DefaultPortfolioId); // act portfolioEntry1 = portfolioEntry1 with { Id = portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry1) }; portfolioEntry2 = portfolioEntry2 with { Id = portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry2) }; portfolioEntry3 = portfolioEntry3 with { Id = portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry3) }; // assert var loadedPortfolios = portfolioEntryRepositoryFixture.PortfolioEntryRepository.GetAll(); Assert.Equal(3, loadedPortfolios.Count); Assert.Equal(new List <PortfolioEntry> { portfolioEntry1, portfolioEntry2, portfolioEntry3 }, loadedPortfolios); }
/// <summary> /// adds a new <see cref="Row"/> with <paramref name="portfolioEntry"/>'s data to table. /// </summary> /// <seealso cref="PropertyTable.AddRow(PropertyRow)"/> /// <param name="portfolioEntry"></param> public void AddRow(PortfolioEntry portfolioEntry) { PortfolioEntryPropertyRow portfolioEntryPropertyRow = new PortfolioEntryPropertyRow(portfolioEntry); propertyTable.AddRow(portfolioEntryPropertyRow); }
public TransactionEntry AddSymbol(string exchange, string symbol, PortfolioEntry entry) { PositionFeed positionFeed = FinanceService.Query(new PositionQuery(entry.EditUri.Content + FinanceNamespace.POSITIONAPPENDQUERY + Details())); TransactionEntry transactionEntry = new TransactionEntry() { TransactionData = new TransactionData() { Type = TransactionTypes.BUY } }; PositionEntry positionEntry = new PositionEntry() { Symbol = new Symbol() { StockSymbol = symbol, Exchange = exchange } }; Uri uri = new Uri(positionFeed.Feed + "/" + positionEntry.Symbol.Exchange + ":" + positionEntry.Symbol.StockSymbol + "/" + FinanceNamespace.TRANSACTIONS); try { return(FinanceService.Insert(uri, transactionEntry)); } catch (Exception ex) { Console.WriteLine("Exception while trying to add symbol={0} to portfolio={1}", symbol + ":" + exchange, entry.Title.Text); Console.WriteLine("Exception: {0}", ex.Message); return(null); } }
/// <summary> /// <para> /// removes <see cref="Row"/> corresponding to <paramref name="portfolioEntry"/> from /// table, if it exists there. /// </para> /// <para> /// returns whether <see cref="Row"/> corresponding to <paramref name="portfolioEntry"/> existed in table /// prior to being removed. /// </para> /// </summary> /// <param name="portfolioEntry"></param> /// <returns> /// true if <see cref="Row"/> with <paramref name="portfolioEntry"/>'s data existed in table /// prior to being removed, /// else false /// </returns> public bool RemoveRow(PortfolioEntry portfolioEntry) { PortfolioEntryPropertyRow portfolioEntryPropertyRow = new PortfolioEntryPropertyRow(portfolioEntry); return(propertyTable.RemoveRow(portfolioEntryPropertyRow)); }
private bool sufficientFundsForTransactions( PortfolioEntry portfolioEntry, SellTransaction[] sellTransactions, out string lackingExchangeName) { bool sufficientFundsForTransactions = true; lackingExchangeName = null; Dictionary <string, double> exchangeNameToExchangeSellAmount = new Dictionary <string, double>(); foreach (SellTransaction sellTransaction in sellTransactions) { if (!exchangeNameToExchangeSellAmount.ContainsKey(sellTransaction.ExchangeName)) { exchangeNameToExchangeSellAmount[sellTransaction.ExchangeName] = 0; } exchangeNameToExchangeSellAmount[sellTransaction.ExchangeName] += sellTransaction.Amount; } foreach (string exchangeName in exchangeNameToExchangeSellAmount.Keys) { double exchangeSellAmount = exchangeNameToExchangeSellAmount[exchangeName]; if (portfolioEntry.GetCoinHoldings(exchangeName) < exchangeSellAmount) { sufficientFundsForTransactions = false; lackingExchangeName = exchangeName; } } return(sufficientFundsForTransactions); }
/// <summary> /// returns <see cref="PortfolioEntry"/> corresponding to <paramref name="coinId"/>. /// </summary> /// <param name="coinId"></param> /// <returns> /// <see cref="PortfolioEntry"/> corresponding to <paramref name="coinId"/>. /// </returns> /// <exception cref="ManagerNotInitializedException"> /// <seealso cref="assertManagerInitialized(string)"/> /// </exception> /// <exception cref="CoinNotInPortfolioException"> /// <seealso cref="assertCoinInPortfolio(long)"/> /// </exception> /// <exception cref="DatabaseCommunicationException"> /// <seealso cref="GetPortfolioEntry(long)"/> /// </exception> public PortfolioEntry GetPortfolioEntry(long coinId) { assertManagerInitialized("GetPortfolioEntry"); assertCoinInPortfolio(coinId); PortfolioEntry portfolioEntry = null; try { portfolioEntry = PortfolioDatabaseManager.Instance.GetPortfolioEntry(coinId); if (CoinTickerManager.Instance.HasCoinTicker(coinId)) { CoinTicker coinTicker = CoinTickerManager.Instance.GetCoinTicker(coinId); portfolioEntry.SetCoinTicker(coinTicker); } } catch (SQLiteDatabaseHandlerException sqliteDatabaseHandlerException) { handleDatabaseHandlerException("GetPortfolioEntry", sqliteDatabaseHandlerException); } return(portfolioEntry); }
public void AddUpdate_Updates() { // fixture unique to this test var portfolioEntryRepositoryFixture = new SqlKataPortfolioEntryRepositoryFixture(); // arrange var btcEntry = new PortfolioEntry("btc", portfolioEntryRepositoryFixture.DefaultPortfolioId); var ethEntry = new PortfolioEntry("eth", portfolioEntryRepositoryFixture.DefaultPortfolioId); // act int btcId = portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(btcEntry); int ethId = portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(ethEntry); ethEntry = ethEntry with { Id = ethId }; btcEntry = btcEntry with { // update the first entry Id = btcId, // change it's name Symbol = "ltc" }; portfolioEntryRepositoryFixture.PortfolioEntryRepository.Update(btcEntry); Assert.Equal(btcEntry, portfolioEntryRepositoryFixture.PortfolioEntryRepository.Get(btcEntry.Id)); Assert.Equal(ethEntry, portfolioEntryRepositoryFixture.PortfolioEntryRepository.Get(ethEntry.Id)); }
/// <summary> /// Create a portfolio /// </summary> /// <param name="title">Name of the portfolio</param> /// <param name="portfolioData">Settings for the portfolio</param> /// <returns>Returns the response from the server</returns> public PortfolioEntry CreatePortfolio(string title, PortfolioData portfolioData) { // Create a new entry. PortfolioEntry entry = new PortfolioEntry(); // Set the name of the portfolio entry.Title.Text = title; // Set the portfolio data entry.PortfolioData = portfolioData; // Default to USD if (entry.PortfolioData.CurrencyCode.Length == 0) { entry.PortfolioData.CurrencyCode = "USD"; } // Return the response from the server. try { return(FinanceService.Insert(new Uri(FinanceNamespace.PORTFOLIOS), entry)); } catch (GDataRequestException ex) { Console.WriteLine("Unable to create portfolio, Exception: {0}", ex.Message); return(null); } }
public bool DeletePortfolioEntry(PortfolioEntry entry) { // when deleting a portfolio entry make sure to delete all of its orders _marketOrderService.DeletePortfolioEntryOrders(entry.Id); // finally delete the portfolio entry return(_portfolioEntryRepository.Delete(entry)); }
/// <summary> /// returns <see cref="PortfolioEntry"/> section of <see cref="PortfolioEntryPropertyRow"/> /// <see cref="object"/> array. /// </summary> /// <seealso cref="CollectionUtils.DuplicateToArray{T}(T, int)"/> /// <param name="portfolioEntry"></param> /// <returns> /// <see cref="PortfolioEntry"/> section of <see cref="PortfolioEntryPropertyRow"/> /// <see cref="object"/> array. /// </returns> private static PortfolioEntry[] constructPortfolioEntryArray(PortfolioEntry portfolioEntry) { // construct PortfolioEntry array PortfolioEntry[] portfolioEntryArray = CollectionUtils.DuplicateToArray( portfolioEntry, portfolioEntryProperties.Length); return(portfolioEntryArray); }
public TransactionEntry AddSymbol(string fullSymbolName, PortfolioEntry entry) { if (!fullSymbolName.Contains(":")) { return(null); } return(AddSymbol(fullSymbolName.Split(':')[0], fullSymbolName.Split(':')[1], entry)); }
public void CreateFeedEntryTest() { string xml = "<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gf='http://schemas.google.com/finance/2007' xmlns:gd='http://schemas.google.com/g/2005'><id>http://finance.google.com/finance/feeds/[email protected]/portfolios</id><updated>2009-06-27T05:40:34.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/finance/2007#portfolio'/><title type='text'>Portfolio Feed</title><link rel='alternate' type='text/html' href='http://finance.google.com/finance/portfolio?action=view'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios'/><link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios'/><link rel='self' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios?positions=true&returns=true'/><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>1</openSearch:itemsPerPage><entry><id>http://finance.google.com/finance/feeds/[email protected]/portfolios/1</id><updated>2009-06-27T05:40:34.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/finance/2007#portfolio'/><title type='text'>My Portfolio</title><link rel='self' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/1'/><link rel='edit' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/1'/><gd:feedLink href='http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions'><feed><id>http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions</id><updated>2009-06-27T05:40:34.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/finance/2007#position'/><title type='text'>My Portfolio</title><link rel='alternate' type='text/html' href='http://finance.google.com/finance/portfolio?action=view&pid=1'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios'/><openSearch:totalResults>9</openSearch:totalResults><openSearch:itemsPerPage>9</openSearch:itemsPerPage><entry><id>http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NASDAQ:MSFT</id><updated>2009-06-27T05:40:34.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/finance/2007#position'/><title type='text'>Microsoft Corporation</title><link rel='self' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NASDAQ%3AMSFT'/><link rel='edit' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NASDAQ%3AMSFT'/><gd:feedLink href='http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NASDAQ:MSFT/transactions'/><gf:positionData gainPercentage='20.82242991' return1w='0.0' return1y='0.0' return3m='0.0' return3y='0.0' return4w='0.0' return5y='0.0' returnOverall='0.0' returnYTD='0.0' shares='1000.0'><gf:costBasis><gd:money amount='1070.0' currencyCode='USD'/></gf:costBasis><gf:daysGain><gd:money amount='-440.001' currencyCode='USD'/></gf:daysGain><gf:gain><gd:money amount='22280.0' currencyCode='USD'/></gf:gain><gf:marketValue><gd:money amount='23350.0' currencyCode='USD'/></gf:marketValue></gf:positionData><gf:symbol exchange='NASDAQ' fullName='Microsoft Corporation' symbol='MSFT'/></entry><entry><id>http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NASDAQ:AAPL</id><updated>2009-06-27T05:40:34.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/finance/2007#position'/><title type='text'>Apple Inc.</title><link rel='self' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NASDAQ%3AAAPL'/><link rel='edit' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NASDAQ%3AAAPL'/><gd:feedLink href='http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NASDAQ:AAPL/transactions'/><gf:positionData gainPercentage='355.1' return1w='0.02122168053' return1y='355.1' return3m='355.1' return3y='355.1' return4w='355.1' return5y='355.1' returnOverall='355.1' returnYTD='355.1' shares='100.0'><gf:costBasis><gd:money amount='40.0' currencyCode='USD'/></gf:costBasis><gf:daysGain><gd:money amount='258.0002' currencyCode='USD'/></gf:daysGain><gf:gain><gd:money amount='14204.0' currencyCode='USD'/></gf:gain><gf:marketValue><gd:money amount='14244.0' currencyCode='USD'/></gf:marketValue></gf:positionData><gf:symbol exchange='NASDAQ' fullName='Apple Inc.' symbol='AAPL'/></entry><entry><id>http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NASDAQ:ACAS</id><updated>2009-06-27T05:40:34.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/finance/2007#position'/><title type='text'>American Capital Ltd.</title><link rel='self' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NASDAQ%3AACAS'/><link rel='edit' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NASDAQ%3AACAS'/><gd:feedLink href='http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NASDAQ:ACAS/transactions'/><gf:positionData gainPercentage='0.1045296167' return1w='0.0' return1y='0.0' return3m='0.0' return3y='0.0' return4w='0.0' return5y='0.0' returnOverall='0.0' returnYTD='0.0' shares='10000.0'><gf:costBasis><gd:money amount='28700.0' currencyCode='USD'/></gf:costBasis><gf:daysGain><gd:money amount='4500.0' currencyCode='USD'/></gf:daysGain><gf:gain><gd:money amount='3000.0' currencyCode='USD'/></gf:gain><gf:marketValue><gd:money amount='31700.0' currencyCode='USD'/></gf:marketValue></gf:positionData><gf:symbol exchange='NASDAQ' fullName='American Capital Ltd.' symbol='ACAS'/></entry><entry><id>http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NYSE:ING</id><updated>2009-06-27T05:40:34.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/finance/2007#position'/><title type='text'>ING Groep N.V. (ADR)</title><link rel='self' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NYSE%3AING'/><link rel='edit' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NYSE%3AING'/><gd:feedLink href='http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NYSE:ING/transactions'/><gf:positionData gainPercentage='0.05503634476' return1w='0.0' return1y='0.0' return3m='0.0' return3y='0.0' return4w='0.0' return5y='0.0' returnOverall='0.0' returnYTD='0.0' shares='124.0'><gf:costBasis><gd:money amount='1194.12' currencyCode='USD'/></gf:costBasis><gf:daysGain><gd:money amount='-2.48' currencyCode='USD'/></gf:daysGain><gf:gain><gd:money amount='65.72' currencyCode='USD'/></gf:gain><gf:marketValue><gd:money amount='1259.84' currencyCode='USD'/></gf:marketValue></gf:positionData><gf:symbol exchange='NYSE' fullName='ING Groep N.V. (ADR)' symbol='ING'/></entry><entry><id>http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NASDAQ:FORTY</id><updated>2009-06-27T05:40:34.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/finance/2007#position'/><title type='text'>Formula Systems (1985) Ltd. (ADR)</title><link rel='self' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NASDAQ%3AFORTY'/><link rel='edit' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NASDAQ%3AFORTY'/><gd:feedLink href='http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NASDAQ:FORTY/transactions'/><gf:positionData gainPercentage='0.03818953324' return1w='0.0' return1y='0.0' return3m='0.0' return3y='0.0' return4w='0.0' return5y='0.0' returnOverall='0.0' returnYTD='0.0' shares='130.0'><gf:costBasis><gd:money amount='919.1' currencyCode='USD'/></gf:costBasis><gf:daysGain><gd:money amount='17.55' currencyCode='USD'/></gf:daysGain><gf:gain><gd:money amount='35.1' currencyCode='USD'/></gf:gain><gf:marketValue><gd:money amount='954.2' currencyCode='USD'/></gf:marketValue></gf:positionData><gf:symbol exchange='NASDAQ' fullName='Formula Systems (1985) Ltd. (ADR)' symbol='FORTY'/></entry><entry><id>http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NYSE:DT</id><updated>2009-06-27T05:40:34.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/finance/2007#position'/><title type='text'>Deutsche Telekom AG (ADR)</title><link rel='self' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NYSE%3ADT'/><link rel='edit' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NYSE%3ADT'/><gd:feedLink href='http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NYSE:DT/transactions'/><gf:positionData gainPercentage='0.01224846894' return1w='0.0' return1y='0.0' return3m='0.0' return3y='0.0' return4w='0.0' return5y='0.0' returnOverall='0.0' returnYTD='0.0' shares='242.0'><gf:costBasis><gd:money amount='2766.06' currencyCode='USD'/></gf:costBasis><gf:daysGain><gd:money amount='14.519758' currencyCode='USD'/></gf:daysGain><gf:gain><gd:money amount='33.88' currencyCode='USD'/></gf:gain><gf:marketValue><gd:money amount='2799.94' currencyCode='USD'/></gf:marketValue></gf:positionData><gf:symbol exchange='NYSE' fullName='Deutsche Telekom AG (ADR)' symbol='DT'/></entry><entry><id>http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NYSE:CHN</id><updated>2009-06-27T05:40:34.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/finance/2007#position'/><title type='text'>China Fund Inc. (The)</title><link rel='self' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NYSE%3ACHN'/><link rel='edit' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NYSE%3ACHN'/><gd:feedLink href='http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NYSE:CHN/transactions'/><gf:positionData gainPercentage='0.03348104382' return1w='0.0' return1y='0.0' return3m='0.0' return3y='0.0' return4w='0.0' return5y='0.0' returnOverall='0.0' returnYTD='0.0' shares='244.0'><gf:costBasis><gd:money amount='4955.64' currencyCode='USD'/></gf:costBasis><gf:daysGain><gd:money amount='7.320244' currencyCode='USD'/></gf:daysGain><gf:gain><gd:money amount='165.92' currencyCode='USD'/></gf:gain><gf:marketValue><gd:money amount='5121.56' currencyCode='USD'/></gf:marketValue></gf:positionData><gf:symbol exchange='NYSE' fullName='China Fund Inc. (The)' symbol='CHN'/></entry><entry><id>http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NYSE:FTE</id><updated>2009-06-27T05:40:34.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/finance/2007#position'/><title type='text'>France Telecom SA (ADR)</title><link rel='self' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NYSE%3AFTE'/><link rel='edit' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NYSE%3AFTE'/><gd:feedLink href='http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NYSE:FTE/transactions'/><gf:positionData gainPercentage='0.02424786709' return1w='0.0' return1y='0.0' return3m='0.0' return3y='0.0' return4w='0.0' return5y='0.0' returnOverall='0.0' returnYTD='0.0' shares='420.0'><gf:costBasis><gd:money amount='9353.4' currencyCode='USD'/></gf:costBasis><gf:daysGain><gd:money amount='-42.0' currencyCode='USD'/></gf:daysGain><gf:gain><gd:money amount='226.8' currencyCode='USD'/></gf:gain><gf:marketValue><gd:money amount='9580.2' currencyCode='USD'/></gf:marketValue></gf:positionData><gf:symbol exchange='NYSE' fullName='France Telecom SA (ADR)' symbol='FTE'/></entry><entry><id>http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NYSE:GNK</id><updated>2009-06-27T05:40:34.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/finance/2007#position'/><title type='text'>Genco Shipping & Trading Limited</title><link rel='self' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NYSE%3AGNK'/><link rel='edit' type='application/atom+xml' href='http://finance.google.com/finance/feeds/default/portfolios/NYSE%3AGNK'/><gd:feedLink href='http://finance.google.com/finance/feeds/[email protected]/portfolios/1/positions/NYSE:GNK/transactions'/><gf:positionData gainPercentage='0.1024649589' return1w='0.0' return1y='0.0' return3m='0.0' return3y='0.0' return4w='0.0' return5y='0.0' returnOverall='0.0' returnYTD='0.0' shares='10.0'><gf:costBasis><gd:money amount='206.9' currencyCode='USD'/></gf:costBasis><gf:daysGain><gd:money amount='14.69999' currencyCode='USD'/></gf:daysGain><gf:gain><gd:money amount='21.2' currencyCode='USD'/></gf:gain><gf:marketValue><gd:money amount='228.1' currencyCode='USD'/></gf:marketValue></gf:positionData><gf:symbol exchange='NYSE' fullName='Genco Shipping & Trading Limited' symbol='GNK'/></entry></feed></gd:feedLink><gf:portfolioData currencyCode='USD' gainPercentage='0.8135848188' return1w='0.02122168053' return1y='355.1' return3m='355.1' return3y='355.1' return4w='355.1' return5y='355.1' returnOverall='355.1' returnYTD='355.1'><gf:costBasis><gd:money amount='49205.22' currencyCode='USD'/></gf:costBasis><gf:daysGain><gd:money amount='4327.609192' currencyCode='USD'/></gf:daysGain><gf:gain><gd:money amount='40032.62' currencyCode='USD'/></gf:gain><gf:marketValue><gd:money amount='140032.62' currencyCode='USD'/></gf:marketValue></gf:portfolioData></entry></feed>"; PortfolioFeed target = Parse(xml); for (int i = 0; i < target.Entries.Count; i++) { PortfolioEntry portfolioEntry = target.Entries[i] as PortfolioEntry; Console.WriteLine("Title: " + portfolioEntry.Title.Text); Console.WriteLine("FeedLink: " + portfolioEntry.FeedLink.ToString()); Console.WriteLine("CurrencyCode: " + portfolioEntry.CurrencyCode); Console.WriteLine("GainPercentage: " + portfolioEntry.GainPercentage.ToString("0.00000000%")); Console.WriteLine("Return1Week: " + portfolioEntry.Return1Week.ToString("0.00000000%")); Console.WriteLine("Return4Week: " + portfolioEntry.Return4Week.ToString("0.00000000%")); Console.WriteLine("Return3Month: " + portfolioEntry.Return3Month.ToString("0.00000000%")); Console.WriteLine("ReturnYTD: " + portfolioEntry.ReturnYTD.ToString("0.00000000%")); Console.WriteLine("Return1Year: " + portfolioEntry.Return1Year.ToString("0.00000000%")); Console.WriteLine("Return3Year: " + portfolioEntry.Return3Year.ToString("0.00000000%")); Console.WriteLine("Return5Year: " + portfolioEntry.Return5Year.ToString("0.00000000%")); Console.WriteLine("ReturnOverall: " + portfolioEntry.ReturnOverall.ToString("0.00000000%")); CostBasis costBasis = portfolioEntry.CostBasis; foreach (Money m in costBasis.Money) { Console.WriteLine("Money: Amount = " + m.Amount as string); Console.WriteLine("Money: CurrencyCode = " + m.CurrencyCode); } DaysGain daysGain = portfolioEntry.DaysGain; foreach (Money m in daysGain.Money) { Console.WriteLine("Money: Amount = " + m.Amount as string); Console.WriteLine("Money: CurrencyCode = " + m.CurrencyCode); } Gain gain = portfolioEntry.Gain; foreach (Money m in gain.Money) { Console.WriteLine("Money: Amount = " + m.Amount as string); Console.WriteLine("Money: CurrencyCode = " + m.CurrencyCode); } MarketValue marketValue = portfolioEntry.MarketValue; foreach (Money m in marketValue.Money) { Console.WriteLine("Money: Amount = " + m.Amount as string); Console.WriteLine("Money: CurrencyCode = " + m.CurrencyCode); } } }
public PortfolioEntry CreatePortfolioEntry(string symbol, int portfolioId) { // create a new instance of the `PortfolioEntry` class var portfolioEntry = new PortfolioEntry(symbol, portfolioId); // add it to the repository and return it with the generated ID return(portfolioEntry with { Id = _portfolioEntryRepository.Add(portfolioEntry) }); }
// TODO: add the detailed query here also. public Dictionary <string, PositionEntry> RetrieveSymbols(PortfolioEntry entry) { PositionFeed positionFeed = FinanceService.Query(new PositionQuery(entry.EditUri.Content + FinanceNamespace.POSITIONAPPENDQUERY + Details())); Dictionary <string, PositionEntry> symbols = new Dictionary <string, PositionEntry>(); foreach (PositionEntry positionEntry in positionFeed.Entries) { symbols.Add(positionEntry.Symbol.Exchange + ":" + positionEntry.Symbol.StockSymbol, positionEntry); } return(symbols); }
public void Add_ReturnsNonZeroId() { // arrange var portfolioEntry = new PortfolioEntry("btc", _portfolioEntryRepositoryFixture.DefaultPortfolioId); // act int id = _portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry); // assert Assert.True(id > 0); }
/// <summary> /// performs a sell transaction. /// </summary> /// <seealso cref="PortfolioEntry.Sell(SellTransaction)"/> /// <param name="sellTransaction"></param> /// <exception cref="ManagerNotInitializedException"> /// <seealso cref="GetPortfolioEntry(int)"/> /// </exception> /// <exception cref="CoinNotInPortfolioException"> /// <seealso cref="GetPortfolioEntry(long)"/> /// </exception> /// <exception cref="InvalidPriceException"> /// <seealso cref="PortfolioEntry.Sell(SellTransaction)"/> /// </exception> /// <exception cref="InsufficientFundsException"> /// <seealso cref="PortfolioEntry.Sell(SellTransaction)"/> /// </exception> /// <exception cref="DatabaseCommunicationException"> /// <seealso cref="GetPortfolioEntry(long)"/> /// <seealso cref="handleDatabaseHandlerException(string, SQLiteDatabaseHandlerException)"/> /// </exception> public void SellCoin(SellTransaction sellTransaction) { PortfolioEntry portfolioEntry = GetPortfolioEntry(sellTransaction.CoinId); try { portfolioEntry.Sell(sellTransaction); } catch (SQLiteDatabaseHandlerException sqliteDatabaseHandlerException) { handleDatabaseHandlerException("SellCoin", sqliteDatabaseHandlerException); } }
/// <summary> /// returns <see cref="CoinTicker"/> section of <see cref="PortfolioEntryPropertyRow"/> /// <see cref="object"/> array. /// </summary> /// <seealso cref="CollectionUtils.DuplicateToArray{T}(T, int)"/> /// <param name="portfolioEntry"></param> /// <returns> /// <see cref="CoinTicker"/> section of <see cref="PortfolioEntryPropertyRow"/> /// <see cref="object"/> array. /// </returns> private static CoinTicker[] constructCoinTickerArray(PortfolioEntry portfolioEntry) { // if coin ticker is not available, its properties are displaye as 'N\A' CoinTicker coinTicker = CoinTickerManager.Instance.HasCoinTicker(portfolioEntry.CoinId) ? CoinTickerManager.Instance.GetCoinTicker(portfolioEntry.CoinId) : null; // construct coin ticker array CoinTicker[] coinTickerArray = CollectionUtils.DuplicateToArray( coinTicker, COIN_TICKER_PROPERTIES.Length); return(coinTickerArray); }
/// <summary> /// returns <see cref="PortfolioEntryPropertyRow"/> <see cref="object"/> array. /// </summary> /// <param name="portfolioEntry"></param> /// <returns> /// row <see cref="object"/> array /// </returns> /// <seealso cref="constructCoinDataArray(PortfolioEntry)"/> /// <seealso cref="constructCoinTickerArray(PortfolioEntry)"/> /// <seealso cref="constructPortfolioEntryArray(PortfolioEntry)"/> private static object[] constructObjectArray(PortfolioEntry portfolioEntry) { CoinData[] coinDataArray = constructCoinDataArray(portfolioEntry); CoinTicker[] coinTickerArray = constructCoinTickerArray(portfolioEntry); PortfolioEntry[] portfolioEntryArray = constructPortfolioEntryArray(portfolioEntry); // merge CoinData, CoinTicker, PortfolioEntry arrays together object[] objectArray = CollectionUtils.MergeToArray <object>( coinDataArray, coinTickerArray, portfolioEntryArray); return(objectArray); }
/// <summary> /// performs a buy transaction for coin having <paramref name="buyTransaction"/>.CoinId. /// </summary> /// <seealso cref="PortfolioEntry.Buy(Transaction)"/> /// <param name="buyTransaction"></param> /// <exception cref="ManagerNotInitializedException"> /// <seealso cref="GetPortfolioEntry(long)"/> /// </exception> /// <exception cref="CoinNotInPortfolioException"> /// <seealso cref="GetPortfolioEntry(long)"/> /// </exception> /// <exception cref="InvalidPriceException"> /// <seealso cref="PortfolioEntry.Buy(Transaction))"/> /// </exception> /// <exception cref="DatabaseCommunicationException"> /// <seealso cref="handleDatabaseHandlerException(string, SQLiteDatabaseHandlerException)"/> /// </exception> public void BuyCoin(BuyTransaction buyTransaction) { assertManagerInitialized("BuyCoin"); PortfolioEntry portfolioEntry = GetPortfolioEntry(buyTransaction.CoinId); try { portfolioEntry.Buy(buyTransaction); } catch (SQLiteDatabaseHandlerException sqliteDatabaseHandlerException) { handleDatabaseHandlerException("BuyCoin", sqliteDatabaseHandlerException); } }
/// <summary> /// returns <see cref="CoinData"/> section of <see cref="PortfolioEntryPropertyRow"/> /// <see cref="object"/> array. /// </summary> /// <seealso cref="CollectionUtils.DuplicateToArray{T}(T, int)"/> /// <param name="portfolioEntry"></param> /// <returns> /// <see cref="CoinData"/> section of <see cref="PortfolioEntryPropertyRow"/> /// <see cref="object"/> array. /// </returns> private static CoinData[] constructCoinDataArray(PortfolioEntry portfolioEntry) { // get coin listing corresponding to PortfolioEntry coin id CoinListing coinListing = CoinListingManager.Instance.GetCoinListing(portfolioEntry.CoinId); // create a corresponding CoinData object CoinData coinData = new CoinData(coinListing); // construct CoinData array CoinData[] coinDataArray = CollectionUtils.DuplicateToArray( coinData, COIN_DATA_PROPERTIES.Length); return(coinDataArray); }
public void Get_CallsRepository() { // arrange var portfolioEntryPresentInRepository = new PortfolioEntry("btc", 1); var repositoryMock = new Mock <IPortfolioEntryRepository>(); var marketOrderServiceMock = new Mock <IMarketOrderService>(); repositoryMock.Setup(x => x.Get(It.Is <int>(id => id == 1))).Returns(portfolioEntryPresentInRepository); var service = new PortfolioEntryServiceImpl(repositoryMock.Object, marketOrderServiceMock.Object); // act var portfolioEntry = service.GetPortfolioEntry(1); // assert Assert.Equal(portfolioEntryPresentInRepository, portfolioEntry); }
public void Update_CallsRepository() { // arrange var entryToBeUpdated = new PortfolioEntry("btc", 1, 1); var repositoryMock = new Mock <IPortfolioEntryRepository>(); var marketOrderServiceMock = new Mock <IMarketOrderService>(); repositoryMock.Setup(x => x.Update(It.IsAny <PortfolioEntry>())).Returns(true); var service = new PortfolioEntryServiceImpl(repositoryMock.Object, marketOrderServiceMock.Object); // act var updated = service.UpdatePortfolioEntry(entryToBeUpdated); // assert Assert.True(updated); }
public void Delete_CallsRepository_And_MarketOrderService() { // arrange var entryToBeDeleted = new PortfolioEntry("btc", 1, 1); var repositoryMock = new Mock <IPortfolioEntryRepository>(); var marketOrderServiceMock = new Mock <IMarketOrderService>(); repositoryMock.Setup(x => x.Delete(It.IsAny <PortfolioEntry>())).Returns(true); var service = new PortfolioEntryServiceImpl(repositoryMock.Object, marketOrderServiceMock.Object); // act var delete = service.DeletePortfolioEntry(entryToBeDeleted); // assert marketOrderServiceMock.Verify(x => x.DeletePortfolioEntryOrders(It.Is <int>(id => id == entryToBeDeleted.Id))); Assert.True(delete); }
/// <summary> /// returns string representation of portfolio in tabular format, /// containing data of <see cref="PortfolioEntry"/>s with specified <paramref name="coinIds"/>. /// </summary> /// <param name="coinIds"></param> /// <returns> /// string representation of portfolio in tabular format, /// containing data of <see cref="PortfolioEntry"/>s with specified <paramref name="coinIds"/>. /// </returns> /// <exception cref="ManagerNotInitializedException"> /// <seealso cref="GetPortfolioEntry(long)"/> /// </exception> /// <exception cref="CoinNotInPortfolioException"> /// <seealso cref="GetPortfolioEntry(long)"/> /// </exception> /// <exception cref="DatabaseCommunicationException"> /// <seealso cref="GetPortfolioEntry(long)"/> /// </exception> public string GetPortfolioEntryDisplayTableString(params long[] coinIds) { // init portfolio entry table PortfolioEntryTable portfolioEntryTable = new PortfolioEntryTable(); foreach (long coinId in coinIds) { // add row corresponding to each portfolio entry associated with specified id PortfolioEntry portfolioEntry = GetPortfolioEntry(coinId); portfolioEntryTable.AddRow(portfolioEntry); } // return table display string string portfolioEntryTableString = portfolioEntryTable.GetTableDisplayString(); return(portfolioEntryTableString); }
public void DeletePortfolioEntries_Deletes_Correct_Entries() { // fixture unique to this test var portfolioEntryRepositoryFixture = new SqlKataPortfolioEntryRepositoryFixture(); // arrange var portfolioEntry1 = new PortfolioEntry("btc", portfolioEntryRepositoryFixture.DefaultPortfolioId); var portfolioEntry2 = new PortfolioEntry("ada", portfolioEntryRepositoryFixture.DefaultPortfolioId); var portfolioEntry3 = new PortfolioEntry("ltc", portfolioEntryRepositoryFixture.DefaultPortfolioId); var portfolioEntry4 = new PortfolioEntry("btc", portfolioEntryRepositoryFixture.SecondaryPortfolioId); var portfolioEntry5 = new PortfolioEntry("eth", portfolioEntryRepositoryFixture.SecondaryPortfolioId); // act portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry1); portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry2); portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry3); portfolioEntry4 = portfolioEntry4 with { Id = portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry4) }; portfolioEntry5 = portfolioEntry5 with { Id = portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry5) }; portfolioEntryRepositoryFixture.PortfolioEntryRepository.DeletePortfolioEntries( portfolioEntryRepositoryFixture.DefaultPortfolioId); // assert Assert.Empty(portfolioEntryRepositoryFixture.PortfolioEntryRepository.GetAllByPortfolioId(portfolioEntryRepositoryFixture.DefaultPortfolioId)); var loadedPortfoliosSecondaryPortfolio = portfolioEntryRepositoryFixture.PortfolioEntryRepository.GetAllByPortfolioId( portfolioEntryRepositoryFixture.SecondaryPortfolioId); Assert.Equal(2, loadedPortfoliosSecondaryPortfolio.Count); Assert.Equal(new List <PortfolioEntry> { portfolioEntry4, portfolioEntry5 }, loadedPortfoliosSecondaryPortfolio); } } }
public void Added_And_Get_AreEqual() { // arrange var portfolioEntry = new PortfolioEntry("btc", _portfolioEntryRepositoryFixture.DefaultPortfolioId); // act int id = _portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry); portfolioEntry = portfolioEntry with { Id = id }; // assert Assert.True(id > 0); Assert.Equal(portfolioEntry, _portfolioEntryRepositoryFixture.PortfolioEntryRepository.Get(portfolioEntry.Id)); }
public void Create_CallsRepository() { // arrange var portfolioEntryToBeAdded = new PortfolioEntry("btc", 1); var repositoryMock = new Mock <IPortfolioEntryRepository>(); var marketOrderServiceMock = new Mock <IMarketOrderService>(); repositoryMock.Setup(x => x.Add(It.Is <PortfolioEntry>(portfolioEntry => portfolioEntry == portfolioEntryToBeAdded))).Returns(1); var service = new PortfolioEntryServiceImpl(repositoryMock.Object, marketOrderServiceMock.Object); // act var portfolioEntry = service.CreatePortfolioEntry("btc", 1); // assert Assert.Equal(portfolioEntryToBeAdded with { Id = 1 }, portfolioEntry); }
public void Delete_Deletes() { // arrange var firstEntry = new PortfolioEntry("btc", _portfolioEntryRepositoryFixture.DefaultPortfolioId); var secondEntry = new PortfolioEntry("ltc", _portfolioEntryRepositoryFixture.DefaultPortfolioId); // act firstEntry = firstEntry with { Id = _portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(firstEntry) }; secondEntry = secondEntry with { Id = _portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(secondEntry) }; _portfolioEntryRepositoryFixture.PortfolioEntryRepository.Delete(firstEntry); // assert Assert.Null(_portfolioEntryRepositoryFixture.PortfolioEntryRepository.Get(firstEntry.Id)); Assert.Equal(secondEntry, _portfolioEntryRepositoryFixture.PortfolioEntryRepository.Get(secondEntry.Id)); Assert.Single(_portfolioEntryRepositoryFixture.PortfolioEntryRepository.GetAll()); }
static void Main(string[] args) { // File name of csv file. string csvFileName; // temp string for reading from the console. string s; // xelement document to store the csv file in. XElement xmlDoc = null; string portfolioName; int portfolioIndex; // Temporary portfolio entry PortfolioEntry portfolioEntry; TransactionEntry transactionEntry; Dictionary <string, PositionEntry> symbols; string fullSymbolName; string user; string password; if (ConfigurationSettings.AppSettings["Username"] == "" || ConfigurationSettings.AppSettings["Password"] == "") { Console.Write("Enter google username: "******"Enter google password: "******"Username"]; password = ConfigurationSettings.AppSettings["Password"]; } //if (ConfigurationSettings.AppSettings["ProxyServer"] != "" && ConfigurationSettings.AppSettings["ProxyPort"] != "") //{ // Uri proxyUri = new Uri(ConfigurationSettings.AppSettings["ProxyServer"] + ":" + ConfigurationSettings.AppSettings["ProxyPort"]); // WebProxy webProxy = new WebProxy(proxyUri); // webProxy.BypassProxyOnLocal = true; // System.Net.GlobalProxySelection.Select = webProxy; //} //else //{ // System.Net.GlobalProxySelection.Select = null; //} GoogleFinanceManager googleFinanceManager = new GoogleFinanceManager(user, password); bool consoleRunning = true; while (consoleRunning) { Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Enter following keys to test each funtion."); Console.WriteLine("========================================================"); Console.WriteLine("'L' = Load SP500.csv file"); Console.WriteLine("'C' = Create portfolio with the loaded .csv file with blank transactions"); Console.WriteLine("'c' = Create a portfolio"); Console.WriteLine("'a' = Add a stock to a portfolio"); Console.WriteLine("'r' = Remove a stock from a portfolio"); Console.WriteLine("'p' = Portfolios Details"); Console.WriteLine("'P' = Portfolio Stocks Details"); Console.WriteLine("'l' = List Portfolios"); Console.WriteLine("'s' = List Stocks from a portfolio"); Console.WriteLine("'D' = Delete Portfolio"); Console.WriteLine("'X' = Exit Program"); Console.WriteLine("========================================================"); Console.WriteLine(); Console.WriteLine(); ConsoleKeyInfo keyInfo = Console.ReadKey(true); switch (keyInfo.KeyChar) { #region 'L' Load csv file case 'L': Console.WriteLine("Enter .csv file name or just use default: [SP500.csv]"); s = Console.ReadLine(); csvFileName = (s == "" ? "sp500.csv" : s); try { xmlDoc = new XElement("Root", File.ReadAllLines("sp500.csv").Select ( line => { var split = line.CsvSplit(); return(new XElement("Stock", new XElement("Ticker", split[0]), new XElement("Stock_Name", split[1]), new XElement("Sector_code", split[2]), new XElement("Sector_Name", split[3]), new XElement("Industry_Group_Code", split[4]), new XElement("Industry_Group_Name", split[5]), new XElement("Industry_Code", split[6]), new XElement("Industry_Name", split[7]), new XElement("Sub_Ind_Code", split[8]), new XElement("Sub_Ind_Name", split[9]) )); } )); } catch (Exception ex) { Console.WriteLine("Exception Parsing the .csv file: ", ex.Message); } break; #endregion #region 'C' Create portfolio with loaded .csv file case 'C': if (xmlDoc == null) { Console.WriteLine("Please load the .csv file first with 'L' command"); break; } // User enters name. Console.WriteLine("Enter the portfolio name: [SP500] "); s = Console.ReadLine(); portfolioName = (s == "" ? "SP500" : s); // TODO: fix up the variable names. get rid of the code outside of this while loop // Create the portfolio portfolioEntry = googleFinanceManager.CreatePortfolio(portfolioName); Func <XElement, TransactionEntry> anonFunc = delegate(XElement el) { string sym = el.Value; YahooHelper y = new YahooHelper(sym); string exc = y.Quote["stock_exchange"]; return(googleFinanceManager.AddSymbol(exc, sym, portfolioEntry)); }; var q = from v in xmlDoc.Elements("Stock") select v; List <TransactionEntry> transactions = new List <TransactionEntry>(); foreach (XElement elx in q.Elements("Ticker")) { transactions.Add(anonFunc(elx)); } break; #endregion #region 'D' Delete portolios case 'D': Console.WriteLine("Enter portfolio name or leave blank to delete all portfolios: "); s = Console.ReadLine(); if (s == "") { // Delete all the portfolios. if (googleFinanceManager.DeleteAllPortfolios()) { Console.WriteLine("All portfolios were deleted"); } else { Console.WriteLine("There was a problem with googleFinanceManager, not all portfolios were deleted."); } } else { // Delete indivual stock. if (!googleFinanceManager.DeletePortfolio(s)) { Console.WriteLine("Portfolio was not deleted, no title with the name {0}", s); } else { Console.WriteLine("Portfolio was deleted: {0}", s); } } break; #endregion #region 'c' Create a portfolio case 'c': Console.WriteLine("Enter the portfolio name: [My Example Portfolio] "); s = Console.ReadLine(); if (s == "") { Console.WriteLine("Portfolio Not Created"); break; } else { portfolioName = s; } // Create the portfolio portfolioEntry = googleFinanceManager.CreatePortfolio(portfolioName); if (portfolioEntry != null) { Console.WriteLine("Portfolio Created = {0}", portfolioEntry.Title.Text); } else { Console.WriteLine("googleFinanceManager.CreatePortfolio return null, Portfolio not created"); } break; #endregion #region 'a' Add a stock to a portfolio case 'a': // Print out a list of portfolios to choose from portfolioIndex = 0; foreach (string t in googleFinanceManager.PortfolioNames) { Console.WriteLine("[{0}] {1}", portfolioIndex++, t); } // ask user to input which they would like to select. Console.WriteLine("Choose a portfolio to add a symbol too: [0] "); s = Console.ReadLine(); s = (s == ""?"0":s); portfolioIndex = int.Parse(s); // ask user if they would like to create a transaction or a simple add. Console.WriteLine("Would you like to create a transaction for this symbol: [y/n]"); s = Console.ReadLine(); if ((s == "" ? "n" : s) == "y") { TransactionDataArgs transactionDataArgs = new TransactionDataArgs() { TransactionType = TransactionTypes.BUY, Price = 0.0f, Commission = 0.0f, Notes = "blahblah", Date = DateTime.Now, Shares = 100.00 }; // Create transaction Console.WriteLine("Enter the full symbol name exchange:symbol: [NASDAQ:GOOG] "); // TODO: need to implement the buying and selling of stock, not just adding it to a portfolio. fullSymbolName = Console.ReadLine(); Console.WriteLine("Enter the type of transaction [0] Buy, [2] Buy to Cover, [3] Sell, [4] Sell Short: [0]"); s = Console.ReadLine(); s = (s == "" ? "0" : s); switch (int.Parse(s)) { case 0: transactionDataArgs.TransactionType = TransactionTypes.BUY; break; case 1: transactionDataArgs.TransactionType = TransactionTypes.BUYTOCOVER; break; case 2: transactionDataArgs.TransactionType = TransactionTypes.SELL; break; case 3: transactionDataArgs.TransactionType = TransactionTypes.SELLSHORT; break; } Console.WriteLine("Enter the price to purchase the stock: [10.95]"); s = Console.ReadLine(); s = (s == "" ? "10.95" : s); transactionDataArgs.Price = float.Parse(s); Console.WriteLine("Enter the price of commission: [10.95]"); s = Console.ReadLine(); s = (s == "" ? "10.95" : s); transactionDataArgs.Commission = float.Parse(s); Console.WriteLine("Enter some notes about this purchase: [Going to make money on this stock]"); s = Console.ReadLine(); s = (s == "" ? "Going to make money on this stock" : s); Console.WriteLine("What date did you purchase this stock: [Today]"); s = Console.ReadLine(); try { transactionDataArgs.Date = DateTime.Parse(s); } catch (Exception) { transactionDataArgs.Date = DateTime.Now; } Console.WriteLine("How many shares do you want to purchase: [100] "); s = Console.ReadLine(); s = (s == "" ? "100" : s); transactionDataArgs.Shares = double.Parse(s); Console.WriteLine("Enter Currency Code: [USD] "); s = Console.ReadLine(); s = (s == "" ? "USD" : s); transactionDataArgs.CurrencyCode = s; transactionEntry = googleFinanceManager.AddSymbol(fullSymbolName, transactionDataArgs, googleFinanceManager.Portfolios[googleFinanceManager.PortfolioNames[portfolioIndex]]); if (transactionEntry != null) { Console.WriteLine("Symbol={0} has successfully been added to Portfolio={1}", fullSymbolName, transactionEntry.Title.Text); Console.WriteLine("Type={0}, Date={1}, Shares={2}, Notes={3}, Commission={4}, Price={5}", transactionDataArgs.TransactionType, transactionDataArgs.Date, transactionDataArgs.Shares, transactionDataArgs.Notes, transactionDataArgs.Commission, transactionDataArgs.Price); } } else { // add symbol to that list. Console.WriteLine("Enter the full symbol name exchange:symbol: [NASDAQ:GOOG] "); s = Console.ReadLine(); fullSymbolName = s; transactionEntry = googleFinanceManager.AddSymbol(fullSymbolName, googleFinanceManager.PortfolioNames[portfolioIndex]); if (transactionEntry != null) { Console.WriteLine("Symbol={0} has successfully been added to Portfolio={1}", fullSymbolName, transactionEntry.Title.Text); } } break; #endregion #region 'r' Remove a stock from a portfolio case 'r': // Print out a list of portfolios to choose from portfolioIndex = 0; foreach (string t in googleFinanceManager.PortfolioNames) { Console.WriteLine("[{0}] {1}", portfolioIndex++, t); } // ask user to input which they would like to select. Console.WriteLine("Choose a portfolio to delete a symbol from: [0] "); s = Console.ReadLine(); s = (s == "" ? "0" : s); portfolioIndex = int.Parse(s); string symbolRemove; symbols = googleFinanceManager.RetrieveSymbols(googleFinanceManager.PortfolioNames[portfolioIndex]); foreach (var sym in symbols) { Console.WriteLine("[{0}]", sym.Key); } Console.WriteLine("Choose a symbol to delete: [] "); s = Console.ReadLine(); symbolRemove = s; googleFinanceManager.DeleteSymbol(symbols[symbolRemove]); break; #endregion #region 'p' Portfolio Details case 'p': googleFinanceManager.PortfolioDetails = true; googleFinanceManager.PositionDetails = true; googleFinanceManager.TransactionDetails = true; foreach (var portfolio in googleFinanceManager.Portfolios) { Console.WriteLine(); Console.WriteLine("Portfolio Name: {0}", portfolio.Key); Console.WriteLine("CurrencyCode: {0}", portfolio.Value.CurrencyCode); Console.WriteLine("GainPercentage: {0}", portfolio.Value.GainPercentage); Console.WriteLine("Return1Week: {0}", portfolio.Value.Return1Week); Console.WriteLine("Return4Week: {0}", portfolio.Value.Return4Week); Console.WriteLine("Return3Month: {0}", portfolio.Value.Return3Month); Console.WriteLine("ReturnYTD: {0}", portfolio.Value.ReturnYTD); Console.WriteLine("Return1Year: {0}", portfolio.Value.Return1Year); Console.WriteLine("Return3Year: {0}", portfolio.Value.Return3Year); Console.WriteLine("Return5Year: {0}", portfolio.Value.Return5Year); Console.WriteLine("ReturnOverall: {0}", portfolio.Value.ReturnOverall); Console.WriteLine("CostBasis: "); if (portfolio.Value.CostBasis != null) { foreach (var m in portfolio.Value.CostBasis.Money) { Console.WriteLine("\tAmount={0:c}", m.Amount); Console.WriteLine("\tAmount={0}\n", m.CurrencyCode); } } Console.WriteLine("DaysGain:"); if (portfolio.Value.DaysGain != null) { foreach (var m in portfolio.Value.DaysGain.Money) { Console.WriteLine("\tAmount={0:c}", m.Amount); Console.WriteLine("\tAmount={0}\n", m.CurrencyCode); } } Console.WriteLine("Gain:"); if (portfolio.Value.Gain != null) { foreach (var m in portfolio.Value.Gain.Money) { Console.WriteLine("\tAmount={0:c}", m.Amount); Console.WriteLine("\tAmount={0}\n", m.CurrencyCode); } } Console.WriteLine("MarketValue:"); if (portfolio.Value.MarketValue != null) { foreach (var m in portfolio.Value.MarketValue.Money) { Console.WriteLine("\tAmount={0:c}", m.Amount); Console.WriteLine("\tAmount={0}\n", m.CurrencyCode); } } Console.WriteLine(); Console.WriteLine(); } break; #endregion #region 'P' Stock Details case 'P': googleFinanceManager.PortfolioDetails = true; googleFinanceManager.PositionDetails = true; googleFinanceManager.TransactionDetails = true; portfolioIndex = 0; foreach (string t in googleFinanceManager.PortfolioNames) { Console.WriteLine("[{0}] {1}", portfolioIndex++, t); } Console.WriteLine("Choose a portfolio to print details of there stocks: [0] "); s = Console.ReadLine(); s = (s == "" ? "0" : s); portfolioIndex = int.Parse(s); symbols = googleFinanceManager.RetrieveSymbols(googleFinanceManager.PortfolioNames[portfolioIndex]); Console.WriteLine("Portfolio Name: {0}", googleFinanceManager.PortfolioNames[portfolioIndex]); foreach (var sym in symbols) { Console.WriteLine(); Console.WriteLine("TransactionHerf: {0}", sym.Value.TransactionHerf); Console.WriteLine("Symbol.FullName: {0}", sym.Value.Symbol.FullName); Console.WriteLine("Symbol.Exchange: {0}", sym.Value.Symbol.Exchange); Console.WriteLine("Symbol.StockSymbol: {0}", sym.Value.Symbol.StockSymbol); Console.WriteLine("DaysGain:"); if (sym.Value.DaysGain != null) { foreach (var m in sym.Value.DaysGain.Money) { Console.WriteLine("\tAmount={0:c}", m.Amount); Console.WriteLine("\tAmount={0}\n", m.CurrencyCode); } } Console.WriteLine("CostBasis: "); if (sym.Value.CostBasis != null) { foreach (var m in sym.Value.CostBasis.Money) { Console.WriteLine("\tAmount={0:c}", m.Amount); Console.WriteLine("\tAmount={0}\n", m.CurrencyCode); } } Console.WriteLine("Gain:"); if (sym.Value.Gain != null) { foreach (var m in sym.Value.Gain.Money) { Console.WriteLine("\tAmount={0:c}", m.Amount); Console.WriteLine("\tAmount={0}\n", m.CurrencyCode); } } Console.WriteLine("MarketValue:"); if (sym.Value.MarketValue != null) { foreach (var m in sym.Value.MarketValue.Money) { Console.WriteLine("\tAmount={0:c}", m.Amount); Console.WriteLine("\tAmount={0}\n", m.CurrencyCode); } } Console.WriteLine("GainPercentage: {0}", sym.Value.GainPercentage); Console.WriteLine("Return1Week: {0}", sym.Value.Return1Week); Console.WriteLine("Return4Week: {0}", sym.Value.Return4Week); Console.WriteLine("Return3Month: {0}", sym.Value.Return3Month); Console.WriteLine("ReturnYTD: {0}", sym.Value.ReturnYTD); Console.WriteLine("Return1Year: {0}", sym.Value.Return1Year); Console.WriteLine("Return3Year: {0}", sym.Value.Return3Year); Console.WriteLine("Return5Year: {0}", sym.Value.Return5Year); Console.WriteLine("ReturnOverall: {0}", sym.Value.ReturnOverall); Console.WriteLine("Shares: {0}", sym.Value.Shares); Console.WriteLine(); } break; #endregion #region 'l' List Portfolios case 'l': Console.WriteLine("Printing Portfolios"); googleFinanceManager.PortfolioNames.ForEach(n => Console.WriteLine("Name: {0}", n)); break; #endregion #region 's' List Stocks from a portfolio case 's': // Print out a list of portfolios to choose from portfolioIndex = 0; foreach (string t in googleFinanceManager.PortfolioNames) { Console.WriteLine("[{0}] {1}", portfolioIndex++, t); } // ask user to input which they would like to select. Console.WriteLine("Choose a portfolio to add a symbol too: [0] "); s = Console.ReadLine(); s = (s == "" ? "0" : s); portfolioIndex = int.Parse(s); PortfolioEntry entry = googleFinanceManager.Portfolios[googleFinanceManager.PortfolioNames[portfolioIndex]]; var stockKeys = googleFinanceManager.RetrieveSymbols(entry).Keys; foreach (var v in stockKeys) { Console.WriteLine("Ticker Symbol: {0}", v); } break; #endregion #region 'X' Exit Program case 'X': Console.WriteLine("Exiting SP500 Program"); return; #endregion } } }
public void GetAllByPortfolioId_Returns_Correct_Entries() { // fixture unique to this test var portfolioEntryRepositoryFixture = new SqlKataPortfolioEntryRepositoryFixture(); // arrange var portfolioEntry1 = new PortfolioEntry("btc", portfolioEntryRepositoryFixture.DefaultPortfolioId); var portfolioEntry2 = new PortfolioEntry("ada", portfolioEntryRepositoryFixture.DefaultPortfolioId); var portfolioEntry3 = new PortfolioEntry("ltc", portfolioEntryRepositoryFixture.DefaultPortfolioId); var portfolioEntry4 = new PortfolioEntry("btc", portfolioEntryRepositoryFixture.SecondaryPortfolioId); var portfolioEntry5 = new PortfolioEntry("eth", portfolioEntryRepositoryFixture.SecondaryPortfolioId); // act var presumablyEmptyList = portfolioEntryRepositoryFixture.PortfolioEntryRepository.GetAllByPortfolioId( portfolioEntryRepositoryFixture.DefaultPortfolioId); var presumablyEmptyList2 = portfolioEntryRepositoryFixture.PortfolioEntryRepository.GetAllByPortfolioId( portfolioEntryRepositoryFixture.SecondaryPortfolioId); portfolioEntry1 = portfolioEntry1 with { Id = portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry1) }; portfolioEntry2 = portfolioEntry2 with { Id = portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry2) }; portfolioEntry3 = portfolioEntry3 with { Id = portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry3) }; portfolioEntry4 = portfolioEntry4 with { Id = portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry4) }; portfolioEntry5 = portfolioEntry5 with { Id = portfolioEntryRepositoryFixture.PortfolioEntryRepository.Add(portfolioEntry5) }; // assert var loadedPortfolios = portfolioEntryRepositoryFixture.PortfolioEntryRepository.GetAllByPortfolioId( portfolioEntryRepositoryFixture.DefaultPortfolioId); Assert.Empty(presumablyEmptyList); Assert.Empty(presumablyEmptyList2); Assert.Equal(new List <PortfolioEntry> { portfolioEntry1, portfolioEntry2, portfolioEntry3 }, loadedPortfolios); var loadedPortfoliosSecondaryPortfolio = portfolioEntryRepositoryFixture.PortfolioEntryRepository.GetAllByPortfolioId( portfolioEntryRepositoryFixture.SecondaryPortfolioId); Assert.Equal(2, loadedPortfoliosSecondaryPortfolio.Count); Assert.Equal(new List <PortfolioEntry> { portfolioEntry4, portfolioEntry5 }, loadedPortfoliosSecondaryPortfolio); }