public async Task <decimal> GetCurrentPriceAsync(string baseAssetSymbol, string quoteAssetSymbol) { var symbol = $"{baseAssetSymbol}-{quoteAssetSymbol}"; var price = await _cache.GetAsync <TickerPrice>(ExchangesIntegratedType.Coinbase, symbol); if (price == null) { price = await _coinbaseIntegrationClient.GetTickerPriceAsync(symbol); if (price == null) { throw new System.InvalidOperationException($"symbol {symbol} not exists in Coinbase"); } await _cache.AddAsync(price, ExchangesIntegratedType.Coinbase, symbol); } return(decimal.Parse(price.Price)); }
public async Task <decimal> GetCurrentPriceAsync(string baseAssetSymbol, string quoteAssetSymbol) { var symbol = $"{baseAssetSymbol}{quoteAssetSymbol}"; var price = await _cache.GetAsync <TickerPrice>(ExchangesIntegratedType.Binance, symbol); if (price == null) { var listPrices = await _binanceIntegrationClient.GetTickerPricesAsync(); price = listPrices.FirstOrDefault(a => a.Symbol.Equals(symbol)); await _cache.AddAsync(listPrices, ExchangesIntegratedType.Binance, a => a.Symbol); if (price == null) { throw new InvalidOperationException($"symbol {symbol} not exists in Binance"); } } return(decimal.Parse(price.Price)); }
public async Task <decimal> GetCurrentPriceAsync(string baseAssetSymbol, string quoteAssetSymbol) { var symbol = $"{baseAssetSymbol}{quoteAssetSymbol}"; var price = await _cache.GetAsync <TickerPrice>(ExchangesIntegratedType.HitBTC, symbol); if (price == null) { var listPrices = await _hitBTCIntegrationClient.GetTickerPricesAsync(); price = listPrices.FirstOrDefault(a => a.Symbol.Equals(symbol)); await _cache.AddAsync(listPrices, ExchangesIntegratedType.HitBTC, a => a.Symbol); if (price == null) { throw new System.InvalidOperationException($"symbol {symbol} not exists in HitBTC"); } } return(string.IsNullOrWhiteSpace(price.Last) ? decimal.Zero : decimal.Parse(price.Last)); }
public async Task <decimal> GetCurrentPriceAsync(string baseAssetSymbol, string quoteAssetSymbol) { //bitcointrade has pairs inverted use BRLBTC instead BTCBRL var symbol = $"{quoteAssetSymbol}{baseAssetSymbol}"; var price = await _cache.GetAsync <TickerPrice>(ExchangesIntegratedType.BitcoinTrade, symbol); if (price == null) { var response = await Policy .Handle <ApiException>(ex => ex.StatusCode == HttpStatusCode.TooManyRequests) .RetryAsync(_numberOfRetries) .ExecuteAsync(async() => await _bitcoinTradeIntegrationClient.GetTickerPriceAsync(symbol)); if (response.Data == null) { throw new InvalidOperationException($"symbol {symbol} not exists in Bitcointrade"); } price = response.Data; await _cache.AddAsync(price, ExchangesIntegratedType.BitcoinTrade, symbol); } return(price.Sell); }