Exemplo n.º 1
0
        public IActionResult Watchlist(string watchlistname)
        {
            string name  = User?.Identity.Name;
            var    email = HttpContext.User.FindFirst(ClaimTypes.Email)?.Value;


            if (string.IsNullOrEmpty(watchlistname))
            {
                return(new BadRequestResult());
            }
            ObservableCollection <Quote> Quotes = new ObservableCollection <Quote>();

            Watchlist watchlist = Data.MongoDBDataAccess.Watchlist(name, watchlistname);

            if (watchlist == null)
            {
                return(new NoContentResult());
            }
            //Some example tickers
            foreach (Stock ticker in watchlist.Symbols)
            {
                Quotes.Add(new Quote(ticker.ToString()));
            }
            YahooStockEngine.Fetch(Quotes);
            return(new JsonResult(new WatchlistQuote()
            {
                Quotes = Quotes, Watchlist = watchlist
            }));
        }
Exemplo n.º 2
0
        public void ShouldSellInvestment_No_Change()
        {
            // Arrange
            Investment investment = new Investment()
            {
                Symbol        = "BLAH",
                PurchasePrice = 1.0m,
                PurchaseDate  = DateTime.Today
            };
            Quote quote = new Quote()
            {
                Symbol = "BLAH", LastTradePrice = 1.0m
            };

            // Act
            StockEngine engine = new YahooStockEngine();

            foreach (Player player in engine.GetAllPlayers())
            {
                bool shouldSell = player.ShouldSellInvestment(quote, investment);

                // Assert
                Assert.False(shouldSell, "Failed ShouldSellInvestment being false for " + player.Name);
                Assert.IsNull(investment.SellReason, "Failed SellReason being null for " + player.Name);
            }
        }
Exemplo n.º 3
0
        public void ShouldSellInvestment_Low_Price()
        {
            // Arrange
            Investment investment = new Investment()
            {
                Symbol        = "BLAH",
                PurchasePrice = 1.0m,
                PurchaseDate  = DateTime.Today
            };
            Quote quote = new Quote()
            {
                Symbol = "BLAH", LastTradePrice = 0.7m
            };

            // Act
            StockEngine engine = new YahooStockEngine();

            foreach (Player player in engine.GetAllPlayers())
            {
                bool shouldSell = player.ShouldSellInvestment(quote, investment);

                // Assert
                Assert.True(shouldSell, "Failed ShouldSellInvestment being true for " + player.Name);
                Assert.That(investment.SellReason, Is.EqualTo(SellReason.LowPrice), "Failed SellReason being Low for " + player.Name);
            }
        }
Exemplo n.º 4
0
        private void companyListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (companyListBox.SelectedIndex == -1)
            {
            }
            else
            {
                this.detailListBox.Items.Clear();
                stock = bLogic.GetStockInfo(companyListBox.SelectedValue.ToString());

                detailListBox.Items.Add("Symbol: " + stock[0].symbol);
                detailListBox.Items.Add("Name: " + stock[0].name);
                if (stock[0].ipoYear == 0)
                {
                    detailListBox.Items.Add("IPOYear: N/A");
                }
                else
                {
                    detailListBox.Items.Add("IPOYear: " + stock[0].ipoYear);
                }

                stockId = stock[0].id;
                // detailListBox.Items.Add("ID: " + stock[0].id);
                detailListBox.Items.Add("Sector: " + stock[0].sector);
                detailListBox.Items.Add("Industry: " + stock[0].industry);


                List <Quote> quote = new List <Quote>();
                quote.Add(new Quote(stock[0].symbol));
                YahooStockEngine.Fetch(quote);
                foreach (var q in quote)
                {
                    if (q.Ask != null)
                    {
                        stock[0].currentPrice = (double)q.Ask;
                        detailListBox.Items.Add("Current Ask Price: " + stock[0].currentPrice);
                        current_price = System.Convert.ToDouble(q.Ask);
                    }
                    else
                    {
                        stock[0].currentPrice = 0.0;
                        current_price         = 0.0;
                        detailListBox.Items.Add("Current Ask Price: Not available");
                    }
                    if (q.Bid != null)
                    {
                        detailListBox.Items.Add("Current bid: " + q.Bid);
                    }
                    else
                    {
                        detailListBox.Items.Add("Current bid: Not available");
                    }
                    detailListBox.Items.Add("Last Trade Price: " + q.LastTradePrice.ToString());
                    detailListBox.Items.Add("Change in percent: " + q.ChangeInPercent.ToString());
                    detailListBox.Items.Add("Last update time: " + q.LastUpdate.ToString());
                    detailListBox.Items.Add("Earnings for share: " + q.EarningsShare);
                }
            }
            // MessageBox.Show(companyListBox.SelectedValue.ToString());
        }
