예제 #1
0
        static void Main(string[] args)
        {
            TransactionRecord              transactionRecord = new TransactionRecord();
            Stock                          stock             = new Stock();
            AddStockInfo                   addStockInfo      = new AddStockInfo();
            JsonDownloader                 jsonDownloader    = new JsonDownloader();
            List <DailyStockRecord>        dailyRecordList   = new List <DailyStockRecord>();
            DailyStockRecord               dailyStockRecord  = new DailyStockRecord();
            Calculations                   calculations      = new Calculations();
            DownloadStockHistoricalRecords downloadStockHistoricalRecords = new DownloadStockHistoricalRecords();
            UserInterface                  userInterface      = new UserInterface();
            UserAccountCreator             userAccountCreator = new UserAccountCreator();
            UserLoggin                     userLoggin         = new UserLoggin();
            List <Portfolio>               portfolioList      = new List <Portfolio>();
            Portfolio                      portfolio          = new Portfolio();
            User           user           = new User();
            ProgramContext programContext = new ProgramContext()

            {
                TransactionRecord = transactionRecord,
                Stock             = stock,
                AddStockInfo      = addStockInfo,
                JsonDownloader    = jsonDownloader,
                DailyRecordList   = dailyRecordList,
                DailyStockRecord  = dailyStockRecord,
                Calculations      = calculations,
                DownloadStockHistoricalRecords = downloadStockHistoricalRecords,
                UserInterface      = userInterface,
                UserAccountCreator = userAccountCreator,
                PortfolioList      = portfolioList,
                Portfolio          = portfolio,
                UserLoggin         = userLoggin,
                User          = user,
                SourceFile1   = @"c:\users\jflem\source\repos\stockportfolio\stockportfolio\companylist1.txt",
                SourceFile2   = @"c:\users\jflem\source\repos\stockportfolio\stockportfolio\companylist2.txt",
                SourceFile3   = @"c:\users\jflem\source\repos\stockportfolio\stockportfolio\companylist3.txt",
                SourceFileKey = @"C:\Users\jflem\Documents\Notepadstuff\alphavantageapikey.txt"
            };

            programContext.AlphaVantageKey = File.ReadAllText(@"C:\Users\jflem\Documents\Notepadstuff\alphavantageapikey.txt");



            // test section



            //Console.ReadLine();
            // end test section

            userInterface.StartUpOptions(programContext);
        }
예제 #2
0
        public void BuySellStock(ProgramContext programContext)
        {
            string            portfolioName;
            int               portfolioID;
            TransactionRecord transactionToBeAdded = new TransactionRecord();
            decimal           transactionFees      = 0;
            decimal           price;
            DateTime          dateTime;
            decimal           quantity;
            string            symbol;
            string            tempStockID;

            Console.WriteLine("Please enter the symbol for the stock you would like to buy or sell");
            symbol = Console.ReadLine();

            Console.WriteLine("Please enter the name of the portfolio this stock is in");
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("StockPortfolio")))
            {
                var tempPortfolioList = connection.Query <Portfolio>(
                    $@"declare @UserAcctID int
set @UserAcctID = '{programContext.User.AcctID}'
select *
from Portfolio
where AcctID = @UserAcctID").ToList();

                foreach (Portfolio portfolio in tempPortfolioList)
                {
                    Console.WriteLine(portfolio.PortfolioName);
                }
            }
            portfolioName = Console.ReadLine();

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("StockPortfolio")))
            {
                portfolioID = connection.QuerySingle <int>(
                    $@"declare @PortfolioName nvarchar(max) = '{portfolioName}'
Select PortfolioID
from Portfolio
where PortfolioName = @PortfolioName");
            }

            Console.WriteLine("Please enter the quantity of share you would like to buy or sell");
            Console.WriteLine("use a - sign to indicate selling");
            quantity = Convert.ToDecimal(Console.ReadLine());

            Console.WriteLine("Please enter the date the stock was bought or sold.  Use year,Month,Day format");
            dateTime = Convert.ToDateTime(Console.ReadLine());

            Console.WriteLine("Please enter the price you bought or sold the shares for");
            price = Convert.ToDecimal(Console.ReadLine());

            transactionToBeAdded.TransactionFees = this.TransactionFeeSelector(programContext, transactionFees, price, quantity);

            transactionToBeAdded.PortfolioID = portfolioID;
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("StockPortfolio")))
            {
                tempStockID = connection.QuerySingle <string>(
                    $@"Declare @symbol nvarchar(10) = '{symbol}'
Select StockID
from Stock
where Symbol = @symbol");
            }

            transactionToBeAdded.StockID  = Convert.ToInt32(tempStockID);
            transactionToBeAdded.DateTime = dateTime;
            transactionToBeAdded.Price    = price;
            transactionToBeAdded.Quantity = quantity;

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("StockPortfolio")))
            {
                connection.Query(
                    $@"Declare @PortfolioID int = '{transactionToBeAdded.PortfolioID}',
@StockID int = '{transactionToBeAdded.StockID}',
@DateTime DateTime = '{transactionToBeAdded.DateTime}',
@Price decimal(18,6) = '{transactionToBeAdded.Price}',
@Quantity decimal(18,6) = '{transactionToBeAdded.Quantity}',
@Fees decimal(18,6) = '{transactionToBeAdded.TransactionFees}',
@TransactionFee decimal(18,6) = '{transactionToBeAdded.TransactionFees}'
Insert Into TransactionRecord (StockID, DateTime, Price, Quantity, Fees, PortfolioID)
values (@StockID, @DateTime, @Price, @Quantity, @Fees, @PortfolioID)");
            }
        }