poloniex API请求“买单取消”原因错误=“无效的API密钥/秘密对。”;

时间:2018-07-05 17:42:25

标签: api swift3 poloniex

您好,我正在swift 3交易应用程序中向每个人编写。我只有3个命令buy sell和cancel才有问题,这些命令会导致错误=“无效的API密钥/秘密对”。其他诸如returnOpenOrders,returnTradehistory returnBalances可以正常工作并返回适当的值。

那可能是请求功能:

func getRawJSON(paramss:[String : Any]){
    var paramss1:[String:Any] = [:]
    let APIURL = "https://poloniex.com/tradingApi"
    let timeNowInt = Int(NSDate().timeIntervalSince1970 ) * 10000000

    var zdanie2:String! = ""

for (x,y) in paramss{

                        paramss1[x]=y

                        }
    paramss1["nonce"]=timeNowInt


for (x,y) in paramss{
    if (zdanie2 == "")
    {zdanie2="\(x)=\(y)"
    }
    else
    {
        zdanie2=zdanie2+"&"+"\(x)=\(y)"
    }

}

zdanie2=zdanie2+"&nonce=\(timeNowInt)"



    let array: [UInt8] = Array(zdanie2.utf8)

    let hmac: Array<UInt8> = try! HMAC(key: secretKey!.utf8.map({$0}), variant: .sha512).authenticate(array)
    let hmacData = Data(bytes: hmac).toHexString()
       let headers  = ["Key": publicKey!,"Sign": hmacData] as   [String : String]


    request(APIURL,method: .post,parameters: paramss1,headers:headers).responseJSON {
        response in
        print(response)
       print(response.request)


    }

}

这是我的买卖功能:

 func buy(currencyPair:String,rate:Double,amount:Double){
    return self.getRawJSON( paramss: ["command":"buy","currencyPair":currencyPair,"rate":rate ,"amount":amount])
}
func sell(currencyPair:String,rate:Double,amount:Double){
    return self.getRawJSON( paramss: ["command":"sell","currencyPair":currencyPair,"rate": rate ,"amount":amount])
}

标头参数(var paramss1)的输出为:

[“金额”:2.0,“命令”:“出售”,“现时”:15308121310000000,“ currencyPair”:“ BTC_XRP”,“费率”:7.6000000000000004e-05]

符号数组为:

amount = 2.0&command = sell&currencyPair = BTC_XRP&rate = 7.6e-05&nonce = 15308121310000000

我真的不知道怎么了 您可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

费率值无效。

rate 和 amount 值必须像 1、1.1、1.00000001。

无效请求: 金额=2.0&command=sell¤cyPair=BTC_XRP&rate=7.6e-05&nonce=15308121310000000

有效请求: command=sell&amount=2.0&¤cyPair=BTC_XRP&rate=7.000006&nonce=15308121310000000