/** * 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)); }
/** * Get the current source and destination pair */ private String getPair() { return ShapeShift.getPair(sourceAccount.getCoinType(), destinationType); }
/** * 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; }
/** * 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; }
/** * Status of deposit to address * * This returns the status of the most recent deposit transaction to the address. */ public ShapeShiftTxStatus getTxStatus(AbstractAddress address) throws ShapeShiftException, IOException { String apiUrl = getApiUrl(String.format(TX_STATUS_API, address.toString())); Request request = new Request.Builder().url(apiUrl).build(); ShapeShiftTxStatus reply = new ShapeShiftTxStatus(getMakeApiCall(request)); if (!reply.isError && reply.address != null) checkAddress(address, reply.address); return new ShapeShiftTxStatus(reply, address); }
/** * Get List of Supported Coins * * List of all the currencies that Shapeshift currently supports at any given time. Sometimes * coins become temporarily unavailable during updates or unexpected service issues. */ public ShapeShiftCoins getCoins() throws ShapeShiftException, IOException { Request request = new Request.Builder().url(getApiUrl(GET_COINS_API)).build(); return new ShapeShiftCoins(getMakeApiCall(request)); }
@Override protected Void doInBackground(Void... params) { if (application.isConnected()) { try { shapeShiftCoins = application.getShapeShift().getCoins(); } catch (Exception e) { error = e; } } else { error = new ShapeShiftException("No connection"); } return null; }
/** * Time Remaining on Fixed Amount Transaction * * When a transaction is created with a fixed amount requested there is a 10 minute window for * the deposit. After the 10 minute window if the deposit has not been received the transaction * expires and a new one must be created. This api call returns how many seconds are left before * the transaction expires. */ public ShapeShiftTime getTime(AbstractAddress address) throws ShapeShiftException, IOException { String apiUrl = getApiUrl(String.format(TIME_REMAINING_API, address.toString())); Request request = new Request.Builder().url(apiUrl).build(); return new ShapeShiftTime(getMakeApiCall(request)); }
@Test(expected = ShapeShiftException.class) public void testFixedAmountTransactionFail3() throws ShapeShiftException, AddressMalformedException, IOException { server.enqueue(new MockResponse().setBody(FIXED_AMOUNT_TRANSACTION_JSON)); // Incorrect amount, correct is 1000 shapeShift.exchangeForAmount(DOGE.value("1"), DOGE.newAddress("DMHLQYG4j96V8cZX9WSuXxLs5RnZn6ibrV"), BTC.newAddress("1Nz4xHJjNCnZFPjRUq8CN4BZEXTgLZfeUW")); }
@Test(expected = ShapeShiftException.class) public void testEmailFail() throws ShapeShiftException, IOException, InterruptedException, JSONException, AddressMalformedException { server.enqueue(new MockResponse().setBody(TX_STATUS_NO_DEPOSIT_JSON)); ShapeShiftTxStatus txStatusReply = shapeShift .getTxStatus(BTC.newAddress("1NDQPAGamGePkSZXW2CYBzXJEefB7N4bTN")); // Bad status shapeShift.requestEmailReceipt("mail@example.com", txStatusReply); }
@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); }
public ShapeShift getShapeShift() { if (shapeShift == null) { shapeShift = new ShapeShift(NetworkUtils.getHttpClient(getApplicationContext())); } return shapeShift; }
@Test(expected = ShapeShiftException.class) public void testGetTxStatusFail() throws ShapeShiftException, AddressMalformedException, IOException { server.enqueue(new MockResponse().setBody(TX_STATUS_COMPLETE_JSON)); // Used an incorrect address, correct is 1NDQPAGamGePkSZXW2CYBzXJEefB7N4bTN shapeShift.getTxStatus(BTC.newAddress("18ETaXCYhJ8sxurh41vpKC3E6Tu7oJ94q8")); }
@Test(expected = ShapeShiftException.class) public void testNormalTransactionFail() throws ShapeShiftException, AddressMalformedException, IOException { server.enqueue(new MockResponse().setBody(NORMAL_TRANSACTION_JSON)); // Incorrect Dogecoin address, correct is DMHLQYG4j96V8cZX9WSuXxLs5RnZn6ibrV shapeShift.exchange(DOGE.newAddress("DSntbp199h851m3Y1g3ruYCQHzWYCZQmmA"), BTC.newAddress("1Nz4xHJjNCnZFPjRUq8CN4BZEXTgLZfeUW")); }
@Test(expected = ShapeShiftException.class) public void testGetRateFail() throws ShapeShiftException, IOException { server.enqueue(new MockResponse().setBody(GET_RATE_BTC_LTC_JSON)); // Incorrect pair shapeShift.getRate(NBT, LTC); }
@Test(expected = ShapeShiftException.class) public void testGetLimitFail() throws ShapeShiftException, IOException { server.enqueue(new MockResponse().setBody(GET_LIMIT_BTC_LTC_JSON)); // Incorrect pair shapeShift.getLimit(LTC, DOGE); }
@Test(expected = ShapeShiftException.class) public void testFixedAmountTransactionFail() throws ShapeShiftException, AddressMalformedException, IOException { server.enqueue(new MockResponse().setBody(FIXED_AMOUNT_TRANSACTION_JSON)); // We withdraw Dogecoins to a Bitcoin address shapeShift.exchangeForAmount(DOGE.value("1000"), BTC.newAddress("18ETaXCYhJ8sxurh41vpKC3E6Tu7oJ94q8"), BTC.newAddress("1Nz4xHJjNCnZFPjRUq8CN4BZEXTgLZfeUW")); }
private void startOrStopMarketRatePolling() { if (address != null && !account.isType(address)) { String pair = ShapeShift.getPair(account.getCoinType(), address.getType()); if (timer == null) { startPolling(pair); } else { pollTask.updatePair(pair); } } else if (timer != null) { stopPolling(); } }
@Test(expected = ShapeShiftException.class) public void testFixedAmountTransactionFail2() throws ShapeShiftException, AddressMalformedException, IOException { server.enqueue(new MockResponse().setBody(FIXED_AMOUNT_TRANSACTION_JSON)); // Incorrect Dogecoin address, correct is DMHLQYG4j96V8cZX9WSuXxLs5RnZn6ibrV shapeShift.exchangeForAmount(DOGE.value("1000"), DOGE.newAddress("DSntbp199h851m3Y1g3ruYCQHzWYCZQmmA"), BTC.newAddress("1Nz4xHJjNCnZFPjRUq8CN4BZEXTgLZfeUW")); }