Пример #1
0
 /// <summary>
 /// Prepare the dividends from YResponse.
 /// </summary>
 /// <param name="resultResponse"></param>
 /// <param name="timeZone"></param>
 /// <returns></returns>
 public static FyDividend[] GetDividends(this YResultResponse resultResponse, TimeZoneInfo timeZone = null)
 => resultResponse?.Events?
 .Dividends?
 .Values
 .Select(x => new FyDividend()
 {
     Date  = GetDateFromTimestamp(x.Date, timeZone),
     Value = x.Amount
 }).ToArray();
Пример #2
0
 /// <summary>
 /// Prepare the splits from YResponse.
 /// </summary>
 /// <param name="resultResponse"></param>
 /// <param name="timeZone"></param>
 /// <returns></returns>
 public static FySplit[] GetSplits(this YResultResponse resultResponse, TimeZoneInfo timeZone = null)
 => resultResponse?.Events?
 .Splits?
 .Values
 .Select(x => new FySplit()
 {
     Date        = GetDateFromTimestamp(x.Date, timeZone),
     Denominator = x.Denominator,
     Numberator  = x.Numerator,
     Ratio       = x.SplitRatio
 }).ToArray();
Пример #3
0
        /// <summary>
        /// Prepare the splits from YResponse.
        /// </summary>
        /// <param name="resultResponse"></param>
        /// <param name="timeZone"></param>
        /// <returns></returns>
        public static FyQuote[] GetQuotes(this YResultResponse resultResponse, TimeZoneInfo timeZone = null)
        {
            var ohlc = resultResponse.Indicators.Quote.First();

            var timestamps = resultResponse.TimeStamp;
            var dateTimes  = timestamps.Select(x => x.HasValue ? GetDateFromTimestamp(x.Value) : null as DateTime?).ToList();

            var adjClose = resultResponse.Indicators.AdjClose?.FirstOrDefault()?.AdjClose ?? ohlc.Close;

            var quotes = new List <FyQuote>();

            for (int i = 0; i < dateTimes.Count; i++)
            {
                if (dateTimes[i] == null ||
                    ohlc.Low[i] == null ||
                    ohlc.Open[i] == null ||
                    ohlc.High[i] == null ||
                    ohlc.Close[i] == null ||
                    adjClose[i] == null ||
                    ohlc.Volume[i] == null)
                {
                    continue;
                }

                DateTime period = dateTimes[i].Value;
                if (timeZone != null)
                {
                    period = period.Add(timeZone.BaseUtcOffset);
                }

                quotes.Add(new FyQuote()
                {
                    Period   = period,
                    Low      = ohlc.Low[i].Value,
                    Open     = ohlc.Open[i].Value,
                    High     = ohlc.High[i].Value,
                    Close    = ohlc.Close[i].Value,
                    AdjClose = adjClose[i].Value,
                    Volume   = ohlc.Volume[i].Value
                });
            }

            return(quotes.ToArray());
        }