Exemplo n.º 5
0
        public CardDeckViewModel()
        {
            Quotes = new ObservableCollection <Quote>();

            //Some example tickers
            Quotes.Add(new Quote("AAPL"));
            Quotes.Add(new Quote("MSFT"));
            Quotes.Add(new Quote("INTC"));
            Quotes.Add(new Quote("IBM"));
            Quotes.Add(new Quote("RVBD"));
            Quotes.Add(new Quote("AMZN"));
            Quotes.Add(new Quote("BIDU"));
            Quotes.Add(new Quote("SINA"));
            Quotes.Add(new Quote("THI"));
            Quotes.Add(new Quote("NVDA"));
            Quotes.Add(new Quote("AMD"));
            Quotes.Add(new Quote("DELL"));
            Quotes.Add(new Quote("WMT"));
            Quotes.Add(new Quote("GLD"));
            Quotes.Add(new Quote("SLV"));
            Quotes.Add(new Quote("V"));
            Quotes.Add(new Quote("V"));
            Quotes.Add(new Quote("MCD"));

            //get the data
            YahooStockEngine.Fetch(Quotes);

            //poll every 25 seconds
            timer.Interval = new TimeSpan(0, 0, 25);
            timer.Tick    += (o, e) => YahooStockEngine.Fetch(Quotes);

            timer.Start();
        }
Exemplo n.º 6
0
        public Quote Get(string ticker)
        {
            Quotes = new ObservableCollection <Quote>();

            //Some example tickers
            Quotes.Add(new Quote(ticker + ".AX"));

            YahooStockEngine.Fetch(Quotes);
            return(Quotes[0]);
        }
Exemplo n.º 7
0
        public string GetData(string value)
        {
            ObservableCollection <Quote> Quotes = new ObservableCollection <Quote>();

            Quotes.Add(new Quote(value));
            YahooStockEngine.Fetch(Quotes);
            Quote myQuote = Quotes.First();

            return(string.Format("Value of " + myQuote.Symbol + ": $" + myQuote.LastTradePrice));
        }
        public ActionResult PlayerHistory(string playerName)
        {
            ViewData["PlayerName"] = playerName;

            List <PlayerViewModel>            players     = new List <PlayerViewModel>();
            StockEngine                       engine      = new YahooStockEngine();
            IEnumerable <Investment>          investments = engine.GetInvestmentHistoryForPlayer(playerName);
            IEnumerable <InvestmentViewModel> model       = investments.Select(x => new InvestmentViewModel(x));

            return(View(model));
        }
