示例#1
0
        public List <StockStats> Gainers()
        {
            string            IEXTrading_API_PATH = BASE_URL + "stock/market/list/gainers";
            string            _stocklist          = "";
            List <StockStats> _list = null;
            StocksDetails     sd    = new StocksDetails();

            httpClient.BaseAddress = new Uri(IEXTrading_API_PATH);
            HttpResponseMessage response = httpClient.GetAsync(IEXTrading_API_PATH).GetAwaiter().GetResult();

            if (response.IsSuccessStatusCode)
            {
                _stocklist = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
            }

            if (!_stocklist.Equals(""))
            {
                _list = JsonConvert.DeserializeObject <List <StockStats> >(_stocklist, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });
            }


            return(_list);
        }
示例#2
0
        public StocksDetails ResultsFromAPI(string symbol)
        {
            StocksDetails _cd = new StocksDetails();

            if (symbol != null)
            {
                IEXHandler webHandler = new IEXHandler();
                _cd = webHandler.GetResultsFromAPI(symbol);
            }

            return(_cd);
        }
示例#3
0
        public StocksDetails GetResultsFromAPI(string symbol)
        {
            string        IEXTrading_API_PATH = BASE_URL + "stock/" + symbol + "/stats";
            string        _stocklist          = "";
            StocksDetails sd = new StocksDetails();

            httpClient.BaseAddress = new Uri(IEXTrading_API_PATH);
            HttpResponseMessage response = httpClient.GetAsync(IEXTrading_API_PATH).GetAwaiter().GetResult();

            if (response.IsSuccessStatusCode)
            {
                _stocklist = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
            }

            var jsonObject = (JObject)JsonConvert.DeserializeObject(_stocklist);

            if ((jsonObject.Property("dividendRate") != null) && (!jsonObject.Property("dividendRate").Value.ToString().Equals("")))
            {
                //test = jsonObject.Property("dividendRate").Value.ToString();
                sd.dividendRate = double.Parse(jsonObject.Property("dividendRate").Value.ToString(), CultureInfo.InvariantCulture);
            }

            if ((jsonObject.Property("ytdChangePercent") != null) && (!jsonObject.Property("ytdChangePercent").Value.ToString().Equals("")))
            {
                //test = jsonObject.Property("ytdChangePercent").Value.ToString();
                sd.dividendRate = double.Parse(jsonObject.Property("ytdChangePercent").Value.ToString(), CultureInfo.InvariantCulture);
            }

            if ((jsonObject.Property("grossProfit") != null) && (!jsonObject.Property("grossProfit").Value.ToString().Equals("")))
            {
                //test = jsonObject.Property("grossProfit").Value.ToString();
                sd.dividendRate = double.Parse(jsonObject.Property("grossProfit").Value.ToString(), CultureInfo.InvariantCulture);
            }

            if (jsonObject.Property("companyName") != null)
            {
                //test = jsonObject.Property("companyName").Value.ToString();
                sd.companyName = jsonObject.Property("companyName").Value.ToString();
            }

            sd.symbol = symbol;

            return(sd);
        }
示例#4
0
        public IActionResult TopBuy()
        {
            List <Company> companies = dbContext.Companies.ToList();

            StocksDetails        temp     = new StocksDetails();
            List <StocksDetails> tempList = new List <StocksDetails>();
            List <StocksDetails> _model   = new List <StocksDetails>();

            if (companies != null)
            {
                foreach (var item in companies)
                {
                    temp = ResultsFromAPI(item.symbol);
                    if (temp != null)
                    {
                        tempList.Add(temp);
                    }
                }
            }

            if (tempList.Count != 0)
            {
                _model = tempList.OrderByDescending(x => x.EBITDA).ThenByDescending(x => x.dividendRate).ThenByDescending(x => x.priceToBook).ToList();
            }

            if (_model != null)
            {
                if (_model.Count >= 5)
                {
                    return(View(_model.GetRange(0, 5)));
                }
                else
                {
                    return(View(_model));
                }
            }

            return(View(_model));
        }
        /* Top 5 stocks: We modified the API to extract the list of top 20 stocks which have seen the highest
         * gain i.e. change in price (high - low) . From that list we selected the top 5 stocks which have
         * the higest percent change in price */
        public StocksDetails GetResultsFromAPI(string symbol)
        {
            string IEXTrading_API_PATH = BASE_URL + "stock/" + symbol + "/stats";
            string _stocklist          = "";

            StocksDetails sd = new StocksDetails();

            httpClient.BaseAddress = new Uri(IEXTrading_API_PATH);
            HttpResponseMessage response = httpClient.GetAsync(IEXTrading_API_PATH).GetAwaiter().GetResult();

            if (response.IsSuccessStatusCode)
            {
                _stocklist = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
            }

            var jsonObject = (JObject)JsonConvert.DeserializeObject(_stocklist, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            /*
             * var jsonObject = (JObject)JsonConvert.SerializeObject(_stocklist);
             */

            if (!jsonObject.Property("priceToBook").Value.ToString().Equals(""))
            {
                sd.priceToBook = Convert.ToDecimal(jsonObject.Property("priceToBook").Value.ToString());
            }

            if (!jsonObject.Property("dividendRate").Value.ToString().Equals(""))
            {
                sd.dividendRate = Convert.ToDecimal(jsonObject.Property("dividendRate").Value.ToString());
            }

            /*
             * if (!jsonObject.Property("year1ChangePercent").Value.ToString().Equals(""))
             * {
             *  sd.year1ChangePercent = Convert.ToDecimal(jsonObject.Property("year1ChangePercent").Value.ToString());
             * }
             */
            if (!jsonObject.Property("EBITDA").Value.ToString().Equals(""))
            {
                sd.EBITDA = Convert.ToDecimal(jsonObject.Property("EBITDA").Value.ToString());
            }

            if (!jsonObject.Property("week52high").Value.ToString().Equals(""))
            {
                sd.week52high = Convert.ToDecimal(jsonObject.Property("week52high").Value.ToString());
            }

            if (!jsonObject.Property("week52low").Value.ToString().Equals(""))
            {
                sd.week52low = Convert.ToDecimal(jsonObject.Property("week52low").Value.ToString());
            }

            if (!jsonObject.Property("latestEPS").Value.ToString().Equals(""))
            {
                sd.latestEPS = Convert.ToDecimal(jsonObject.Property("latestEPS").Value.ToString());
            }


            sd.companyName = jsonObject.Property("companyName").Value.ToString();
            sd.symbol      = symbol;

            return(sd);
        }