Exemple #1
0
        public async Task <StockRateFull> GetStockInfoAsync(string stockCode, StockTimeScale timeScale, CancellationToken token)
        {
            try
            {
                StockRequested?.Invoke(this, new OnStockRequestedEventArgs(stockCode));

                var endpoint = AdjustEndpoint(stockCode, timeScale);
                var response = await _client.GetAsync(endpoint, token);

                StockRateFull stocks = new StockRateFull();
                if (response.IsSuccessStatusCode)
                {
                    // What does content contain initially if not string?
                    var json = await response.Content.ReadAsStringAsync();

                    stocks = JsonConvert.DeserializeObject <StockRateFull>(json);
                    if (stocks.MetaData == null)
                    {
                        throw new HttpRequestException(json);
                    }
                }
                else
                {
                    throw new HttpRequestException($"Server returned {response.StatusCode}");
                }

                StockRetrieved?.Invoke(this, new OnStockRetrievedEventArgs(stocks));
                return(stocks);
            }
            catch (HttpRequestException e)
            {
                throw e;
            }
        }
        private void AddToStockHistory(StockRateFull stockRateFull)
        {
            var stockSymbol = stockRateFull.MetaData.StockCode;
            var stockRates  = stockRateFull.StockRates;

            if (_stockRatesFullHistory.ContainsKey(stockSymbol))
            {
                //foreach (var stockRate in stockRates)
                //{
                //    _stockRatesFullHistory[stockSymbol].Add(stockRate.Key, stockRate.Value);
                //}
            }
            else
            {
                _stockRatesFullHistory.Add(stockSymbol, stockRates);
            }
        }
 public OnStockRetrievedEventArgs(StockRateFull stockRateFull)
 {
     StockRateFull = stockRateFull;
 }