protected RuntimeException handleHttpError(HttpStatusIOException exception) throws IOException { if (exception.getHttpStatusCode() == 304) { return new NonceException(exception.getHttpBody()); } else { throw exception; } }
public boolean cancelOrder(CurrencyPair pair, long id) throws IOException { try { return coinfloor.cancelOrder(normalise(pair.base), normalise(pair.counter), id); } catch (HttpStatusIOException e) { if (e.getHttpStatusCode() == HttpURLConnection.HTTP_BAD_REQUEST) { throw new ExchangeException(e.getHttpBody(), e); } else { throw e; } } } }
public CoinfloorOrder[] getOpenOrders(CurrencyPair pair) throws IOException { try { return coinfloor.getOpenOrders(normalise(pair.base), normalise(pair.counter)); } catch (HttpStatusIOException e) { if (e.getHttpStatusCode() == HttpURLConnection.HTTP_BAD_REQUEST) { throw new ExchangeException(e.getHttpBody(), e); } else { throw e; } } }
public CoinfloorUserTransaction[] getUserTransactions( CurrencyPair pair, Integer numberOfTransactions, Long offset, TradeHistoryParamsSorted.Order sort) throws IOException { try { return coinfloor.getUserTransactions( normalise(pair.base), normalise(pair.counter), numberOfTransactions, offset, sort == null ? null : sort.toString()); } catch (HttpStatusIOException e) { if (e.getHttpStatusCode() == HttpURLConnection.HTTP_BAD_REQUEST) { throw new ExchangeException(e.getHttpBody(), e); } else { throw e; } } }
public CoinfloorOrder placeLimitOrder( CurrencyPair pair, OrderType side, BigDecimal amount, BigDecimal price) throws IOException { Currency base = normalise(pair.base); Currency counter = normalise(pair.counter); try { if (side == OrderType.BID) { return coinfloor.buy(base, counter, amount, price); } else { return coinfloor.sell(base, counter, amount, price); } } catch (HttpStatusIOException e) { if (e.getHttpStatusCode() == HttpURLConnection.HTTP_BAD_REQUEST) { // e.g. if too many decimal places are specified in the quantity field the HTTP body // contains the message: "amount" parameter must not have more than 4 fractional digits throw new ExchangeException(e.getHttpBody(), e); } else { throw e; } } }
public CoinfloorMarketOrderResponse placeMarketOrder( CurrencyPair pair, OrderType side, BigDecimal amount) throws IOException { Currency base = normalise(pair.base); Currency counter = normalise(pair.counter); try { if (side == OrderType.BID) { return coinfloor.buyMarket(base, counter, amount); } else { return coinfloor.sellMarket(base, counter, amount); } } catch (HttpStatusIOException e) { if (e.getHttpStatusCode() == HttpURLConnection.HTTP_BAD_REQUEST) { // e.g. if too many decimal places are specified in the quantity field the HTTP body // contains the message: "quantity" parameter must not have more than 4 fractional digits throw new ExchangeException(e.getHttpBody(), e); } else { throw e; } } }
protected RuntimeException handleHttpError(HttpStatusIOException exception) throws IOException { if (exception.getHttpStatusCode() == 304) { return new NonceException(exception.getHttpBody()); } else { throw exception; } }
/** * Place a buy order. * * @param price The price in quote currency to buy 1 base currency. Max 2 decimals for BTC/CNY and LTC/CNY markets. 4 decimals for LTC/BTC market. * Market order is executed by setting price to 'null'. * @param amount The amount of LTC/BTC to buy. Supports 4 decimal places for BTC and 3 decimal places for LTC. * @param market [ BTCCNY | LTCCNY | LTCBTC ] * @return order ID. * @throws IOException */ public BTCChinaIntegerResponse buy(BigDecimal price, BigDecimal amount, String market) throws IOException { BTCChinaBuyOrderRequest request = new BTCChinaBuyOrderRequest(price, amount, market); final BTCChinaIntegerResponse response; try { response = btcChina.buyOrder2(signatureCreator, exchange.getNonceFactory(), request); } catch (HttpStatusIOException e) { if (e.getHttpStatusCode() == 401) { log.error("{}, request: {}, response: {}", e.getMessage(), request, e.getHttpBody()); } throw e; } return checkResult(response); }
/** * Place a sell order. * * @param price The price in quote currency to sell 1 base currency. Max 2 decimals for BTC/CNY and LTC/CNY markets. 4 decimals for LTC/BTC market. * Market order is executed by setting price to 'null'. * @param amount The amount of LTC/BTC to sell. Supports 4 decimal places for BTC and 3 decimal places for LTC. * @param market [ BTCCNY | LTCCNY | LTCBTC ] * @return order ID. * @throws IOException */ public BTCChinaIntegerResponse sell(BigDecimal price, BigDecimal amount, String market) throws IOException { BTCChinaSellOrderRequest request = new BTCChinaSellOrderRequest(price, amount, market); final BTCChinaIntegerResponse response; try { response = btcChina.sellOrder2(signatureCreator, exchange.getNonceFactory(), request); } catch (HttpStatusIOException e) { if (e.getHttpStatusCode() == 401) { log.error("{}, request: {}, response: {}", e.getMessage(), request, e.getHttpBody()); } throw e; } return checkResult(response); }