public TransactionEntry AddSymbol(string exchange, string symbol, TransactionDataArgs args, PortfolioEntry entry) { PositionFeed positionFeed = FinanceService.Query(new PositionQuery(entry.EditUri.Content + FinanceNamespace.POSITIONAPPENDQUERY + Details())); TransactionEntry transactionEntry = new TransactionEntry() { TransactionData = new TransactionData() { Type = args.TransactionType, Date = args.Date.ToString(), Shares = args.Shares, Notes = args.Notes, Commission = new Commission(), Price = new Price() } }; PositionEntry positionEntry = new PositionEntry() { Symbol = new Symbol() { StockSymbol = symbol, Exchange = exchange } }; transactionEntry.TransactionData.Commission.Money.Add(new Money() { Amount = args.Commission, CurrencyCode= args.CurrencyCode }); transactionEntry.TransactionData.Price.Money.Add(new Money() { Amount = args.Price, CurrencyCode= args.CurrencyCode }); 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} and transaction: ", positionEntry.Symbol.Exchange + ":" + positionEntry.Symbol.StockSymbol, entry.Title.Text); Console.WriteLine("Type={0}, Date={1}, Shares={2}, Notes={3}, Commission={4}, Price={5}", transactionEntry.TransactionData.Type, transactionEntry.TransactionData.Date, transactionEntry.TransactionData.Shares, transactionEntry.TransactionData.Notes, transactionEntry.TransactionData.Commission, transactionEntry.TransactionData.Price); Console.WriteLine("Exception: {0}", ex.Message); return null; } }
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; } }