Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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));
        }
Exemplo n.º 5
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.º 6
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());
        }
Exemplo n.º 7
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.º 8
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.º 9
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.º 10
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.º 11
0
 public void GetQuotes()
 {
     YahooStockEngine.Fetch(Quotes);
 }
Exemplo n.º 12
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;
        }
        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);
                    }
                }
            }
        }