0

Poloniex の取引 API を使用して売買注文を送信しようとしていますが、問題は次のエラーが発生し続けることです。

{
    error = "Invalid API key/secret pair.";
}

注文を投稿するためのコードは次のとおりです。

func postOrder(type: String, price: String, amount: String) {

        let timeNowInt = Int((NSDate().timeIntervalSince1970)*500000)
        let timeNow = String(timeNowInt)

        if key != "" && secret != "" {
            guard let url = URL(string: "https://poloniex.com/tradingApi") else {return}

            let sign = "nonce=\(timeNow)&command=\(orderType.lowercased())&currencyPair=\(coinPair)&rate=\(price)&amount=\(amount)"

            let parameters: Parameters = ["command" : orderType.lowercased(), "currencyPair" : coinPair, "rate" : price, "amount" : amount, "nonce" : timeNow]

            let hmacSign: String = SweetHMAC(message: sign, secret: secret).HMAC(algorithm: .sha512)

            let headers: HTTPHeaders = ["key" : key, "sign" : hmacSign]

            print(parameters)
            print(sign)

            request(url, method: .post, parameters: parameters, encoding: URLEncoding.httpBody, headers: headers).responseJSON(completionHandler: {
                response in

                if let jsonResponse = response.result.value as? NSDictionary {

                    print(jsonResponse)

                    if let orderNumber = jsonResponse["orderNumber"] as? String {

                        print("placed order with id: " + orderNumber)

                        JSSAlertView().show(self, title: "Success", text: "The order has been placed", noButtons: false, buttonText: nil, cancelButtonText: "Ok", color: .white)

                        self.priceTextField.text = ""
                        self.amountTextField.text = ""

                    } else {
                        JSSAlertView().show(self, title: "Failure", text: "Not able to place order", noButtons: false, buttonText: nil, cancelButtonText: "Ok", color: .red)
                    }
                } else {
                    print("json is not readable")
                    JSSAlertView().show(self, title: "Failure", text: "Not able to place order", noButtons: false, buttonText: nil, cancelButtonText: "Ok", color: .red)
                }

            })

        } else {
            print("can't show balances because the key and secret are nil")

            JSSAlertView().show(self, title: "Log in", text: "Please log in before trying to place an order", noButtons: false, buttonText: nil, cancelButtonText: "Ok", color: .gray)
        }

    }

もちろん、適切なコマンドを使用して、この関数を使用して API から他のデータにアクセスしました。しかし、今回は働きたくありません。

定数内のパラメーターをシャッフルすることでsign、通常は機能させることができます。

彼らのドキュメンテーションはかなり貧弱で、私はこれをしばらく研究してきました。どんな助けでも大歓迎です。ありがとうございました!

4

0 に答える 0