Exemplo n.º 9
0
        //public IEnumerable<Quote> Get()
        //{
        //    Quotes = new ObservableCollection<Quote>();

        //    //Some example tickers
        //    Quotes.Add(new Quote("FAR.AX"));
        //    Quotes.Add(new Quote("MTS.AX"));
        //    YahooStockEngine.Fetch(Quotes);
        //    return Quotes.AsEnumerable<Quote>();
        //}

        public List <BsonDocument> Get()
        {
            Quotes = new ObservableCollection <Quote>();

            //Some example tickers
            Quotes.Add(new Quote("FAR.AX"));
            Quotes.Add(new Quote("MTS.AX"));
            YahooStockEngine.Fetch(Quotes);
            //return Quotes.AsEnumerable<Quote>();
            return(Data.MongoDBDataAccess.Connect());
        }
        public ActionResult QuoteHistoryForPlayers()
        {
            StockEngine engine = new YahooStockEngine();

            DateTime lastWeek = DateTime.Today.AddDays(-7);
            IEnumerable <QuoteViewModel> model = engine.AllQuotesForPlayersAfter(lastWeek)
                                                 .OrderByDescending(x => x.CreateDate)
                                                 .OrderBy(x => x.Symbol)
                                                 .Select(x => new QuoteViewModel(x));

            return(View(model));
        }
Exemplo n.º 11
0
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage

        static void Main()
        {
            var config = new JobHostConfiguration();

            if (config.IsDevelopment)
            {
                config.UseDevelopmentSettings();
            }
            YahooStockEngine.Fetch();
            //var host = new JobHost();
            // The following code ensures that the WebJob will be running continuously
            //host.RunAndBlock();
        }
Exemplo n.º 12
0
        public void PickRandomSymbol()
        {
            // Arrange
            StockEngine engine = new YahooStockEngine();

            // Act
            IEnumerable <string> symbols = engine.LoadSymbolsFromTextFile("aim.txt");
            string randomSymbol          = engine.PickRandomSymbol(symbols);

            // Assert
            Console.WriteLine("Picked: {0}", randomSymbol);
            Assert.IsNotNullOrEmpty(randomSymbol);
        }
Exemplo n.º 13
0
        public void LookupQuotesForPlayers()
        {
            // Arrange
            StockEngine engine     = new YahooStockEngine();
            decimal     walletSize = 400;

            engine.ReInitializeAllPlayers(walletSize);

            // Act
            IEnumerable <Quote> quotes = engine.LookupQuotesForPlayers(engine.GetAllPlayers().Select(x => x.Name).ToArray());

            // Assert
            Assert.That(quotes.Count(), Is.EqualTo(5));
        }
Exemplo n.º 14
0
        public YahooViewModel()
        {
            Quotes = new ObservableCollection <ObservableQuote>();

            Quotes.Add(new ObservableQuote("AAPL"));
            Quotes.Add(new ObservableQuote("MSFT"));
            Quotes.Add(new ObservableQuote("DELL"));

            YahooStockEngine.Fetch(Quotes);

            timer.Interval = new TimeSpan(0, 0, 5);
            timer.Tick    += (o, e) => YahooStockEngine.Fetch(Quotes);

            timer.Start();
        }
Exemplo n.º 15
0
        private static void Initialize()
        {
            StockEngine engine = new YahooStockEngine();

            engine.ReInitializeAllPlayers(400);
            IEnumerable <Quote> stocks = engine.LookupQuotesForPlayers(engine.GetAllPlayers().Select(x => x.Name).ToArray());

            engine.InsertQuotes(stocks);

            Log.Information("Saved {0} new stock prices to the database.", stocks.Count());
            Log.Information("Initialized all players");

            Console.WriteLine("Saved {0} new stock prices to the database.", stocks.Count());
            Console.WriteLine("Initialized all players");
        }
Exemplo n.º 16
0
        public CardDeckViewModel()
        {
            Quotes = new ObservableCollection <Quote>();

            //Some example tickers
            Quotes.Add(new Quote("KOSPI100.KQ"));

            //get the data
            YahooStockEngine.Fetch(Quotes);

            //poll every 25 seconds
            timer.Interval = new TimeSpan(0, 0, 25);
            timer.Tick    += (o, e) => YahooStockEngine.Fetch(Quotes);

            timer.Start();
        }
Exemplo n.º 17
0
        public void SellInvestment()
        {
            // Arrange
            StockEngine         engine = new YahooStockEngine();
            IEnumerable <Quote> stocks = engine.AllQuotes();

            Investment investment = new Investment()
            {
                Id = Guid.NewGuid()
            };
            decimal newPrice = 1.1m;

            // Act
            engine.SellInvestment(investment.Id, newPrice, SellReason.HighPrice, DateTime.Today);

            // Assert
        }
