public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            var quoteMaker = new QuoteMaker(new InvestipsQuoteBuilder());

            var httpClient = GetHttpClient();

            var symbols = await GetStockSymbols(httpClient);

            foreach (var symbol in symbols)
            {
                var history = await Yahoo.GetHistoricalAsync(symbol, new DateTime(2018, 1, 1), DateTime.Now, Period.Daily);

                quoteMaker.BuildQuote(history, symbol);
                var quote = quoteMaker.GetQuotes();
            }

            var quoteService  = new QuoteService();
            var historyQuotes = await quoteService.GetHistoricalQuotes();



            var mvAvgs10Info = GetMovingAveragesByPeriod(historyQuotes, 10);

            log.Info("C# HTTP trigger function processed a request.");


            // parse query parameter
            string name = req.GetQueryNameValuePairs()
                          .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
                          .Value;

            if (name == null)
            {
                // Get request body
                dynamic data = await req.Content.ReadAsAsync <object>();

                name = data?.name;
            }

            using (var db = new InvestipsQuotesContext())
            {
                db.Quotes.Add(new Quote {
                    Symbol = "AAPL", Open = 100, High = 103, Low = 99, Close = 102, TimeStampDateTime = DateTime.Now
                });
                await db.SaveChangesAsync();

                log.Info("Quote Created");
            }

            return(name == null
                ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
                : req.CreateResponse(HttpStatusCode.OK, "Hello " + name));
        }
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")]
                                              HttpRequestMessage req, TraceWriter log)
        {
            List <Quote> quotes = new List <Quote>();

            using (var db = new InvestipsQuotesContext())
            {
                quotes = db.Quotes.Where(q => q.IsSuperGapBear == true)
                         .OrderByDescending(q => q.TimeStampDateTime).ToList();
            }

            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(JsonConvert.SerializeObject(quotes.Select(q => q.Symbol).Distinct().ToList()), Encoding.UTF8,
                                            "application/json")
            });
        }
Exemple #3
0
        public static SignalMarks GetBullStoch307(string symbol)
        {
            var          marks  = new SignalMarks();
            List <Quote> quotes = new List <Quote>();

            using (var db = new InvestipsQuotesContext())
            {
                quotes = db.Quotes.Where(
                    q => q.IsStoch101Cossing20Up &&
                    q.IsPriceCrossMovAvg7Up &&
                    q.IsMovingAvg30PointingUp &&
                    q.Symbol == symbol
                    ).ToList();
            }


            if (quotes.Count > 0)
            {
                quotes.Add(quotes.Last()); // Temporary POC fix for issue displaying last item in UI
                var ids   = Enumerable.Range(0, quotes.Count() - 1).ToList();
                var times = quotes.Select(x => Convert.ToInt64(ToUnixTimeStamp(x.TimeStampDateTime)))
                            .ToList();
                var colors          = quotes.Select(x => "yellow").ToList();
                var texts           = quotes.Select(x => "STOCH307").ToList();
                var labels          = quotes.Select(x => "ST").ToList();
                var labelFontColors = quotes.Select(x => "black").ToList();
                var minSizes        = quotes.Select(x => 20).ToList();

                marks = new SignalMarks()
                {
                    id             = ids,
                    time           = times,
                    color          = colors,
                    text           = texts,
                    label          = labels,
                    labelFontColor = labelFontColors,
                    minSize        = minSizes
                };
            }

            return(marks);
        }
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")]
                                              HttpRequestMessage req, TraceWriter log)
        {
            List <Quote> quotes = new List <Quote>();

            using (var db = new InvestipsQuotesContext())
            {
                quotes = db.Quotes.Where(q => q.IsSuperGap == true ||
                                         q.IsBullEight45Degreed ||
                                         (q.IsStoch101Cossing20Up &&
                                          q.IsPriceCrossMovAvg7Up &&
                                          q.IsMovingAvg30PointingUp)
                                         ).OrderByDescending(q => q.TimeStampDateTime).ToList();
            }

            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(JsonConvert.SerializeObject(quotes.Select(q => q.Symbol).Distinct().ToList()), Encoding.UTF8,
                                            "application/json")
            });
        }
