@Test(expected = ShapeShiftException.class) public void testInvalidMarketInfo() throws JSONException, ShapeShiftException { new ShapeShiftRate(new JSONObject( "{" + "\"pair\" : \"btc_nbt\"," + "\"rate\" : \"0\"," + "\"minerFee\" : \"0.01\"," + "\"limit\" : \"0\"," + "\"minimum\" : 0" + "}")); }
@Test(expected = ShapeShiftException.class) public void testInvalidRate() throws ShapeShiftException { new ShapeShiftRate(new JSONObject()); }
/** * Rate * * Gets the current rate offered by Shapeshift. This is an estimate because the rate can * occasionally change rapidly depending on the markets. The rate is also a 'use-able' rate not * a direct market rate. Meaning multiplying your input coin amount times the rate should give * you a close approximation of what will be sent out. This rate does not include the * transaction (miner) fee taken off every transaction. */ public ShapeShiftRate getRate(CoinType typeFrom, CoinType typeTo) throws ShapeShiftException, IOException { String pair = getPair(typeFrom, typeTo); String apiUrl = getApiUrl(String.format(RATE_API, pair)); Request request = new Request.Builder().url(apiUrl).build(); ShapeShiftRate reply = new ShapeShiftRate(getMakeApiCall(request)); if (!reply.isError) checkPair(pair, reply.pair); return reply; }
@Test public void testRateError() throws JSONException, ShapeShiftException { JSONObject json = new JSONObject("{ error: \"error\" }"); ShapeShiftRate rate = new ShapeShiftRate(json); assertNotNull(rate); assertTrue(rate.isError); assertEquals("error", rate.errorMessage); assertNull(rate.pair); assertNull(rate.rate); }
@Test public void testRateWithoutMinerFee2() throws JSONException, ShapeShiftException { JSONObject json = new JSONObject( "{" + "\"pair\" : \"btc_nbt\"," + "\"rate\" : \"123.456789\"" + "}"); ShapeShiftRate rate = new ShapeShiftRate(json); assertNotNull(rate); assertFalse(rate.isError); assertEquals("btc_nbt", rate.pair); assertNotNull(rate.rate); assertEquals(NBT, rate.rate.convert(ONE_BTC).type); assertEquals(BTC, rate.rate.convert(NBT.oneCoin()).type); }
@Test public void testRateWithMinerFee() throws JSONException, ShapeShiftException { JSONObject json = new JSONObject( "{" + "\"pair\" : \"btc_nbt\"," + "\"rate\" : \"100\"," + "\"minerFee\" : \"0.01\"" + "}"); ShapeShiftRate rate = new ShapeShiftRate(json); assertNotNull(rate); assertFalse(rate.isError); assertEquals("btc_nbt", rate.pair); assertNotNull(rate.rate); assertEquals(NBT.value("99.99"), rate.rate.convert(BTC.value("1"))); assertEquals(BTC.value("1"), rate.rate.convert(NBT.value("99.99"))); }
@Test public void testRateWithoutMinerFee() throws JSONException, ShapeShiftException { JSONObject json = new JSONObject( "{" + "\"pair\" : \"btc_ltc\"," + "\"rate\" : \"100\"" + "}"); ShapeShiftRate rate = new ShapeShiftRate(json); assertNotNull(rate); assertFalse(rate.isError); assertEquals("btc_ltc", rate.pair); assertNotNull(rate.rate); assertEquals(LTC.value("100"), rate.rate.convert(BTC.value("1"))); assertEquals(LTC.value("1"), rate.rate.convert(BTC.value("0.01"))); assertEquals(BTC.value("0.01"), rate.rate.convert(LTC.value("1"))); assertEquals(BTC.value("1"), rate.rate.convert(LTC.value("100"))); }