Exemplo n.º 18
0
        private static void Scan()
        {
            StockEngine engine = new YahooStockEngine();

            IEnumerable <string> symbols = engine.LoadSymbolsFromTextFile("aim.txt");

            //IEnumerable<Quote> stocks = engine.LookupPrices(symbols); // Get everything
            string[] playerNames = engine.GetAllPlayers().Select(x => x.Name).ToArray();

            IEnumerable <Quote> stocks = engine.LookupQuotesForPlayers(playerNames);

            if (stocks.Count() < 1 || stocks.Any(s => s == null))
            {
                // Try Google
                Log.Information("No stocks found - switching to the Google API");
                engine  = new GoogleStockEngine();
                symbols = engine.LoadSymbolsFromTextFile("aim.txt");
                stocks  = engine.LookupQuotesForPlayers(playerNames);
            }

            engine.InsertQuotes(stocks);
            Log.Information("Saved {0} new stock prices to the database.", stocks.Count());

            //
            // Calculate if investments should be sold for each players
            //
            foreach (Player player in engine.GetAllPlayers())
            {
                Quote      quote      = engine.GetCurrentQuoteForPlayer(player.Name);
                Investment investment = engine.GetCurrentInvestmentForPlayer(player.Name);
                if (player.ShouldSellInvestment(quote, investment))
                {
                    // Sell sell sell
                    Log.Information("Selling {0}'s investment in {1} - ({2}) current price is {3}", player.Name, investment.Symbol, investment.SellReason, quote.LastTradePrice.Value);
                    engine.SellInvestment(investment.Id, quote.LastTradePrice.Value, investment.SellReason.Value, DateTime.Now);

                    // Buy buy buy
                    string nextSymbol = engine.PickRandomSymbol(symbols);
                    Quote  nextQuote  = engine.LookupPrice(nextSymbol);
                    engine.InitializePlayer(player, nextQuote, 400);
                    Log.Information("New investment set up for {0}. Bought {1} shares in {2} at price of {3}", player.Name, investment.Quantity, quote.Symbol, quote.LastTradePrice.Value);
                }
            }
        }
        public ActionResult Index()
        {
            List <PlayerViewModel> players = new List <PlayerViewModel>();
            StockEngine            engine  = new YahooStockEngine();

            // Chris
            Player          player     = new Chris();
            Investment      investment = engine.GetCurrentInvestmentForPlayer(player.Name);
            Quote           quote      = engine.GetCurrentQuoteForPlayer(player.Name);
            PlayerViewModel model      = new PlayerViewModel(investment, quote, player);

            players.Add(model);

            // Fiona
            player     = new Fiona();
            investment = engine.GetCurrentInvestmentForPlayer(player.Name);
            quote      = engine.GetCurrentQuoteForPlayer(player.Name);
            model      = new PlayerViewModel(investment, quote, player);
            players.Add(model);

            // Wilson
            player     = new Wilson();
            investment = engine.GetCurrentInvestmentForPlayer(player.Name);
            quote      = engine.GetCurrentQuoteForPlayer(player.Name);
            model      = new PlayerViewModel(investment, quote, player);
            players.Add(model);

            // Katherine
            player     = new Katherine();
            investment = engine.GetCurrentInvestmentForPlayer(player.Name);
            quote      = engine.GetCurrentQuoteForPlayer(player.Name);
            model      = new PlayerViewModel(investment, quote, player);
            players.Add(model);

            // Jon
            player     = new Jon();
            investment = engine.GetCurrentInvestmentForPlayer(player.Name);
            quote      = engine.GetCurrentQuoteForPlayer(player.Name);
            model      = new PlayerViewModel(investment, quote, player);
            players.Add(model);

            return(View(players));
        }
