Beispiel #1
0
        /// <summary>
        /// Get the ticker.
        /// </summary>
        /// <returns></returns>
        private async Task <KrakenTicker> GetTicker(KrakenPair pair)
        {
            using (HttpResponseMessage response = await this._httpClient.GetAsync(new Uri($"Ticker?pair={pair.PairId}", UriKind.Relative)))
            {
                string json = await response.Content.ReadAsStringAsync();

                JObject      jObject = JObject.Parse(json);
                KrakenTicker ticker  = JsonConvert.DeserializeObject <KrakenTicker>(jObject["result"][pair.PairId].ToString(), this._serializerSettings);
                ticker.BaseCurrency  = pair.BaseCurrency;
                ticker.QuoteCurrency = pair.QuoteCurrency;
                return(ticker);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get the market summaries.
        /// </summary>
        /// <returns></returns>
        private async Task <List <KrakenPair> > GetPairs()
        {
            using (HttpResponseMessage response = await this._httpClient.GetAsync(new Uri("AssetPairs", UriKind.Relative)))
            {
                string json = await response.Content.ReadAsStringAsync();

                JObject           jResponse = JObject.Parse(json);
                List <KrakenPair> pairs     = jResponse.GetValue("result").Children().Cast <JProperty>().Select(property =>
                {
                    KrakenPair pair = JsonConvert.DeserializeObject <KrakenPair>(property.Value.ToString());
                    pair.PairId     = property.Name;
                    return(pair);
                }).ToList();
                return(pairs);
            }
        }
Beispiel #3
0
        /// <summary>
        ///     Get the ticker.
        /// </summary>
        /// <returns></returns>
        private async Task <KrakenTicker?> GetTickerAsync(KrakenPair pair)
        {
            try
            {
                HttpClient httpClient = this.CreateHttpClient();

                using (HttpResponseMessage response = await httpClient.GetAsync(new Uri($"Ticker?pair={pair.PairId}", uriKind: UriKind.Relative)))
                {
                    response.EnsureSuccessStatusCode();

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

                    try
                    {
                        KrakenTickerWrapper item = JsonSerializer.Deserialize <KrakenTickerWrapper>(json: json, options: this._serializerSettings);

                        if (item.Result == null)
                        {
                            return(null);
                        }

                        if (item.Result.TryGetValue(key: pair.PairId, out KrakenTicker? ticker))
                        {
                            ticker.BaseCurrency  = pair.BaseCurrency;
                            ticker.QuoteCurrency = pair.QuoteCurrency;

                            return(ticker);
                        }

                        return(null);
                    }
                    catch (Exception exception)
                    {
                        this.Logger.LogError(new EventId(exception.HResult), exception: exception, message: "Failed to deserialize");

                        return(null);
                    }
                }
            }
            catch (Exception exception)
            {
                this.Logger.LogError(new EventId(exception.HResult), exception: exception, $"Failed to retrieve {pair.BaseCurrency}/{pair.QuoteCurrency}: {exception.Message}");

                return(null);
            }
        }