/** * Updates the exchange rate and limits for the specific market. * Note: if the current pair is different that the marketInfo pair, do nothing */ private void onMarketUpdate(ShapeShiftMarketInfo marketInfo) { if (address != null && marketInfo.isPair(account.getCoinType(), address.getType())) { this.marketInfo = marketInfo; } }
@Test public void testMarketInfo() throws JSONException, ShapeShiftException { JSONObject json = new JSONObject( "{" + "\"pair\" : \"btc_nbt\"," + "\"rate\" : \"100\"," + "\"minerFee\" : \"0.01\"," + "\"limit\" : \"4\"," + "\"minimum\" : 0.00000104" + "}"); ShapeShiftMarketInfo marketInfo = new ShapeShiftMarketInfo(json); assertNotNull(marketInfo); assertFalse(marketInfo.isError); assertEquals("btc_nbt", marketInfo.pair); assertTrue(marketInfo.isPair("BTC_NBT")); assertTrue(marketInfo.isPair("btc_nbt")); assertTrue(marketInfo.isPair(BTC, NBT)); assertFalse(marketInfo.isPair("doge_ltc")); assertFalse(marketInfo.isPair(DOGE, LTC)); assertNotNull(marketInfo.rate); assertNotNull(marketInfo.limit); assertNotNull(marketInfo.minimum); assertEquals(NBT.value("99.99"), marketInfo.rate.convert(BTC.value("1"))); assertEquals(BTC.value("4"), marketInfo.limit); assertEquals(BTC.value("0.00000104"), marketInfo.minimum); }
/** * Updates the exchange rate and limits for the specific market. * Note: if the current pair is different that the marketInfo pair, do nothing */ private void onMarketUpdate(ShapeShiftMarketInfo marketInfo) { // If not current pair, do nothing if (!marketInfo.isPair(sourceAccount.getCoinType(), destinationType)) return; maximumDeposit = marketInfo.limit; minimumDeposit = marketInfo.minimum; lastRate = marketInfo.rate; amountCalculatorLink.setExchangeRate(lastRate); if (amountCalculatorLink.isEmpty() && lastRate != null) { Value hintValue = sourceAccount.getCoinType().oneCoin(); Value exchangedValue = lastRate.convert(hintValue); Value minerFee100 = marketInfo.rate.minerFee.multiply(100); // If hint value is too small, make it higher to get a no zero exchanged value and // at least 10 times higher than the miner fee for (int tries = 8; tries > 0 && (exchangedValue.isZero() || exchangedValue.compareTo(minerFee100) < 0); tries--) { hintValue = hintValue.multiply(10); exchangedValue = lastRate.convert(hintValue); } amountCalculatorLink.setExchangeRateHints(hintValue); } }