Beispiel #1
0
        public static List <TradingDay> DownloadStocksUsingString(string Ticks, DateTime From)
        {
            List <TradingDay> Market = new List <TradingDay>();
            int c = 1;

            HistQuotesDownload dl = new HistQuotesDownload();

            dl.Settings.IDs      = new string[] { Ticks };
            dl.Settings.FromDate = From;
            dl.Settings.ToDate   = DateTime.Today;
            dl.Settings.Interval = HistQuotesInterval.Daily;

            Response <HistQuotesResult> resp = dl.Download();

            foreach (HistQuotesDataChain hqc in resp.Result.Chains)
            {
                foreach (HistQuotesData hqd in hqc)
                {
                    TradingDay tempday = new TradingDay(hqc.ID, c, hqd.TradingDate.ToLocalTime(), hqd.Open, hqd.Close,
                                                        hqd.High,
                                                        hqd.Low, hqd.CloseAdjusted, hqd.PreviousClose, (int)hqd.Volume);

                    c++;
                    Market.Add(tempday);
                }
            }

            return(Market);
        }
Beispiel #2
0
        private static void DownloadHistPriceAndCalculateAverage(List <string> ETFList, ref List <QuoteFiveDay> quoteFiveDayList, bool calcLows)
        {
            string[]        quotesArray = ETFList.ToArray();
            System.DateTime fromDate    = System.DateTime.Today.AddDays(-5);
            System.DateTime toDate      = System.DateTime.Today.AddDays(-1);
            MaasOne.Finance.YahooFinance.HistQuotesInterval interval = MaasOne.Finance.YahooFinance.HistQuotesInterval.Daily;

            //Download
            MaasOne.Finance.YahooFinance.HistQuotesDownload dl2 = new HistQuotesDownload();
            Response <HistQuotesResult> hqResp = dl2.Download(quotesArray, fromDate, toDate, interval);

            if (hqResp.Connection.State == MaasOne.Base.ConnectionState.Success)
            {
                HistQuotesResult      result = hqResp.Result;
                HistQuotesDataChain[] chains = result.Chains;

                foreach (HistQuotesDataChain chain in chains)
                {
                    var quoteFiveDayItem = quoteFiveDayList.FirstOrDefault(i => i.Id == chain.ID);
                    if (calcLows)
                    {
                        CalculateAvgFromLows(chain, quoteFiveDayItem);
                    }
                    else
                    {
                        CalculateAvgFromHighs(chain, quoteFiveDayItem);
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets the daily share ticker from yahoo.
        /// </summary>
        /// <param name="symbol">The y symbol.</param>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        /// <returns></returns>
        public List <Ticker> GetDailyShareTickerFromYahoo(string symbol, DateTime startDate, DateTime endDate)
        {
            List <Ticker> enList = new List <Ticker>();

            HistQuotesDownload         hsDownload = new HistQuotesDownload();
            HistQuotesDownloadSettings settings   = new HistQuotesDownloadSettings();

            var share = new ShareBLL(_unit).GetShareBySymbol(symbol);

            try
            {
                if (share != null)
                {
                    settings.ID       = symbol;
                    settings.FromDate = startDate;
                    settings.ToDate   = endDate;
                    settings.Interval = HistQuotesInterval.Daily;

                    hsDownload.Settings = settings;

                    Response <HistQuotesResult> resp = hsDownload.Download();

                    if (resp != null && resp.Result != null && resp.Result.Chains.Length == 1)
                    {
                        var tickerArray = resp.Result.Chains[0];

                        foreach (var t in tickerArray)
                        {
                            Ticker en = new Ticker();

                            en.TradingDate   = DateHelper.DateToInt(t.TradingDate);
                            en.AdjustedClose = t.CloseAdjusted;
                            en.High          = t.High;
                            en.Low           = t.Low;
                            en.Open          = t.Open;
                            en.Close         = t.Close;
                            en.Volumn        = t.Volume;
                            en.ShareId       = share.Id;
                            en.JSTicks       = DateHelper.DateToJSTicks(t.TradingDate);

                            enList.Add(en);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, "Error load share tickers from yahoo. ", ex);
                throw;
            }
            return(enList);
        }