Esempio n. 1
0
        public async Task <ProductPrice> GetCurrentPrice(string productId)
        {
            var client   = new ProductClient(EnvironmentVariables.ApiBaseUri, _authenticator);
            var response = await client.GetProductTickerAsync(productId);

            return(response.Value);
        }
Esempio n. 2
0
        public async Task <ProductPrice> GetCurrentPrice(string productId)
        {
            var client   = new ProductClient(_appSettings.ProductionBaseUri, _authenticator);
            var response = await client.GetProductTickerAsync(productId);

            return(response.Value);
        }
Esempio n. 3
0
        public static async Task Run()
        {
            var ready = false;

            while (true)
            {
                var toAdd = new Dictionary <string, ProductTicker>();

                foreach (var currency in Currencies)
                {
                    var vals = ApiKeys.Instance;

                    var requestAuthenticator = new RequestAuthenticator(vals.ApiKey, vals.ApiPassphrase, vals.ApiSecret);
                    var productClient        = new ProductClient(vals.BaseUrl, requestAuthenticator);
                    var productResponse      = await productClient.GetProductTickerAsync("BTC-USD");

                    if (productResponse.StatusCode == HttpStatusCode.OK)
                    {
                        toAdd[currency] = productResponse.Value;
                    }
                }
                ;

                PriceHistory.Add(toAdd);

                // keep only 30 minute's worth of data
                if (PriceHistory.Count() > 60)
                {
                    PriceHistory = PriceHistory.GetRange(1, PriceHistory.Count() - 1);

                    if (!ready)
                    {
                        ready = true;
                        if (Ready != null)
                        {
                            Ready(null, null);
                        }
                    }
                }
                else
                {
                    Console.WriteLine($"{PriceHistory.Count()} - prepopulating.");
                }

                await Task.Delay((int)TimeSpan.FromSeconds(30).TotalMilliseconds);
            }
        }