Exemple #5
0
        public static SignalMarks GetBullBigEightMarks(string symbol)
        {
            var          marks  = new SignalMarks();
            List <Quote> quotes = new List <Quote>();

            using (var db = new InvestipsQuotesContext())
            {
                quotes = db.Quotes.Where(
                    q => q.IsBullEight45Degreed && q.Symbol == symbol
                    ).ToList();
            }

            if (quotes.Count > 0)
            {
                quotes.Add(quotes.Last());
                var ids   = Enumerable.Range(1, quotes.Count()).ToList();
                var times = quotes.Select(x => Convert.ToInt64(ToUnixTimeStamp(x.TimeStampDateTime)))
                            .ToList();
                var colors          = quotes.Select(x => "black").ToList();
                var texts           = quotes.Select(x => "BullBigEight").ToList();
                var labels          = quotes.Select(x => "B8").ToList();
                var labelFontColors = quotes.Select(x => "white").ToList();
                var minSizes        = quotes.Select(x => 20).ToList();

                marks = new SignalMarks()
                {
                    id             = ids,
                    time           = times,
                    color          = colors,
                    text           = texts,
                    label          = labels,
                    labelFontColor = labelFontColors,
                    minSize        = minSizes
                };
            }

            return(marks);
        }
        public static SignalMarks GetBearGap(string symbol)
        {
            var          marks  = new SignalMarks();
            List <Quote> quotes = new List <Quote>();

            using (var db = new InvestipsQuotesContext())
            {
                quotes = db.Quotes.Where(q => q.IsSuperGapBear == true && q.Symbol == symbol).ToList();
            }


            if (quotes.Count > 0)
            {
                quotes.Add(quotes.Last()); // Temporary POC fix for issue displaying last item in UI
                var ids   = Enumerable.Range(1, quotes.Count()).ToList();
                var times = quotes.Select(x => Convert.ToInt64(ToUnixTimeStamp(x.TimeStampDateTime)))
                            .ToList();
                var colors          = quotes.Select(x => "red").ToList();
                var texts           = quotes.Select(x => "Super Gaps").ToList();
                var labels          = quotes.Select(x => "GP").ToList();
                var labelFontColors = quotes.Select(x => "white").ToList();
                var minSizes        = quotes.Select(x => 20).ToList();

                marks = new SignalMarks()
                {
                    id             = ids,
                    time           = times,
                    color          = colors,
                    text           = texts,
                    label          = labels,
                    labelFontColor = labelFontColors,
                    minSize        = minSizes
                };
            }

            return(marks);
        }
