public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { if (context.ForSingleMethod) { return(await GetPriceAsync(context).ConfigureAwait(false)); } return(await GetPricesAsync(context).ConfigureAwait(false)); }
private async Task <MarketPrices> GetPriceAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this); var r = await api.GetMarketInfo(pairCode).ConfigureAwait(false); return(new MarketPrices(new MarketPrice(Network, context.Pair, r.rate))); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this); var r = await api.GetLatestPriceAsync(pairCode).ConfigureAwait(false); var price = new MarketPrice(Network, context.Pair, r.data.amount); return(new MarketPrices(price)); }
public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetAllTickersAsync().ConfigureAwait(false); var prices = new MarketPrices(); if (context.IsRequestAll) { var knownPairs = new AssetPairs(); foreach (var ticker in r.OrderBy(x => x.symbol.Length)) { var pairCodes = AssetsUtilities.GetAssetPair(ticker.symbol, knownPairs); if (!pairCodes.HasValue || !ticker.last.HasValue) { continue; } var pair = new AssetPair(pairCodes.Value.AssetCode1, pairCodes.Value.AssetCode2, this); knownPairs.Add(pair); prices.Add(new MarketPrice(Network, pair, ticker.last.Value) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, ticker.ask, ticker.bid, ticker.low, ticker.high), Volume = new NetworkPairVolume(Network, pair, ticker.volume, ticker.volumeQuote) }); } } else { foreach (var pair in context.Pairs) { var pairCode = pair.ToTicker(this); var ticker = r.FirstOrDefault(x => x.symbol.Equals(pairCode, StringComparison.OrdinalIgnoreCase)); if (ticker?.last == null) { prices.MissedPairs.Add(pair); continue; } prices.Add(new MarketPrice(Network, pair, ticker.last.Value) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, ticker.ask, ticker.bid, ticker.low, ticker.high), Volume = new NetworkPairVolume(Network, pair, ticker.volume, ticker.volumeQuote) }); } } return(prices); }
public async Task <MarketPricesResult> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickersAsync().ConfigureAwait(false); return(new MarketPricesResult(new MarketPrice(Network, context.Pair, r.last_traded_price) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ask, r.bid, r.low, r.high), Volume = new NetworkPairVolume(Network, context.Pair, r.total_volume_24h) })); }
public async Task<MarketPricesResult> GetPriceAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this, ""); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); return new MarketPricesResult(new MarketPrice(Network, context.Pair, r.last_trade) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ask, r.bid, null, null), Volume = new NetworkPairVolume(Network, context.Pair, r.rolling_24_hour_volume) }); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); return(new MarketPrices(new MarketPrice(Network, context.Pair, r.ll) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, null, null, r.l, r.h), Volume = new NetworkPairVolume(Network, context.Pair, r.a) })); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); return(new MarketPrices(new MarketPrice(Network, context.Pair, r.ticker.last) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ticker.sell == 0 ? (decimal?)null : r.ticker.sell, r.ticker.buy == 0 ? (decimal?)null : r.ticker.buy, r.ticker.low, r.ticker.high), Volume = new NetworkPairVolume(Network, context.Pair, r.ticker.vol) })); }
public async Task <MarketPrices> GetPriceAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this).ToLower(); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); return(new MarketPrices(new MarketPrice(Network, context.Pair, r.ticker.last) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ticker.ask, r.ticker.bid, r.ticker.low, r.ticker.high), Volume = new NetworkPairVolume(Network, context.Pair, r.ticker.volume) })); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var currencyCode = context.Pair.Asset1.ToRemoteCode(this); var r = await api.GetTickerAsync(currencyCode).ConfigureAwait(false); return(new MarketPrices(new MarketPrice(Network, context.Pair, r.price) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ask, r.bid, r.low, r.high), Volume = new NetworkPairVolume(Network, context.Pair, r.volume) })); }
public async Task <MarketPricesResult> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this, ""); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); return(new MarketPricesResult(new MarketPrice(Network, context.Pair, r.ticker.Last) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ticker.AskPrice, r.ticker.BidPrice, r.ticker.Low, r.ticker.High), Volume = new NetworkPairVolume(Network, context.Pair, r.ticker.Volume24H) })); }
public async Task <MarketPricesResult> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this, '/'); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); return(new MarketPricesResult(new MarketPrice(Network, context.Pair, r.lastPrice) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.bestAsk, r.bestBid), Volume = new NetworkPairVolume(Network, context.Pair, r.volume24h) })); }
public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var rRaw = await api.GetSymbolPriceTickerAsync().ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); var prices = new MarketPrices(); var knownPairs = new AssetPairs(); if (context.IsRequestAll) { foreach (var rPrice in r.OrderBy(x => x.symbol.Length)) { var tPair = AssetsUtilities.GetAssetPair(rPrice.symbol, knownPairs); if (!tPair.HasValue) { continue; } var pair = new AssetPair(tPair.Value.AssetCode1, tPair.Value.AssetCode2, this); knownPairs.Add(pair); prices.Add(new MarketPrice(Network, pair, rPrice.price)); } } else { foreach (var pair in context.Pairs) { var lowerPairTicker = pair.ToTicker(this).ToLower(); var lpr = r.FirstOrDefault(x => x.symbol.ToLower().Equals(lowerPairTicker)); if (lpr == null) { prices.MissedPairs.Add(pair); continue; } prices.Add(new MarketPrice(Network, pair, lpr.price)); } } return(prices); }
public async Task <MarketPrices> GetPriceAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var ticker = context.Pair.ToTicker(this); var r = await api.Get24HrTickerAsync(ticker).ConfigureAwait(false); var marketPrice = new MarketPrices(new MarketPrice(Network, context.Pair, r.lastPrice) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.askPrice, r.bidPrice, r.lowPrice, r.highPrice), Volume = new NetworkPairVolume(Network, context.Pair, r.volume) }); return(marketPrice); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var productCode = context.Pair.ToTicker(this, '_'); var r = await api.GetTickerAsync(productCode).ConfigureAwait(false); var price = new MarketPrice(Network, context.Pair, r.ltp) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.best_ask, r.best_bid), Volume = new NetworkPairVolume(Network, context.Pair, r.volume_by_product) }; return(new MarketPrices(price)); }
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); } }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); if (r.success == false && r.result.Length > 0) { throw new ApiResponseException(r.message, this); } return(new MarketPrices(new MarketPrice(Network, context.Pair, 1 / r.result[0].Last) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.result[0].Ask, r.result[0].Bid) })); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); if (r == null || r.error || r.data == null) { throw new ApiResponseException("No tickers found", this); } return(new MarketPrices(new MarketPrice(Network, context.Pair, r.data.last) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.data.ask, r.data.bid, r.data.low, r.data.high) })); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { CheckInputAssetPair(context.Pair); var api = ApiProvider.GetApi(context); var tickerResponse = context.Pair.Equals(AssetPairBtcUsd) ? await api.GetBtcTickerAsync().ConfigureAwait(false) : await api.GetLtcTickerAsync().ConfigureAwait(false); return(new MarketPrices(new MarketPrice(Network, context.Pair, tickerResponse.last) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, tickerResponse.ask, tickerResponse.bid, tickerResponse.low, tickerResponse.high), Volume = new NetworkPairVolume(Network, context.Pair, tickerResponse.volume) })); }
public async Task <MarketPrices> GetPriceAsync(PublicPricesContext context) { if (!PairCodeToProductId.TryGetValue(context.Pair, out var productId)) { throw new ApiResponseException("No product found with specified asset pair", this); } var api = ApiProvider.GetApi(context); var r = await api.GetProductAsync(productId).ConfigureAwait(false); return(new MarketPrices(new MarketPrice(Network, context.Pair, (decimal?)r.last_traded_price ?? 0) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, (decimal)r.high_market_ask, (decimal)r.low_market_bid), Volume = new NetworkPairVolume(Network, context.Pair, r.volume_24h) })); }
public async Task <MarketPrices> GetPriceAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this).ToLower(); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); if (r?.ticker == null) { throw new ApiResponseException("No ticker returned", this); } return(new MarketPrices(new MarketPrice(Network, context.Pair, r.ticker.lastprice) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ticker.sell, r.ticker.buy, r.ticker.low, r.ticker.high) })); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickerAsync(context.Pair.Asset1.ShortCode, context.Pair.Asset2.ShortCode).ConfigureAwait(false); if (r == null) { throw new ApiResponseException("No ticker returned"); } return(new MarketPrices(new MarketPrice(Network, context.Pair, r.LastPrice) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, null, r.BidHigh, r.LastLow, r.LastHigh), Volume = new NetworkPairVolume(Network, context.Pair, r.Volume) })); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickersAsync().ConfigureAwait(false); if (r == null || r.success == false || r.message == null) { throw new ApiResponseException("No tickers found", this); } return(new MarketPrices(new MarketPrice(Network, context.Pair, r.message.lastPrice) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.message.ask, r.message.bid, r.message.low, r.message.high), Volume = new NetworkPairVolume(Network, context.Pair, r.message.coinvolume, r.message.fiatvolume) })); }
public async Task <MarketPricesResult> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickerAsync(context.Pair.Asset1.ToRemoteCode(this)).ConfigureAwait(false); if (r?.ticker == null) { throw new ApiResponseException("No tickers returned.", this); } return(new MarketPricesResult(new MarketPrice(Network, context.Pair, r.ticker.last) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ticker.sell, r.ticker.buy, r.ticker.low, r.ticker.high), Volume = new NetworkPairVolume(Network, context.Pair, r.ticker.vol) })); }
public async Task <MarketPrices> GetPriceAsync(PublicPricesContext context) { var pairsCsv = string.Join(" ", context.Pairs.Select(x => x.ToTicker(this))); var r = await ApiProvider.GetApi(context).GetTickerAsync(pairsCsv).ConfigureAwait(false); if (r == null || r.Length == 0) { throw new ApiResponseException("No ticker returned", this); } return(new MarketPrices(new MarketPrice(Network, context.Pair, r[0].LastBuyPrice) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r[0].BestAsk, r[0].BestBid), Volume = new NetworkPairVolume(Network, context.Pair, r[0].DailyTradedTotalVolume) })); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this, '_').ToLower(); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); if (r == null) { throw new ApiResponseException("No tickers returned", this); } return(new MarketPrices(new MarketPrice(Network, context.Pair, r.last) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ask, r.bid, r.low, r.high), Volume = new NetworkPairVolume(Network, context.Pair, r.volume) })); }
public async Task <MarketPrices> GetPriceAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); if (r.ticker == null || !CheckTickerResponse(r.ticker)) { throw new ApiResponseException("No ticker returned", this); } return(new MarketPrices(new MarketPrice(Network, context.Pair, 1 / r.ticker.last) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ticker.sell, r.ticker.buy, r.ticker.low, r.ticker.high), Volume = new NetworkPairVolume(Network, context.Pair, (decimal)r.ticker.vol) })); }
public async Task <MarketPrices> GetPriceAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this).ToLower(); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); if (r.Count == 0 || r.TryGetValue(pairCode, out var ticker) == false) { throw new ApiResponseException("No ticker returned", this); } return(new MarketPrices(new MarketPrice(Network, context.Pair, ticker.last) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, ticker.sell, ticker.buy, ticker.low, ticker.high), Volume = new NetworkPairVolume(Network, context.Pair, ticker.vol) })); }
public async Task <MarketPrices> GetPriceAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); if (r.success == false || r.data == null) { throw new ApiResponseException(r.msg, this); } return(new MarketPrices(new MarketPrice(Network, context.Pair, r.data.lastDealPrice) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.data.sell, r.data.buy, r.data.low, r.data.high), Volume = new NetworkPairVolume(Network, context.Pair, r.data.vol) })); }
public async Task <MarketPricesResult> GetPriceAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this, ""); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); if (r == null || r.responseStatus?.message?.Equals("OK", StringComparison.InvariantCultureIgnoreCase) == false || r.ticker == null) { throw new ApiResponseException("No asset pairs returned.", this); } return(new MarketPricesResult(new MarketPrice(Network, context.Pair, r.ticker.last) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ticker.ask, r.ticker.bid, r.ticker.low, r.ticker.high), Volume = new NetworkPairVolume(Network, context.Pair, r.ticker.volume) })); }