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 override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject jsonObject = JObject.Load(reader); BitcoinPriceBase configuration = new GdaxBitcoinPrice(); configuration.Value = (decimal)jsonObject["price"]; DateTime temp = DateTime.Parse(jsonObject["time"].ToString()); configuration.Timestamp = temp.GetUnixTimestampInSeconds(); return(configuration); }
public void Test_Last_Added_Value() { this.InitializeRepositoryWithTestData(); IBitcoinPrice price = new GdaxBitcoinPrice() { Currency = CurrencyPair.USDBTC, Value = 1, Timestamp = DateTime.UtcNow.AddMinutes(-1).GetUnixTimestampInSeconds() }; this._repositoryService.Persist(price); decimal lastAddedValue = this._repositoryService.GetLastValue(price.Currency, out TrendType trend); Assert.Equal(price.Value, lastAddedValue); }