Пример #1
0
        public async Task <IBitcoinPrice> GetPriceAsync(HarvestTask task)
        {
            if (task.Origin != Origin.GDAX)
            {
                this._logger.LogError("Task exchange service differs");
                return(null);
            }

            string method = "products/" + this.APICurrencyId[task.Pair] + "/ticker";

            this._logger.LogInformation("Fetch new price");
            HttpResponseMessage response = await _gdaxClient.GetAsync(method);

            if (!response.IsSuccessStatusCode)
            {
                this._logger.LogError("Error response from exchange API");
                return(null);
            }

            String json = await response.Content.ReadAsStringAsync();

            GdaxBitcoinPrice price = JsonConvert.DeserializeObject <GdaxBitcoinPrice>(json, this._serializer);

            price.Currency = task.Pair;

            return(price);
        }
        public async Task Execute(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                HarvestTask task = this._taskQueue.Take(token);

                IHarvestingService harvester = this._harvestingServiceFactory.GetHarvestingService(task.Origin);

                IBitcoinPrice price = await harvester.GetPriceAsync(task);

                this._repositoryService.Persist(price);
            }
        }