private static int getCurrencyScale(CoinfloorCurrency currency) { switch (currency) { case BTC: return 4; case GBP: case EUR: case USD: case PLN: return 2; } throw new ExchangeException("Currency " + currency + " not supported by coinfloor!"); }
/** * Format a date String for Bitso * * @param dateString * @return */ public static Date parseDate(String dateString) { try { return DATE_FORMAT.parse(dateString); } catch (ParseException e) { throw new ExchangeException("Illegal date/time format", e); } }
private void addToEventQueue(CoinfloorExchangeEvent event) { try { consumerEventQueue.put(event); systemEventQueue.put(event); synchronized (systemEventQueue) { systemEventQueue.notifyAll(); } } catch (InterruptedException e) { throw new ExchangeException("InterruptedException!", e); } } }
public Map<String, Object> adaptEstimateMarketOrder(String data) { Map<String, Object> resultMap = new HashMap<String, Object>(); CoinfloorEstimateMarketOrder rawRetObj; try { rawRetObj = streamObjectMapper.readValue(data, CoinfloorEstimateMarketOrder.class); } catch (IOException e) { throw new ExchangeException("JSON parse error", e); } resultMap.put("generic", rawRetObj); resultMap.put("raw", rawRetObj); return resultMap; }
public Map<String, Object> adaptCancelOrder(String data) { Map<String, Object> resultMap = new HashMap<String, Object>(); CoinfloorCancelOrder rawRetObj; try { rawRetObj = streamObjectMapper.readValue(data, CoinfloorCancelOrder.class); } catch (IOException e) { throw new ExchangeException("JSON parse error", e); } resultMap.put("generic", true); resultMap.put("raw", rawRetObj); return resultMap; }
public static void checkSuccess(Map<String, Object> payload) { if (payload.containsKey("error_code")) { if (!(payload.get("error_code") instanceof Integer) || (Integer) payload.get("error_code") != 0) { throw new ExchangeException("Server returned error " + payload.get("error_code") + ": " + payload.get("error_msg")); } } }
public Map<String, Object> adaptTradeVolume(String data) { Map<String, Object> resultMap = new HashMap<String, Object>(); CoinfloorTradeVolume rawRetObj; try { rawRetObj = streamObjectMapper.readValue(data, CoinfloorTradeVolume.class); } catch (IOException e) { throw new ExchangeException("JSON parse error", e); } resultMap.put("generic", rawRetObj.getAssetVol()); resultMap.put("raw", rawRetObj); return resultMap; }
public String getDepositAddress(String currency) throws IOException { HashMap<String, String> response = poloniexAuthenticated.returnDepositAddresses(apiKey, signatureCreator, exchange.getNonceFactory()); if (response.containsKey("error")) { throw new ExchangeException(response.get("error")); } if (response.containsKey(currency)) { return response.get(currency); } else { throw new ExchangeException("Poloniex did not return a deposit address for " + currency); } }
@SuppressWarnings("rawtypes") public static <T extends LakeBTCResponse> T checkResult(T returnObject) { if (returnObject.getResult() == null) { throw new ExchangeException("Null data returned"); } return returnObject; } }
@SuppressWarnings("rawtypes") public static <T extends CryptsyGenericReturn> T checkResult(T info) { if (info == null) { throw new ExchangeException("Cryptsy returned nothing"); } else if (!info.isSuccess()) { throw new ExchangeException(info.getError()); } else if (info.getError() != null) { throw new ExchangeException(info.getError()); } else if (info.getReturnValue() == null) { throw new ExchangeException("Null data returned"); } return info; }
protected <R extends CryptoTradeBaseResponse> R handleResponse(R response) { final String status = response.getStatus(); final String error = response.getError(); if ((status != null && status.equalsIgnoreCase("error")) || (error != null && !error.isEmpty())) { throw new ExchangeException(error); } return response; }
protected RuntimeException handleException(HitbtcException exception) { String message = exception.getMessage(); if ("Nonce has been used".equals(message)) { return new NonceException(message); } return new ExchangeException(message); } }
public BitfinexLendDepth getBitfinexLendBook(String currency, int limitBids, int limitAsks) throws IOException { try { BitfinexLendDepth bitfinexLendDepth = bitfinex.getLendBook(currency, limitBids, limitAsks); return bitfinexLendDepth; } catch (BitfinexException e) { throw new ExchangeException("Bitfinex returned an error: " + e.getMessage()); } }
public BitfinexLend[] getBitfinexLends(String currency, long sinceTimestamp, int limitTrades) throws IOException { try { BitfinexLend[] bitfinexLends = bitfinex.getLends(currency, sinceTimestamp, limitTrades); return bitfinexLends; } catch (BitfinexException e) { throw new ExchangeException("Bitfinex returned an error: " + e.getMessage()); } }
public static CoinbaseExDigest createInstance(String secretKey) { try { return secretKey == null ? null : new CoinbaseExDigest(Base64.decode(secretKey)); } catch (IOException e) { throw new ExchangeException("Cannot decode secret key"); } }
private static void checkException(BTCTradeResult result) { if (!result.isSuccess()) { throw new ExchangeException(result.getMessage()); } }
public Map<String, PoloniexCurrencyInfo> getPoloniexCurrencyInfo() throws IOException { String command = "returnCurrencies"; try { Map<String, PoloniexCurrencyInfo> currencyInfo = poloniex.getCurrencyInfo(command); return currencyInfo; } catch (PoloniexException e) { throw new ExchangeException(e.getError()); } }
public Map<String, PoloniexMarketData> getAllPoloniexTickers() throws IOException { String command = "returnTicker"; try { Map<String, PoloniexMarketData> marketData = poloniex.getTicker(command); return marketData; } catch (PoloniexException e) { throw new ExchangeException(e.getError()); } }
public BitfinexTrade[] getBitfinexTrades(String pair, long sinceTimestamp) throws IOException { try { BitfinexTrade[] bitfinexTrades = bitfinex.getTrades(pair, sinceTimestamp); return bitfinexTrades; } catch (BitfinexException e) { throw new ExchangeException("Bitfinex returned an error: " + e.getMessage()); } }
public List<Wallet> getWallets() throws IOException { HashMap<String, String> response = poloniexAuthenticated.returnBalances(apiKey, signatureCreator, exchange.getNonceFactory()); if (response.containsKey("error")) { throw new ExchangeException(response.get("error")); } else { return PoloniexAdapters.adaptPoloniexBalances(response); } }