Exemple #7
0
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")]
                                              HttpRequestMessage req, TraceWriter log)
        {
            string from = req.GetQueryNameValuePairs()
                          .FirstOrDefault(q => String.Compare(q.Key, "from", StringComparison.OrdinalIgnoreCase) == 0)
                          .Value;

            string to = req.GetQueryNameValuePairs()
                        .FirstOrDefault(q => String.Compare(q.Key, "to", StringComparison.OrdinalIgnoreCase) == 0)
                        .Value;

            string symbol = req.GetQueryNameValuePairs()
                            .FirstOrDefault(q => String.Compare(q.Key, "symbol", StringComparison.OrdinalIgnoreCase) == 0)
                            .Value;

            string resolution = req.GetQueryNameValuePairs()
                                .FirstOrDefault(q => String.Compare(q.Key, "resolution", StringComparison.OrdinalIgnoreCase) == 0)
                                .Value;
            // parse query parameter
            string name = req.GetQueryNameValuePairs()
                          .FirstOrDefault(q => String.Compare(q.Key, "name", StringComparison.OrdinalIgnoreCase) == 0)
                          .Value;

            List <Quote> quotes = new List <Quote>();

            using (var db = new InvestipsQuotesContext())
            {
                quotes = db.Quotes.Where(
                    q => q.IsBullEight45Degreed && q.Symbol == symbol
                    ).ToList();
            }

            if (quotes.Count > 0)
            {
                quotes.Add(quotes.Last()); // Temporary POC fix for issue displaying last item in UI
                var ids   = Enumerable.Range(0, quotes.Count() - 1).ToList();
                var times = quotes.Select(x => Convert.ToInt64(ToUnixTimeStamp(x.TimeStampDateTime)))
                            .ToList();
                var colors          = quotes.Select(x => "green").ToList();
                var texts           = quotes.Select(x => "BullBigEight").ToList();
                var labels          = quotes.Select(x => "B8").ToList();
                var labelFontColors = quotes.Select(x => "black").ToList();
                var minSizes        = quotes.Select(x => 20).ToList();

                var marks = new SignalMarks()
                {
                    id             = ids,
                    time           = times,
                    color          = colors,
                    text           = texts,
                    label          = labels,
                    labelFontColor = labelFontColors,
                    minSize        = minSizes
                };

                var jsonToReturn = JsonConvert.SerializeObject(marks);
                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(jsonToReturn, Encoding.UTF8, "application/json")
                });
            }

            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(JsonConvert.SerializeObject(new SignalMarks()), Encoding.UTF8,
                                            "application/json")
            });
        }
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")]
                                              HttpRequestMessage req, TraceWriter log)
        {
            string from = req.GetQueryNameValuePairs()
                          .FirstOrDefault(q => String.Compare(q.Key, "from", StringComparison.OrdinalIgnoreCase) == 0)
                          .Value;

            string to = req.GetQueryNameValuePairs()
                        .FirstOrDefault(q => String.Compare(q.Key, "to", StringComparison.OrdinalIgnoreCase) == 0)
                        .Value;

            string symbol = req.GetQueryNameValuePairs()
                            .FirstOrDefault(q => String.Compare(q.Key, "symbol", StringComparison.OrdinalIgnoreCase) == 0)
                            .Value;

            string resolution = req.GetQueryNameValuePairs()
                                .FirstOrDefault(q => String.Compare(q.Key, "resolution", StringComparison.OrdinalIgnoreCase) == 0)
                                .Value;

            DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); //from 1970/1/1 00:00:00 to now

            var yesterday = DateTime.UtcNow.AddDays(-2);

            TimeSpan result = yesterday.Subtract(dt);

            int seconds = Convert.ToInt32(result.TotalSeconds);


            List <Quote> quotes = new List <Quote>();

            using (var db = new InvestipsQuotesContext())
            {
                quotes = db.Quotes.Where(q => q.IsSuperGap == true &&
                                         q.Symbol == symbol).ToList();
            }


            if (quotes.Count > 0)
            {
                quotes.Add(quotes.Last()); // Temporary POC fix for issue displaying last item in UI
                var ids   = Enumerable.Range(0, quotes.Count() - 1).ToList();
                var times = quotes.Select(x => Convert.ToInt64(ToUnixTimeStamp(x.TimeStampDateTime)))
                            .ToList();
                var colors          = quotes.Select(x => "blue").ToList();
                var texts           = quotes.Select(x => "Super Gaps").ToList();
                var labels          = quotes.Select(x => "G").ToList();
                var labelFontColors = quotes.Select(x => "white").ToList();
                var minSizes        = quotes.Select(x => 20).ToList();

                var marks = new SignalMarks()
                {
                    id             = ids,
                    time           = times,
                    color          = colors,
                    text           = texts,
                    label          = labels,
                    labelFontColor = labelFontColors,
                    minSize        = minSizes
                };

                var jsonToReturn = JsonConvert.SerializeObject(marks);
                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(jsonToReturn, Encoding.UTF8, "application/json")
                });
            }

            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(JsonConvert.SerializeObject(new SignalMarks()), Encoding.UTF8,
                                            "application/json")
            });
        }
