Beispiel #1
0
        public void ProcessSymbol(int total, SymbolData symData, IEXData.HistoryType ht)
        {
            Trading.Company c = Trading.IEXData.DownloadSymbol(symData.symbol, ht, symData);
            if (c.Id != -1)
            {
                this.AddSymbol(c);
            }

            current++;
            int      left   = total - current;
            double   avgSec = sw.Elapsed.TotalSeconds / current;
            TimeSpan ts     = new TimeSpan(0, 0, (int)(avgSec * left));

            Debug.Nlog(current.ToString() + "/" + total.ToString() + "\t" + symData.symbol + ", " + ts.ToString() + " left");
        }
Beispiel #2
0
        }                                                 //Highest close value in series up to date

        public Company(string symbol, List <HistoricalDataResponse> data, SymbolData sym = null)
        {
            Iterator                  = -1;
            Count                     = 0;
            date                      = new List <LocalDate>();
            open                      = new List <float>();
            high                      = new List <float>();
            low                       = new List <float>();
            close                     = new List <float>();
            volume                    = new List <int>();
            unadjustedVolume          = new List <int>();
            change                    = new List <float>();
            changePercent             = new List <float>();
            vwap                      = new List <float>();
            label                     = new List <string>();
            changeOverTime            = new List <float>();
            MovingAverageClose        = new List <float>();
            MovingAverageVolume       = new List <int>();
            RelativePriceVolume       = new List <float>();
            MovingRelativePriceVolume = new List <float>();
            CurrentCupHandle          = new CupHandle();
            EarningsQuarters          = new List <LocalDate>();
            EarningsData              = new List <float>();
            EarningsGrowth            = new List <float>();
            CloseHighToDate           = new List <float>();


            this.Symbol = symbol;
            if (sym != null)
            {
                Name = sym.name;
            }
            else
            {
                Name = "";
            }

            foreach (HistoricalDataResponse d in data)
            {
                string[]  dateSplit = d.date.Split('-');
                LocalDate localDate = new LocalDate(Int16.Parse(dateSplit[0]), Int16.Parse(dateSplit[1]), Int16.Parse(dateSplit[2]));
                date.Add(localDate);
                open.Add(d.open);
                high.Add(d.high);
                low.Add(d.low);
                close.Add(d.close);
                volume.Add(d.volume);
                unadjustedVolume.Add(d.unadjustedVolume);
                change.Add(d.change);
                changePercent.Add(d.changePercent);
                vwap.Add(d.vwap);
                label.Add(d.label);
                changeOverTime.Add(d.changeOverTime);
                Count++;
            }

            MinClose  = close.Min();
            MinVolume = close.Max();

            List <float> changeSpread = new List <float>();

            for (int i = 0; i < close.Count; i++)
            {
                float delta = high[i] - low[i];
                changeSpread.Add(delta / open[i]);
            }
            maxDayChangePerc = changeSpread.Max();

            MovingAverageClose  = MathHelpers.MovingAverage(close, 50);
            MovingAverageVolume = MathHelpers.MovingAverage(volume, 50);

            RelativePriceVolume.Add(0);
            for (int i = 1; i < close.Count; i++)
            {
                float y = (close[i] - close[i - 1]) / close[i - 1];
                RelativePriceVolume.Add(volume[i] * y);
            }
            MovingRelativePriceVolume = MathHelpers.MovingAverage(RelativePriceVolume, 50);
        }
Beispiel #3
0
        public static Company DownloadSymbol(string symbol, HistoryType ht, SymbolData symbolData = null)
        {
            List <HistoricalDataResponse> data = new List <HistoricalDataResponse>();


            #region GetEarningsData
            //EarningsData earnings = new EarningsData();
            //using (HttpClient client = new HttpClient())
            //{
            //    try
            //    {
            //        string IEXTrading_API_PATH = GetEarningsDataURL(symbol);
            //        client.DefaultRequestHeaders.Accept.Clear();
            //        client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            //        //For IP-API
            //        client.BaseAddress = new Uri(IEXTrading_API_PATH);
            //        HttpResponseMessage response = client.GetAsync(IEXTrading_API_PATH).GetAwaiter().GetResult();
            //        if (response.IsSuccessStatusCode)
            //        {
            //            earnings = response.Content.ReadAsAsync<EarningsData>().GetAwaiter().GetResult();
            //        }
            //        else { }
            //    }
            //    catch (Exception ex)
            //    {
            //        return new Company();
            //        Debug.Nlog(symbol + "\n" + ex.Message);
            //    }
            //}

            //if (earnings == null)
            //{
            //    return new Company();
            //}
            #endregion

            #region GetHistoricalData
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    string IEXTrading_API_PATH = GetHistoricalDataURL(symbol, ht);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                    //For IP-API
                    client.BaseAddress = new Uri(IEXTrading_API_PATH);
                    HttpResponseMessage response = client.GetAsync(IEXTrading_API_PATH).GetAwaiter().GetResult();
                    if (response.IsSuccessStatusCode)
                    {
                        var historicalDataList = response.Content.ReadAsAsync <List <HistoricalDataResponse> >().GetAwaiter().GetResult();

                        if (historicalDataList.Count > 0)
                        {
                            foreach (var historicalData in historicalDataList)
                            {
                                if (historicalData != null)
                                {
                                    //Console.WriteLine("Open: " + historicalData.open);
                                    //Console.WriteLine("Close: " + historicalData.close);
                                    //Console.WriteLine("Low: " + historicalData.low);
                                    //Console.WriteLine("High: " + historicalData.high);
                                    //Console.WriteLine("Change: " + historicalData.change);
                                    //Console.WriteLine("Change Percentage: " + historicalData.changePercent);
                                    data.Add(historicalData);
                                }
                                else
                                {
                                    return(new Company());
                                }
                            }
                        }
                        else
                        {
                            return(new Company());
                        }
                    }
                    else
                    {
                        return(new Company());
                    }
                }
                catch (Exception ex)
                {
                    Debug.Nlog(symbol + "\n" + ex.Message);
                }
            }
            #endregion



            return(new Company(symbol, data, symbolData));
        }