/** * Get Market Info * * This is a combined call for {@link #getRate(CoinType, CoinType) getRate()} and * {@link #getLimit(CoinType, CoinType) getLimit()} API calls. */ public ShapeShiftMarketInfo getMarketInfo(CoinType typeFrom, CoinType typeTo) throws ShapeShiftException, IOException { return getMarketInfo(getPair(typeFrom, typeTo)); }
/** * Makes a call to ShapeShift about the market info of a pair. If case of a problem, it will * retry 3 times and return null if there was an error. * * Note: do not call this from the main thread! */ @Nullable public static ShapeShiftMarketInfo getMarketInfoSync(ShapeShift shapeShift, String pair) { // Try 3 times for (int tries = 1; tries <= 3; tries++) { try { log.info("Polling market info for pair: {}", pair); return shapeShift.getMarketInfo(pair); } catch (Exception e) { log.info("Will retry: {}", e.getMessage()); /* ignore and retry, with linear backoff */ try { Thread.sleep(1000 * tries); } catch (InterruptedException ie) { /*ignored*/ } } } return null; } }
ShapeShiftMarketInfo marketInfo = shapeShift.getMarketInfo( sourceType, sendToAddress.getType());
@Test(expected = ShapeShiftException.class) public void testGetMarketInfoFail() throws ShapeShiftException, IOException { server.enqueue(new MockResponse().setBody(MARKET_INFO_BTC_NBT_JSON)); // Incorrect pair shapeShift.getMarketInfo(BTC, LTC); }
@Test public void testGetMarketInfo() throws ShapeShiftException, IOException, InterruptedException, JSONException { // Schedule some responses. server.enqueue(new MockResponse().setBody(MARKET_INFO_BTC_NBT_JSON)); ShapeShiftMarketInfo marketInfoReply = shapeShift.getMarketInfo(BTC, NBT); assertFalse(marketInfoReply.isError); assertEquals("btc_nbt", marketInfoReply.pair); assertNotNull(marketInfoReply.rate); assertNotNull(marketInfoReply.rate); assertNotNull(marketInfoReply.limit); assertNotNull(marketInfoReply.minimum); assertEquals(NBT.value("99.99"), marketInfoReply.rate.convert(BTC.value("1"))); assertEquals(BTC.value("4"), marketInfoReply.limit); assertEquals(BTC.value("0.00000104"), marketInfoReply.minimum); // Optional: confirm that your app made the HTTP requests you were expecting. RecordedRequest request = server.takeRequest(); assertEquals("/marketinfo/btc_nbt", request.getPath()); }