Exemplo n.º 20
0
        public void ReInitializeAllPlayers()
        {
            // Arrange
            StockEngine engine     = new YahooStockEngine();
            decimal     walletSize = 400;

            // Act
            engine.ReInitializeAllPlayers(walletSize);

            // Assert
            List <Investment> investments = engine.GetInvestments().ToList();

            Assert.That(investments.Count, Is.EqualTo(5));
            Assert.NotNull(investments.FirstOrDefault(x => x.PlayerName == "Chris"));
            Assert.NotNull(investments.FirstOrDefault(x => x.PlayerName == "Fiona"));
            Assert.NotNull(investments.FirstOrDefault(x => x.PlayerName == "Wilson"));
            Assert.NotNull(investments.FirstOrDefault(x => x.PlayerName == "Katherine"));
            Assert.NotNull(investments.FirstOrDefault(x => x.PlayerName == "Jon"));
        }
Exemplo n.º 21
0
        public void GetCurrentQuoteForPlayer()
        {
            // Arrange
            StockEngine          engine  = new YahooStockEngine();
            IEnumerable <string> symbols = engine.LoadSymbolsFromTextFile("aim.txt");
            string  randomSymbol         = engine.PickRandomSymbol(symbols);
            Quote   quote      = engine.LookupPrice(randomSymbol);
            decimal walletSize = 400;             // £400

            Player player = new Chris();

            // Act
            engine.InsertQuote(quote);
            engine.InitializePlayer(player, quote, walletSize);
            Quote currentQuote = engine.GetCurrentQuoteForPlayer(player.Name);

            // Assert
            Assert.That(currentQuote.Id, Is.EqualTo(quote.Id));
            Assert.That(currentQuote.Symbol, Is.EqualTo(quote.Symbol));
            Assert.That(currentQuote.LastTradePrice, Is.EqualTo(quote.LastTradePrice));
        }
Exemplo n.º 22
0
        private async void populateWatchListTable()
        {
            DataTable dt = null;


            dt = bLogic.getWatchlistStock(loggedUser.id);
            if (dt.Rows.Count > 0)
            {
                dt.Columns.Add("Current Ask", typeof(System.Double));
                dt.Columns.Add("Current Bid", typeof(System.Double));
                List <Quote> quotes = new List <Quote>();

                foreach (DataRow dr in dt.Rows)
                {
                    quotes.Add(new Quote(dr["Symbol"].ToString()));
                }
                await Task.Run(() => YahooStockEngine.Fetch(quotes));

                //YahooStockEngine.Fetch(quotes);
                int i = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    dr["Current Ask"] = (quotes[i] != null)? ((quotes[i].Ask != null) ? (double)quotes[i].Ask : 0.0): 0.0;
                    dr["Current Bid"] = (quotes[i] != null) ? ((quotes[i].Bid != null) ? (double)quotes[i].Bid : 0.0) : 0.0;
                    i++;
                }

                this.watchlistDataGridView.DataSource = dt;
                this.watchlistDataGridView.Columns["Current Ask"].DefaultCellStyle.Format = "c";
                this.watchlistDataGridView.Columns["Current Bid"].DefaultCellStyle.Format = "c";
                this.watchlistDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                this.watchlistDataGridView.AutoSizeRowsMode    = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;
                this.watchlistDataGridView.AutoResizeColumns();


                populateGraph();
            }
        }
Exemplo n.º 23
0
        public void InitializePlayer()
        {
            // Arrange
            StockEngine          engine  = new YahooStockEngine();
            IEnumerable <string> symbols = engine.LoadSymbolsFromTextFile("aim.txt");
            string  randomSymbol         = engine.PickRandomSymbol(symbols);
            Quote   quote      = engine.LookupPrice(randomSymbol);
            decimal walletSize = 400;             // £400

            Player player = new Chris();

            // Act
            engine.InsertQuote(quote);
            engine.InitializePlayer(player, quote, walletSize);

            // Assert
            Investment investment = engine.GetCurrentInvestmentForPlayer(player.Name);

            Assert.That(investment.Symbol, Is.EqualTo(randomSymbol));
            Assert.That(investment.PlayerName, Is.EqualTo(player.GetType().Name));
            Assert.That(investment.PurchaseDate, Is.GreaterThan(DateTime.Today));
            Assert.That(investment.PurchasePrice, Is.EqualTo(quote.LastTradePrice.Value));
        }
