大家好,我在 swift 3 交易应用程序中写的每一个人。我只有 3 个命令 buy sell 和 cancel 有问题,那些会导致 error = "Invalid API key/secret pair."; 其他类似 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,“货币对”:“BTC_XRP”,“汇率”:7.6000000000000004e-05]
符号数组是:
金额=2.0&command=sell¤cyPair=BTC_XRP&rate=7.6e-05&nonce=15308121310000000
我真的不知道出了什么问题你能帮忙解决这个问题吗?