/// <summary> /// Function returning the current market price for one <paramref name="currency"/> /// <paramref name="currency"/> have to be in <see cref="MainCryptos"/> /// </summary> /// <param name="currency">the name of the cryptocurrency.</param> /// <returns>A <see cref="Price"/> object representing the current market price</returns> override public Price GetPrice(string currency) { BittrexSharp.Domain.MarketSummary onePrice; Price cryptoPrice = new Price(); string exchange; string ccyBase; string ccyPair; double mid; string[] mktName; // Handle the fact that Bitcoin Cash have different ticker on Binance if (currency == MainCryptos.BCH.ToString()) { currency = "BCC"; } if (currency != MainCryptos.BTC.ToString()) { try { onePrice = my_bittrex.GetMarketSummary(MainCryptos.BTC.ToString() + "-" + currency).Result.Result; } catch { cryptoPrice = new Price(error: true, exchange: Exchanges.BITTREX.ToString()); onePrice = new BittrexSharp.Domain.MarketSummary(); onePrice.Ask = (decimal)0.00; onePrice.Bid = (decimal)0.00; } } else { try { onePrice = my_bittrex.GetMarketSummary(MainCryptos.USDT.ToString() + "-" + MainCryptos.BTC.ToString()).Result.Result; } catch { cryptoPrice = new Price(error: true, exchange: Exchanges.BITTREX.ToString()); onePrice = new BittrexSharp.Domain.MarketSummary(); onePrice.Ask = (decimal)0.00; onePrice.Bid = (decimal)0.00; } } if (cryptoPrice.error != true) { exchange = Exchanges.BITTREX.ToString(); mktName = onePrice.MarketName.Split('-'); ccyBase = mktName[1]; ccyPair = mktName[0]; mid = (double)(onePrice.Ask + onePrice.Bid) / 2.00; cryptoPrice = new Price(exchange, ccyBase, ccyPair, mid); } return(cryptoPrice); }
public void GetMarketSummary_ShouldNotThrowException() { var bittrex = new Bittrex(); Func <Task> action = async() => { var _ = await bittrex.GetMarketSummary(DefaultMarketName); }; action.ShouldNotThrow(); }
public async void MarketSummaryInvalidOnline() { var r = new Maybe <IDownloadData>(); var b = new Bittrex(r); var res = await b.GetMarketSummary("NotValid"); Assert.Equal("INVALID_MARKET", res.Message); }
public async Task <decimal> GetBalanceBtc() { var all = await bittrex.GetBalances(); decimal total = 0; decimal price = 0; foreach (var balance in all.Result.Where(x => x.Balance > 0)) { decimal estBtcValue = 0; if (balance.Currency == "BTC") { estBtcValue = balance.Balance; total += estBtcValue; } else if (balance.Currency == "USDT") { var market = await bittrex.GetMarketSummary("USDT-BTC"); price = market.Result.Last; estBtcValue = balance.Balance / price; total += estBtcValue; } else { try { var market = await bittrex.GetMarketSummary("BTC-" + balance.Currency); price = market.Result.Last; estBtcValue = price * balance.Balance; total += estBtcValue; } catch { // LOG } } } return(total); }
public async Task UpdateMarketSummary() { LinkMS = await BittrexLink.GetMarketSummary(SelectedMarketPair); }
public async void GetMarketSummary() { var res = await bittrex.GetMarketSummary("BTC-ETH"); Assert.NotNull(res.Result); }