Exemplo n.º 24
0
        public void GetPlayerHistory()
        {
            // Arrange
            StockEngine          engine  = new YahooStockEngine();
            IEnumerable <string> symbols = engine.LoadSymbolsFromTextFile("aim.txt");
            string  randomSymbol         = engine.PickRandomSymbol(symbols);
            decimal walletSize           = 400;

            Player player = new Chris();
            Quote  quote1 = engine.LookupPrice(randomSymbol);

            engine.InitializePlayer(player, quote1, walletSize);

            Quote quote2 = engine.LookupPrice(randomSymbol);

            engine.InitializePlayer(player, quote2, walletSize);

            // Act
            IEnumerable <Investment> investments = engine.GetInvestmentHistoryForPlayer(player.Name);

            // Assert
            Assert.That(investments.Count(), Is.EqualTo(2));
        }
        public static void ScanStocks()
        {
            //Log.Error(typeof(CollectDataManager), "Test 1");
            //Log.Error(typeof(CollectDataManager),"Test tets");
            //Log.Error(typeof(CollectDataManager), "Test tets 123", new Exception("Failed to test"));
            var engine = new YahooStockEngine();

            var quoteList = new ObservableCollection <Quote>();
            var boList    = new List <CompanyList>();

            using (var db = new TheFishEntities())
            {
                boList = db.CompanyLists.Where(x => x.Sector.Equals("Health care", StringComparison.OrdinalIgnoreCase) && x.Symbol.Length < 5).ToList();
            }

            int i = 1;
            var quoteSingleCollectionChunk = new List <Quote>();

            foreach (var item in boList)
            {
                //if (i > 2)
                //    break;
                try
                {
                    var quote = new Quote(item.Symbol.Trim());
                    quoteSingleCollectionChunk.Add(quote);
                    if (i == StockFetchTrunk)
                    {
                        YahooStockEngine.Fetch(quoteSingleCollectionChunk);
                        //YahooStockDownoader.GetQuote(quoteSingleCollectionChunk);
                        foreach (var stockInfo in quoteSingleCollectionChunk)
                        {
                            quoteList.Add(stockInfo);
                        }
                        quoteSingleCollectionChunk = new List <Quote>();
                        i = 1;
                    }
                    i++;
                }catch (Exception ex)
                {
                    var message = ex.Message;
                }
                //i++;
            }

            try
            {
                if (quoteSingleCollectionChunk.Count > 0)
                {
                    YahooStockEngine.Fetch(quoteSingleCollectionChunk);
                    //YahooStockDownoader.GetQuote(quoteSingleCollectionChunk);
                    foreach (var stockInfo in quoteSingleCollectionChunk)
                    {
                        quoteList.Add(stockInfo);
                    }
                }
            }catch (Exception ex)
            {
                var message = ex.Message;
            }

            DateTime today    = DateTime.Today;                 // earliest time today
            DateTime tomorrow = DateTime.Today.AddDays(1);      // earliest time tomorrow

            using (var db = new TheFishEntities())
            {
                foreach (var item in quoteList.ToList())
                {
                    try
                    {
                        var result             = StockAnalyzer.AnalyzeStock(item);
                        var isPriceChangeFish  = result.IsPriceChangedDramatically;
                        var isVolumeChangeFish = result.IsVolumeAbnormal;
                        var isPrice52WeeksLow  = result.IsPrice52WeeksLow;
                        if (!(isPriceChangeFish || isVolumeChangeFish || isPrice52WeeksLow))
                        {
                            continue;
                        }
                        if (
                            db.CaughtFish.Where(
                                x => x.Symbol.Equals(item.Symbol) && x.WhenCreated > today && x.WhenCreated < tomorrow)
                            .Any())
                        {
                            continue;
                        }
                        var caughtFish = new CaughtFish();
                        caughtFish.Symbol                = item.Symbol;
                        caughtFish.WhenCreated           = DateTime.Now;
                        caughtFish.Price                 = item.LastTradePrice;
                        caughtFish.PriceChangePercentage = item.ChangeInPercent;
                        caughtFish.Volume                = item.Volume;
                        if (item.AverageDailyVolume > 0 && item.Volume > 0)
                        {
                            caughtFish.VolumeChangePercentage =
                                (int)(0.5M + 100M * (item.Volume - item.AverageDailyVolume) / item.AverageDailyVolume);
                        }
                        var message = "";
                        var subject = "";
                        if (isPriceChangeFish)
                        {
                            caughtFish.FishType = 0;
                            message             = string.Format(MessageText, "Price Change Alert -- ", caughtFish.Symbol,
                                                                caughtFish.Price.ToString(),
                                                                caughtFish.PriceChangePercentage.ToString(),
                                                                caughtFish.Volume.ToString(), caughtFish.VolumeChangePercentage);
                            subject = " Price Drop Alert -- " + caughtFish.Symbol;
                        }
                        else if (isVolumeChangeFish)
                        {
                            caughtFish.FishType = 1;
                            message             = string.Format(MessageText, "Volume Change Alert -- ", caughtFish.Symbol,
                                                                caughtFish.Price.ToString(),
                                                                caughtFish.PriceChangePercentage.ToString(),
                                                                caughtFish.Volume.ToString(),
                                                                caughtFish.VolumeChangePercentage.ToString());
                            subject = " Volumne Change Alert -- " + caughtFish.Symbol;
                        }
                        else if (isPrice52WeeksLow)
                        {
                            caughtFish.FishType = 1;
                            message             = string.Format(MessageText, "52 Weeks low price Alert -- ", caughtFish.Symbol,
                                                                caughtFish.Price.ToString(),
                                                                caughtFish.PriceChangePercentage.ToString(),
                                                                caughtFish.Volume.ToString(),
                                                                caughtFish.VolumeChangePercentage.ToString());
                            subject = " 52 Weeks Low Alert -- " + caughtFish.Symbol;
                        }
                        db.CaughtFish.Add(caughtFish);
                        db.SaveChanges();
                        Messaging.SendEmailGmail(subject, MessageDetail.GetMessageDetail(item));
                    }
                    catch (Exception ex)
                    {
                        StaticLog.Error(ex);
                    }
                }
            }
        }
