我在編碼方面還很陌生,希望能得到解決問題的建議。我正在編寫一個 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)
1 回答

翻閱古今
TA貢獻1780條經驗 獲得超5個贊
所以 - 403 意味著您已正確驗證并被系統識別 - 但系統確定您缺少權限。從本質上講,它發現您是用戶 - 但表示您無權訪問您想做的事情。有關狀態代碼的更多信息,請訪問https://httpstatuses.com/
之前使用過這些 API 密鑰 - 我想知道您是否沒有設置 API 密鑰以允許您執行給您 403 的操作。
我建議查看您在加密網站上創建的 API 密鑰。確保您不僅擁有密鑰 - 而且您已啟用該密鑰以用于您想要的操作。看起來 trade.io 稱它們為“權限”,可以在此處查看https://trade.io/en/api。
我的猜測是您只為該鍵啟用了“讀取訪問”,而不是“交易”。
歡迎來到 Stack Overflow :-) 。
添加回答
舉報
0/150
提交
取消