/** * Get the market depth as a Depth object. * * @param currencyPair The queried currency pair. * @throws TradeDataNotAvailableException if the depth is not available. */ public Depth getDepth(CurrencyPair currencyPair) throws TradeDataNotAvailableException { if (!isSupportedCurrencyPair(currencyPair)) { throw new CurrencyNotSupportedException( "Currency pair: " + currencyPair.toString() + " is currently not supported on " + _name); } // Create the URL to fetch the depth. String url = _url + "depth_" + currencyPair.getCurrency().toString().toLowerCase() + "_json.js"; // Do the actual request. String requestResult = HttpUtils.httpGet(url); if (requestResult != null) { // Request sucessful? try { // Convert the result to JSON. JSONObject requestResultJSON = (JSONObject) JSONObject.fromObject(requestResult); // Try to convert the response to a depth object and return it. return new HuobiDepth(requestResultJSON, currencyPair, this); } catch (JSONException je) { LogUtils.getInstance() .getLogger() .error("Cannot parse " + this._name + " depth return: " + je.toString()); throw new TradeDataNotAvailableException("cannot parse depth data from " + this._name); } } // Response from server was null. throw new TradeDataNotAvailableException( this._name + " server did not respond to depth request"); }
public void handlRequest(HttpServletRequest request, HttpServletResponse response) { printRequest(request); String method = request.getParameter(ServiceConstant.METHOD); CommonService obj = null; try { obj = CommonService.createServiceObjectByMethod(method); } catch (InstantiationException e1) { log.severe( "<handlRequest> but exception while create service object for method(" + method + "), exception=" + e1.toString()); e1.printStackTrace(); } catch (IllegalAccessException e1) { log.severe( "<handlRequest> but exception while create service object for method(" + method + "), exception=" + e1.toString()); e1.printStackTrace(); } try { if (obj == null) { sendResponseByErrorCode(response, ErrorCode.ERROR_PARA_METHOD_NOT_FOUND); return; } obj.setCassandraClient(cassandraClient); obj.setMongoClient(mongoClient); obj.setRequest(request); if (!obj.validateSecurity(request)) { sendResponseByErrorCode(response, ErrorCode.ERROR_INVALID_SECURITY); return; } // parse request parameters if (!obj.setDataFromRequest(request)) { sendResponseByErrorCode(response, obj.resultCode); return; } // print parameters obj.printData(); // handle request obj.handleData(); } catch (HectorException e) { obj.resultCode = ErrorCode.ERROR_CASSANDRA; log.severe("catch DB exception=" + e.toString()); e.printStackTrace(); } catch (JSONException e) { obj.resultCode = ErrorCode.ERROR_JSON; log.severe("catch JSON exception=" + e.toString()); e.printStackTrace(); } catch (Exception e) { obj.resultCode = ErrorCode.ERROR_SYSTEM; log.severe("catch general exception=" + e.toString()); e.printStackTrace(); } finally { } String responseData = obj.getResponseString(); // send back response sendResponse(response, responseData); }