@Test(expected = ShapeShiftException.class) public void testInvalidLimit() throws ShapeShiftException { new ShapeShiftLimit(new JSONObject()); }
public ShapeShiftLimit(JSONObject data) throws ShapeShiftException { super(data); if (!isError) { try { String[] pairs = pair.split("_"); checkState(pairs.length == 2); CoinType typeFrom = CoinID.typeFromSymbol(pairs[0]); limit = parseValue(typeFrom, data.getString("limit"), RoundingMode.DOWN); minimum = parseValue(typeFrom, data.getString("min"), RoundingMode.UP); } catch (Exception e) { throw new ShapeShiftException("Could not parse object", e); } } else { limit = null; minimum = null; } } }
/** * Deposit Limit * * Gets the current deposit limit set by Shapeshift. Amounts deposited over this limit will be * sent to the return address if one was entered, otherwise the user will need to contact * ShapeShift support to retrieve their coins. This is an estimate because a sudden market swing * could move the limit. */ public ShapeShiftLimit getLimit(CoinType typeFrom, CoinType typeTo) throws ShapeShiftException, IOException { String pair = getPair(typeFrom, typeTo); String apiUrl = getApiUrl(String.format(LIMIT_API, pair)); Request request = new Request.Builder().url(apiUrl).build(); ShapeShiftLimit reply = new ShapeShiftLimit(getMakeApiCall(request)); if (!reply.isError) checkPair(pair, reply.pair); return reply; }
@Test public void testLimitError() throws JSONException, ShapeShiftException { JSONObject json = new JSONObject("{ error: \"error\" }"); ShapeShiftLimit limit = new ShapeShiftLimit(json); assertNotNull(limit); assertTrue(limit.isError); assertEquals("error", limit.errorMessage); assertNull(limit.pair); assertNull(limit.limit); assertNull(limit.minimum); }
@Test public void testLimit() throws JSONException, ShapeShiftException { JSONObject json = new JSONObject( "{" + "\"pair\" : \"ltc_doge\"," + "\"limit\" : \"200\"," + "\"min\" : 0.00014772" + "}"); ShapeShiftLimit limit = new ShapeShiftLimit(json); assertNotNull(limit); assertFalse(limit.isError); assertEquals("ltc_doge", limit.pair); assertNotNull(limit.limit); assertNotNull(limit.minimum); assertEquals(LTC.value("200"), limit.limit); assertEquals(LTC.value("0.00014772"), limit.minimum); }
@Test public void testLimit2() throws JSONException, ShapeShiftException { JSONObject json = new JSONObject( "{" + "pair: \"nbt_btc\"," + "limit: \"1015.15359146\"," + "min: 0.053118518219312046" + "}"); ShapeShiftLimit limit = new ShapeShiftLimit(json); assertNotNull(limit); assertFalse(limit.isError); assertEquals("nbt_btc", limit.pair); assertNotNull(limit.limit); assertNotNull(limit.minimum); assertEquals(NBT.value("1015.1535"), limit.limit); assertEquals(NBT.value("0.0532"), limit.minimum); }