Exemple #9
0
        public static SignalMarks GetBullThreeArrowsMarks(string symbol)
        {
            var          marks         = new SignalMarks();
            List <Quote> quotes        = new List <Quote>();
            var          matchedQuotes = new List <Quote>();

            using (var db = new InvestipsQuotesContext())
            {
                quotes = db.Quotes.Where(q => q.Symbol == symbol &&
                                         (q.IsMacdCrossingHorizontalUp || q.IsPriceCrossMovAvg30Up || q.IsStoch145Cossing25Up))
                         .OrderBy(q => q.TimeStampDateTime).ToList();
                for (int i = 0; i < quotes.Count; i++)
                {
                    var quote      = quotes[i];
                    var isMacd     = quote.IsMacdCrossingHorizontalUp ? 1 : 0;
                    var isMovAvg30 = quote.IsPriceCrossMovAvg30Up ? 1 : 0;
                    var isStoch145 = quote.IsStoch145Cossing25Up ? 1 : 0;
                    var markCount  = isMacd + isMovAvg30 + isStoch145;

                    if (quote.IsStoch14505PointingUp)
                    {
                        if (quote.IsMacdCrossingHorizontalUp && quote.IsPriceCrossMovAvg30Up &&
                            quote.IsStoch145Cossing25Up)
                        {
                            matchedQuotes.Add(quote);
                        }
                        //if (quote.IsMacdCrossingHorizontalUp && PreviousTwoAreInRange(i, quote, quotes, markCount))
                        //{
                        //    matchedQuotes.Add(quote);
                        //}
                        //if (quote.IsPriceCrossMovAvg30Up && PreviousTwoAreInRange(i, quote, quotes, markCount))
                        //{
                        //    matchedQuotes.Add(quote);
                        //}
                        //if (quote.IsStoch145Cossing25Up && PreviousTwoAreInRange(i, quote, quotes, markCount))
                        //{
                        //    matchedQuotes.Add(quote);
                        //}
                    }
                }
            }

            if (matchedQuotes.Count > 0)
            {
                var ids             = Enumerable.Range(0, matchedQuotes.Count() - 1).ToList();
                var times           = matchedQuotes.Select(x => Convert.ToInt64(ToUnixTimeStamp(x.TimeStampDateTime))).ToList();
                var colors          = matchedQuotes.Select(x => "green").ToList();
                var texts           = matchedQuotes.Select(x => "3 Green Arrows").ToList();
                var labels          = matchedQuotes.Select(x => "G").ToList();
                var labelFontColors = matchedQuotes.Select(x => "black").ToList();
                var minSizes        = matchedQuotes.Select(x => 20).ToList();

                marks = new SignalMarks()
                {
                    id             = ids,
                    time           = times,
                    color          = colors,
                    text           = texts,
                    label          = labels,
                    labelFontColor = labelFontColors,
                    minSize        = minSizes
                };
            }

            return(marks);
        }
Exemple #10
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            List <Quote> quotes     = new List <Quote>();
            var          quoteMaker = new QuoteMaker(new InvestipsQuoteBuilder());

            var httpClient = GetHttpClient();

            var symbols = await GetStockSymbols(httpClient);

            //var subsetSymbols = symbols.Where(s => s.StartsWith("S") || s.StartsWith("T") || s.StartsWith("U") || s.StartsWith("V") || s.StartsWith("W")
            //                                       || s.StartsWith("X") || s.StartsWith("Y") || s.StartsWith("Z")).ToList();
            var index = 1;

            foreach (var symbol in symbols)
            {
                //if (index < 3)
                //{
                try
                {
                    var history = await Yahoo.GetHistoricalAsync(symbol, new DateTime(2019, 3, 1), DateTime.Now,
                                                                 Period.Daily);

                    quoteMaker.BuildQuote(history, symbol);
                    quotes.AddRange(quoteMaker.GetQuotes());
                    index++;

                    Debug.WriteLine(
                        $"------------------------------------------------------------------------------");
                    Debug.WriteLine(
                        $"                       Symbol {symbol} - with index {index}                   ");
                    Debug.WriteLine(
                        $"______________________________________________________________________________");
                }
                catch (FlurlHttpException ex)
                {
                    Debug.WriteLine($"Error fetching  {symbol} quotes ", ex.Message);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Error fetching  {symbol} quotes ", ex.Message);
                }
                //  }
            }

            using (var db = new InvestipsQuotesContext())
            {
                var today = DateTime.Today;

                var existingSingleQuote = await db.Quotes.Where(q => q.TimeStampDateTime != null && q.Symbol.StartsWith("C")).OrderByDescending(q => q.TimeStampDateTime).FirstOrDefaultAsync();

                if (existingSingleQuote != null)
                {
                    quotes = quotes.Where(q => q.TimeStampDateTime <= today &&
                                          q.TimeStampDateTime > existingSingleQuote.TimeStampDateTime).ToList();
                }
            }


            using (var db = new InvestipsQuotesContext())
            {
                EFBatchOperation.For(db, db.Quotes).InsertAll(quotes);
                log.Info("Quote Created");
            }

            //using (var db = new InvestipsQuotesContext())
            //{
            //    foreach (var quote in quotes)
            //    {
            //        db.Quotes.Add(quote);
            //        await db.SaveChangesAsync();
            //        log.Info("Quote Created");
            //    }
            //    //db.Quotes.Add(new Quote { Symbol = "AAPL", Open = 100, High = 103, Low = 99, Close = 102, TimeStampDateTime = DateTime.Now });
            //}

            return(req.CreateResponse(HttpStatusCode.OK, "Done "));
        }