Пример #1
0
        public FinanceSearchResult(YahooFinancePriceResponse priceResponse, YahooFinanceSearchResponse searchResponse) : base(priceResponse.Url)
        {
            var pricePrefix = priceResponse.RegularMarketPrice > priceResponse.PreviousClose
                ? "+"
                : "-";
            var priceChange   = Math.Abs(PriceChange(priceResponse));
            var percentChange = Math.Abs(PercentChange(priceResponse));

            Title = searchResponse.ShortName + " (" + priceResponse.Symbol + ") @ " + priceResponse.RegularMarketPrice + " " + pricePrefix + priceChange + " (" + pricePrefix + percentChange + "%)";
        }
Пример #2
0
        public bool TryGet(string ticker, out YahooFinancePriceResponse priceResponse)
        {
            if (!ResponseCache.ContainsKey(ticker))
            {
                priceResponse = null;
                return(false);
            }

            var now = DateTimeOffset.Now.ToUnixTimeMilliseconds();

            if (now - UpdateTimeCache[ticker] >= CacheTimeout.Milliseconds)
            {
                priceResponse = null;
                return(false);
            }

            priceResponse = ResponseCache[ticker];
            return(true);
        }
Пример #3
0
 private double PercentChange(YahooFinancePriceResponse priceResponse)
 {
     return(Math.Round((priceResponse.PreviousClose - priceResponse.RegularMarketPrice) / priceResponse.PreviousClose * 100f, 2));
 }
Пример #4
0
 private double PriceChange(YahooFinancePriceResponse priceResponse)
 {
     return(Math.Round(priceResponse.RegularMarketPrice - priceResponse.PreviousClose, 2));
 }
Пример #5
0
 public void Put(string ticker, YahooFinancePriceResponse priceResponse)
 {
     ResponseCache[ticker]   = priceResponse;
     UpdateTimeCache[ticker] = DateTimeOffset.Now.ToUnixTimeMilliseconds();
 }