我在編碼方面還很陌生,希望能得到解決問題的建議。我正在編寫一個 java 代碼來連接到 trade.io API,但我不知道如何使用“POST”和“DELETE”向交易所提交正確的加密消息。到目前為止,我設法弄清楚了如何使用“GET”接收信息,但在其他方面沒有成功。這是我到目前為止寫的:/** CancelOrder cancels an existing order ==> This doesn't work!*/ public String CancelOrder(String orderId) throws MalformedURLException, IOException { return signAndSend("/order/" + orderId, "DELETE"); } /* * Reads the open orders in the account ==> This works! */ public String getOpenOrders(String symbol) throws MalformedURLException, IOException { return signAndSend("/openOrders/" + symbol, "GET"); } /* * Signs and Sends signature. This method is called when signature is needed. */ private String signAndSend(String url, String method) throws MalformedURLException, IOException { String nonce = String.valueOf(System.currentTimeMillis()); String baseUrl = UrlTradeio.urlV1; String ts = "?ts=" + nonce; String sign = hmac512Digest(ts, TRADEIO_SECRET_KEY).toUpperCase(); HttpURLConnection con = (HttpURLConnection) new URL(baseUrl + url + ts).openConnection(); con.setRequestProperty("Sign", sign); con.setRequestProperty("Key", TRADEIO_API_KEY); con.setRequestMethod(method); con.connect(); InputStream response = con.getInputStream();// try (Scanner scanner = new Scanner(response)) { String responseBody = scanner.next(); return responseBody; } }交易所在此處提供了非常詳盡的 C# 示例:https://github.com/tradeio/api-csharpclient/blob/master/Tradeio.Client/TradeioApi.cs這是“getOpenOrders”的輸出和我嘗試關閉它時的錯誤消息。線程“main”中的異常 java.io.IOException:服務器返回 HTTP 響應代碼:403 URL:https ://api.exchange.trade.io/api/v1/order/-72057593948251267?ts= 1559338452695 at java.base /sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1913)
連接到加密交換 api。使用“POST”或“DELETE”方法“簽名并發(fā)送”消息時出錯?
30秒到達戰(zhàn)場
2022-12-28 10:44:22