/** * 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); }
public boolean isPair(CoinType sourceType, CoinType destinationType) { return isPair(ShapeShift.getPair(sourceType, destinationType)); }
public ShapeShiftNormalTx(JSONObject data) throws ShapeShiftException { super(data); if (!isError) { try { deposit = CoinID.typeFromSymbol(data.getString("depositType")). newAddress(data.getString("deposit")); withdrawal = CoinID.typeFromSymbol(data.getString("withdrawalType")). newAddress(data.getString("withdrawal")); pair = ShapeShift.getPair(deposit.getType(), withdrawal.getType()); } catch (Exception e) { throw new ShapeShiftException("Could not parse object", e); } } else { deposit = null; withdrawal = null; pair = 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; }
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(); } }
/** * Normal Transaction * * Make a normal exchange and receive with {@code withdrawal} address. The exchange pair is * determined from the {@link CoinType}s of {@code refund} and {@code withdrawal}. */ public ShapeShiftNormalTx exchange(AbstractAddress withdrawal, AbstractAddress refund) throws ShapeShiftException, IOException { JSONObject requestJson = new JSONObject(); try { requestJson.put("withdrawal", withdrawal.toString()); requestJson.put("pair", getPair(refund.getType(), withdrawal.getType())); requestJson.put("returnAddress", refund.toString()); if (apiPublicKey != null) requestJson.put("apiKey", apiPublicKey); } catch (JSONException e) { throw new ShapeShiftException("Could not create a JSON request", e); } String apiUrl = getApiUrl(NORMAL_TX_API); RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, requestJson.toString()); Request request = new Request.Builder().url(apiUrl).post(body).build(); ShapeShiftNormalTx reply = new ShapeShiftNormalTx(getMakeApiCall(request)); if (!reply.isError) checkAddress(withdrawal, reply.withdrawal); 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; }
AbstractAddress refund) throws ShapeShiftException, IOException { String pair = getPair(refund.getType(), withdrawal.getType()); JSONObject requestJson = new JSONObject(); try {