Exemplo n.º 26
0
 public void GetQuotes()
 {
     YahooStockEngine.Fetch(Quotes);
 }
Exemplo n.º 27
0
        private async void populateControls(ZedGraphControl zgc)
        {
            /////////////Show the gridView control with verious columns////////////////////
            Double totalInvestment = 0.0;
            Double totalReturn     = 0.0;

            this.mainFormLoadingCircle.Visible = true;
            dt = await Task.Run(() => bLogic.getUserPurchaseTable(loggedUser.userName));

            if (dt.Rows.Count > 0)
            {
                dt.Columns.Add("Total Return", typeof(System.Double));
                dt.Columns.Add("Current Bid", typeof(System.Double));
                dt.Columns.Add("Current Ask", typeof(System.Double));
                List <Quote> quotes = new List <Quote>();

                foreach (DataRow dr in dt.Rows)
                {
                    quotes.Add(new Quote(dr["Symbol"].ToString()));
                }
                await Task.Run(() => YahooStockEngine.Fetch(quotes));

                int    i         = 0;
                double currPrice = 0.0;
                foreach (DataRow dr in dt.Rows)
                {
                    if (quotes != null && quotes[i] != null && quotes[i].Bid != null)
                    {
                        currPrice         = (double)quotes[i].Bid;
                        currPrice        *= System.Convert.ToDouble(dr["Total Stocks"].ToString());
                        dr["Current Bid"] = (double)quotes[i].Bid;
                    }
                    else
                    {
                        currPrice         = System.Convert.ToDouble(dr["Total Investment"]);
                        dr["Current Bid"] = 0.0;
                    }
                    if (quotes != null && quotes[i] != null && quotes[i].Ask != null)
                    {
                        dr["Current Ask"] = (double)quotes[i].Ask;
                    }
                    else
                    {
                        currPrice         = System.Convert.ToDouble(dr["Total Investment"]);
                        dr["Current Ask"] = 0.0;
                    }
                    totalReturn       += currPrice;
                    totalInvestment   += System.Convert.ToDouble(dr["Total Investment"]);
                    dr["Total Return"] = currPrice; //.ToString (String.Format("#.##"));
                    i++;
                }
                this.cashTextBox.Text   = loggedUser.balance.ToString(String.Format("c"));
                this.returnTextBox.Text = totalReturn.ToString(String.Format("c"));
                this.investTextBox.Text = totalInvestment.ToString(String.Format("c"));
                double profitLoss = (totalReturn - totalInvestment);
                this.profitTextBox.Text           = profitLoss.ToString();
                this.stockDataGridView.DataSource = dt;
                this.stockDataGridView.Columns["Total Return"].DefaultCellStyle.Format     = "c";
                this.stockDataGridView.Columns["Current Bid"].DefaultCellStyle.Format      = "c";
                this.stockDataGridView.Columns["Current Ask"].DefaultCellStyle.Format      = "c";
                this.stockDataGridView.Columns["Total Investment"].DefaultCellStyle.Format = "c";
                this.stockDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            } // end of  if (dt.Rows.Count > 0)
            else
            {
                this.cashTextBox.Text   = loggedUser.balance.ToString(String.Format("c"));
                this.returnTextBox.Text = totalReturn.ToString(String.Format("c"));
                this.investTextBox.Text = totalInvestment.ToString(String.Format("c"));
                double profitLoss = (totalReturn - totalInvestment);
                this.profitTextBox.Text           = profitLoss.ToString();
                this.stockDataGridView.DataSource = null;
            }
            /////////////Show the graph control with current selected row from the gridView////////////////////

            populateGraphControl();

            /////////////Show the Pie Chart control with all the stocks////////////////////

            zgc.GraphPane.CurveList.Clear();
            zgc.GraphPane.GraphObjList.Clear();
            GraphPane myPane = zgc.GraphPane;

            // Set the Titles
            myPane.Title.Text = "Total assets distribution for " + loggedUser.firstName + " " + loggedUser.lastName;
            double[] totReturn = new double[dt.Rows.Count];
            String[] companies = new String[dt.Rows.Count];
            int      j         = 0;

            foreach (DataRow dr in dt.Rows)
            {
                totReturn[j] = System.Convert.ToDouble(dr["Total Return"].ToString());
                companies[j] = dr["Name"].ToString();
                j++;
            }
            myPane.AddPieSlices(totReturn, companies);
            // Fill the axis background with a gradient
            myPane.Chart.Fill = new Fill(Color.LightGreen, Color.DeepSkyBlue, 45.0f);
            myPane.Fill       = new Fill(Color.LightGreen);
            //myPane.Legend.Position = LegendPos.Bottom;
            myPane.Legend.IsVisible = false;
            foreach (var x in myPane.CurveList.OfType <PieItem>())
            {
                x.LabelType    = PieLabelType.Name_Percent;
                x.Displacement = x.Value % 0.07;
            }
            zgc.IsShowPointValues = true;
            zgc.AxisChange();
            zgc.Invalidate();
            this.mainFormLoadingCircle.Visible = false;
            return;
        }
Exemplo n.º 28
0
 public void GetHistoricalQuotes(string ticker)
 {
     YahooStockEngine.FetchHistorical(HistoricalQuotes, ticker);
 }