Esempio n. 1
0
        public async Task <bool> TestPublicApiAsync(NetworkProviderContext context)
        {
            var ctx = new PublicPriceContext("btcvef".ToAssetPair(this, 3));
            var r   = await GetPricingAsync(ctx).ConfigureAwait(false);

            return(r != null);
        }
Esempio n. 2
0
        public async Task <bool> TestPublicApiAsync(NetworkProviderContext context)
        {
            var priceCtx = new PublicPriceContext("BTC_LTC".ToAssetPair(this));

            var r = await GetPriceAsync(priceCtx).ConfigureAwait(false);

            return(r != null && r.IsCompleted && r.FirstPrice != null);
        }
Esempio n. 3
0
        public async Task <MarketPrice> GetPriceAsync(PublicPriceContext context)
        {
            var r = await GetPricingAsync(new PublicPricesContext(new List <AssetPair>()
            {
                context.Pair
            }, context.L)).ConfigureAwait(false);

            return(r.FirstOrDefault());
        }
Esempio n. 4
0
        private static void LatestPriceTest()
        {
            var provider = Networks.I.Providers.OfType <BitMexProvider>().FirstProvider();
            var ctx      = new PublicPriceContext(new AssetPair("XBT".ToAsset(provider), "USD".ToAsset(provider)));

            try
            {
                var c = AsyncContext.Run(() => provider.GetPriceAsync(ctx));
                Console.WriteLine(c.FirstPrice.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 5
0
        private void TestVolumePricingSanity(INetworkProvider provider, List <AssetPair> pairs)
        {
            // TODO: to be reviewed and tested when there will be new providers that support Volume and Pricing interfaces.

            if (IsVolumePricingSanityTested)
            {
                return;
            }

            IsVolumePricingSanityTested = true;

            if (provider is IPublicVolumeProvider volumeProvider && provider is IPublicPricingProvider pricingProvider)
            {
                // Single test.

                if (pricingProvider.PricingFeatures.Single == null || volumeProvider.VolumeFeatures.Single == null)
                {
                    return;
                }

                if (pricingProvider.PricingFeatures.Single.CanVolume ^ volumeProvider.VolumeFeatures.Single.CanVolume)
                {
                    return;
                }

                var priceCtx = new PublicPriceContext(pairs.First());
                var rPrice   = AsyncContext.Run(() => pricingProvider.GetPricingAsync(priceCtx));

                AssetPrice(rPrice, volumeProvider.VolumeFeatures.Single.CanVolumeBase, volumeProvider.VolumeFeatures.Single.CanVolumeQuote);

                // Multiple pairs test.

                if (pricingProvider.PricingFeatures.Bulk == null || volumeProvider.VolumeFeatures.Bulk == null)
                {
                    return;
                }

                if (pricingProvider.PricingFeatures.Bulk.CanVolume ^ volumeProvider.VolumeFeatures.Bulk.CanVolume)
                {
                    return;
                }

                var pricesCtx = new PublicPricesContext(pairs);
                var rPrices   = AsyncContext.Run(() => pricingProvider.GetPricingAsync(pricesCtx));

                AssetPrice(rPrices, volumeProvider.VolumeFeatures.Bulk.CanVolumeBase, volumeProvider.VolumeFeatures.Bulk.CanVolumeQuote);
            }
        }
Esempio n. 6
0
            public void GetLatestPrice()
            {
                var provider = Networks.I.Providers.OfType <KrakenProvider>().FirstProvider();
                var ctx      = new PublicPriceContext(new AssetPair("BTC", "USD"));

                try
                {
                    var price = AsyncContext.Run(() => provider.GetPricingAsync(ctx));

                    System.Console.WriteLine($"Latest {ctx.Pair} value is {price.FirstPrice.Price}");
                }
                catch (Exception e)
                {
                    System.Console.WriteLine(e.Message);
                    throw;
                }
            }
        private void GetPricing(IPublicPricingProvider provider, List <AssetPair> pairs, bool firstPriceLessThan1)
        {
            try
            {
                Trace.WriteLine("Pricing interface test\n\n");

                if (provider.PricingFeatures.HasSingle)
                {
                    Trace.WriteLine("\nSingle features test\n");
                    var context = new PublicPriceContext(pairs.First())
                    {
                        RequestStatistics = provider.PricingFeatures.Single.CanStatistics,
                        RequestVolume     = provider.PricingFeatures.Single.CanVolume
                    };

                    InternalGetPriceAsync(provider, context, firstPriceLessThan1, true);
                }

                if (provider.PricingFeatures.HasBulk)
                {
                    Trace.WriteLine("\nBulk features test with pairs selection\n");
                    var context = new PublicPricesContext(pairs)
                    {
                        RequestStatistics = provider.PricingFeatures.Bulk.CanStatistics,
                        RequestVolume     = provider.PricingFeatures.Bulk.CanVolume
                    };

                    InternalGetPriceAsync(provider, context, firstPriceLessThan1, false);

                    if (provider.PricingFeatures.Bulk.CanReturnAll)
                    {
                        Trace.WriteLine("\nBulk features test (provider can return all prices)\n");
                        context = new PublicPricesContext();

                        InternalGetPriceAsync(provider, context, firstPriceLessThan1, false);
                    }
                }

                TestVolumePricingSanity(provider, pairs);
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
        }
Esempio n. 8
0
            public void LatestPrices()
            {
                var provider = Networks.I.Providers.OfType <BittrexProvider>().FirstProvider();
                var pair     = new AssetPair("BTC", "LTC");

                var ctx = new PublicPriceContext(pair);

                try
                {
                    var price = AsyncContext.Run(() => provider.GetPriceAsync(ctx));

                    System.Console.WriteLine($"Latest price for {pair} is {price.FirstPrice}");
                }
                catch (Exception e)
                {
                    System.Console.WriteLine(e);
                    throw;
                }
            }
Esempio n. 9
0
        public async Task <MarketPrice> GetPriceAsync(PublicPriceContext context)
        {
            var api = ApiProvider.GetApi(context);

            if (!context.Pair.Asset2.ToRemoteCode(this).Equals(Asset.Krw.ShortCode))
            {
                throw new NoAssetPairException(context.Pair, this);
            }

            var r = await api.GetTickerAsync(context.Pair.Asset1.ShortCode).ConfigureAwait(false);

            CheckResponseErrors(r);

            return(new MarketPrice(Network, context.Pair, r.last)
            {
                PriceStatistics = new PriceStatistics(Network, context.QuoteAsset, null, null, r.low, r.high),
                Volume = new NetworkPairVolume(Network, context.Pair, r.volume)
            });
        }
Esempio n. 10
0
            public void GetLatestPrice()
            {
                var provider = Networks.I.Providers.OfType <BitMexProvider>().FirstProvider();

                var ctx = new PublicPriceContext(new AssetPair("USD".ToAsset(provider), "BTC".ToAssetRaw()));

                try
                {
                    var c = AsyncContext.Run(() => provider.GetPriceAsync(ctx));

                    Console.WriteLine($"Base asset: {ctx.QuoteAsset}\n");
                    Console.WriteLine(c.FirstPrice.Price.Display);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    throw;
                }
            }
Esempio n. 11
0
            public void GetLatestPrices()
            {
                var provider = Networks.I.Providers.OfType <BitStampProvider>().FirstProvider();
                var pair     = new AssetPair("BTC", "USD");

                var priceContext = new PublicPriceContext(pair);

                try
                {
                    var price = AsyncContext.Run(() => provider.GetPricingAsync(priceContext));

                    System.Console.WriteLine($"Latest {pair}: {price.FirstPrice}");
                }
                catch (Exception e)
                {
                    System.Console.WriteLine(e.Message);
                    throw;
                }
            }
Esempio n. 12
0
            public void LatestPrice()
            {
                var provider = Networks.I.Providers.OfType <CoinbaseProvider>().FirstProvider();
                var pair     = new AssetPair("BTC", "USd");

                var ctx = new PublicPriceContext(pair);

                try
                {
                    var price = AsyncContext.Run(() => provider.GetPricingAsync(ctx));

                    Console.WriteLine($"Latest price for {pair} is {price.FirstPrice.Price}");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
Esempio n. 13
0
        public void Run()
        {
            UserContext userContext = new UserContext(ObjectId.NewObjectId(), "Alex");
            //ApiTestContext testContext = new ApiTestContext(new ApiKey("Key", BitMexAuthenticator.Key, BitMexAuthenticator.Secret));

            NetworkProviderPrivateContext providerPrivateContext = new NetworkProviderPrivateContext(userContext);

            BitMexProvider provider = new BitMexProvider();

            IWalletService walletService = provider;
            //var balances = walletService.GetBalancesAsync(providerPrivateContext).Result;

            IPublicPriceProvider priceProvider = provider;

            PublicPriceContext priceContext = new PublicPriceContext(new AssetPair("XBT".ToAsset(provider), "USD".ToAsset(provider)));

            var latestPrice = priceProvider.GetLatestPriceAsync(priceContext).Result;

            //walletService.TestApiAsync(testContext).RunSynchronously();
        }
Esempio n. 14
0
        public void GetPricesFromProvidersTest()
        {
            // TODO: Sean check your providers here.

            var ctx = new PublicPriceContext("BTC_USD".ToAssetPairRaw());

            var providers = Networks.I.Providers.OfType <IPublicPricingProvider>().Where(x => x.IsDirect).ToList();

            foreach (var provider in providers)
            {
                try
                {
                    var r = AsyncContext.Run(() => provider.GetPricingAsync(ctx)).FirstPrice;

                    Trace.WriteLine($"{r.QuoteAsset}: {r.Price.Display} - {provider.Network}");
                }
                catch (Exception e)
                {
                    Trace.WriteLine($"{provider.Network} failed: {e.Message}");
                }
            }
        }
        protected void GetPricingTest(IPublicPricingProvider provider, List <AssetPair> pairs, bool firstPriceLessThan1, bool?firstVolumeBaseBiggerThanQuote = null)
        {
            OutputWriter.WriteLine("Pricing interface test\n\n");

            if (provider.PricingFeatures.HasSingle)
            {
                OutputWriter.WriteLine("\nSingle features test\n");
                var context = new PublicPriceContext(pairs.First())
                {
                    RequestStatistics = provider.PricingFeatures.Single.CanStatistics,
                    RequestVolume     = provider.PricingFeatures.Single.CanVolume
                };

                InternalGetPriceAsync(provider, context, true, firstPriceLessThan1, firstVolumeBaseBiggerThanQuote);
            }

            if (provider.PricingFeatures.HasBulk)
            {
                OutputWriter.WriteLine("\nBulk features test with pairs selection\n");
                var context = new PublicPricesContext(pairs)
                {
                    RequestStatistics = provider.PricingFeatures.Bulk.CanStatistics,
                    RequestVolume     = provider.PricingFeatures.Bulk.CanVolume
                };

                InternalGetPriceAsync(provider, context, false, firstPriceLessThan1, firstVolumeBaseBiggerThanQuote);

                if (provider.PricingFeatures.Bulk.CanReturnAll)
                {
                    OutputWriter.WriteLine("\nBulk features test (provider can return all prices)\n");
                    context = new PublicPricesContext();

                    InternalGetPriceAsync(provider, context, false, firstPriceLessThan1, firstVolumeBaseBiggerThanQuote);
                }
            }

            TestVolumePricingSanity(provider, pairs);
        }