Example #1
0
        public static ExchangeRateStatus ToExchangeRateStatus(ExchangeRate rate, ExchangeRateTrend trend)
        {
            var status = new ExchangeRateStatus
            {
                Trend       = trend,
                LatestPrice = rate.Price,
                TimeStamp   = DateTimeOffset.FromUnixTimeSeconds(rate.Timestamp).LocalDateTime
            };

            return(status);
        }
Example #2
0
        private static async Task GetExchangeRateStatus(IApplicationBuilder app, HttpResponse response)
        {
            var predictor = app.ApplicationServices.GetService <IExchangeRatePredictor>();
            var rateTrend = predictor.GetExchangeRateTrend();

            var exchangeRateProvider = app.ApplicationServices.GetService <IExchangeRatesStorage>();
            var currentRate          = exchangeRateProvider.LatestExchangeRate;

            response.ContentType = "application/json";
            response.StatusCode  = StatusCodes.Status200OK;
            var responseJson =
                JsonConvert.SerializeObject(ExchangeRateStatus.ToExchangeRateStatus(currentRate, rateTrend));

            await response.WriteAsync(responseJson);
        }